BaseModel.php 1.2 KB

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