BaseModel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. abstract class BaseModel extends Model
  5. {
  6. public function __call($method, $args)
  7. {
  8. return parent::__call($method, $args); // TODO: Change the autogenerated stub
  9. }
  10. abstract protected function genSchema(array $schema);
  11. public function getCreateTimeAttr($v) {
  12. if(!$v)return $v;
  13. return date("Y-m-d H:i:s", $v);
  14. }
  15. public function getUpdateTimeAttr($v) {
  16. if(!$v)return $v;
  17. return date("Y-m-d H:i:s", $v);
  18. }
  19. public function deleteByIds(array $ids) {
  20. return $this->whereIn('id',$ids)->update(['is_delete' => 1]);
  21. }
  22. /**
  23. * @param $id
  24. * @return BaseModel|array|mixed|Model|null
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function findById($id) {
  30. return $this->where([
  31. ['id','=',$id],
  32. ['is_delete','=', 0]
  33. ])->find();
  34. }
  35. public function findByIds(array $ids) {
  36. return $this->where([
  37. ['id','in', $ids],
  38. ['is_delete','=', 0]
  39. ])->select();
  40. }
  41. }