BaseNormalModel.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  47. * 游戏ID搜索
  48. */
  49. public function searchGameIdAttr($query, $value)
  50. {
  51. if (is_array($value)) {
  52. $query->whereIn('game_id', $value);
  53. } else if($value!='') {
  54. $query->where('game_id', $value);
  55. }
  56. }
  57. /**
  58. * 负责人ID搜索
  59. */
  60. public function searchAuthIdAttr($query, $value)
  61. {
  62. if(is_array($value)){
  63. $query->whereIn('auth_id', $value);
  64. }else if($value!=''){
  65. $query->where('auth_id', $value);
  66. }
  67. }
  68. /**
  69. * ID搜索
  70. */
  71. public function searchIdAttr($query, $value)
  72. {
  73. if (is_array($value)) {
  74. $query->whereIn('id', $value);
  75. } else if($value!=''){
  76. $query->where('id', $value);
  77. }
  78. }
  79. }