BaseNormalModel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\basic;
  8. use think\Model;
  9. /**
  10. * 模型基类-非软删除
  11. * @package plugin\saiadmin\basic
  12. */
  13. class BaseNormalModel extends Model
  14. {
  15. // 添加时间
  16. protected $createTime = 'create_time';
  17. // 更新时间
  18. protected $updateTime = 'update_time';
  19. // 隐藏字段
  20. protected $hidden = ['delete_time'];
  21. // 只读字段
  22. protected $readonly = ['created_by', 'create_time'];
  23. /**
  24. * 时间范围搜索
  25. */
  26. public function searchCreateTimeAttr($query, $value)
  27. {
  28. $query->whereTime('create_time', 'between', $value);
  29. }
  30. /**
  31. * 新增前
  32. */
  33. public static function onBeforeInsert($model)
  34. {
  35. $info = getCurrentInfo();
  36. $info && $model->setAttr('created_by', $info['id']);
  37. }
  38. /**
  39. * 写入前
  40. */
  41. public static function onBeforeWrite($model)
  42. {
  43. $info = getCurrentInfo();
  44. $info && $model->setAttr('updated_by', $info['id']);
  45. }
  46. }