BaseModel.php 951 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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:i:s", $v);
  18. }
  19. public function getUpdateTimeAttr($v) {
  20. if(!$v)return $v;
  21. return date("Y-m-d H:i:s", $v);
  22. }
  23. public function deleteByIds(array $ids) {
  24. return $this->whereIn('id',$ids)->update(['is_delete' => 1]);
  25. }
  26. public function findById($id) {
  27. return $this->find([
  28. ['id',$id],
  29. ['is_delete', 0],
  30. ]);
  31. }
  32. }