| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: sai <1430792918@qq.com>
- // +----------------------------------------------------------------------
- namespace plugin\saiadmin\basic;
- use think\Model;
- /**
- * 模型基类-非软删除
- * @package plugin\saiadmin\basic
- */
- class BaseNormalModel extends Model
- {
- // 添加时间
- protected $createTime = 'create_time';
- // 更新时间
- protected $updateTime = 'update_time';
- // 隐藏字段
- protected $hidden = ['delete_time'];
- // 只读字段
- protected $readonly = ['created_by', 'create_time'];
- /**
- * 时间范围搜索
- */
- public function searchCreateTimeAttr($query, $value)
- {
- $query->whereTime('create_time', 'between', $value);
- }
- /**
- * 新增前
- */
- public static function onBeforeInsert($model)
- {
- $info = getCurrentInfo();
- $info && $model->setAttr('created_by', $info['id']);
- }
- /**
- * 写入前
- */
- public static function onBeforeWrite($model)
- {
- $info = getCurrentInfo();
- $info && $model->setAttr('updated_by', $info['id']);
- }
- /**
- * 游戏ID搜索
- */
- public function searchGameIdAttr($query, $value)
- {
- if (is_array($value)) {
- $query->whereIn('game_id', $value);
- } else if($value!='') {
- $query->where('game_id', $value);
- }
- }
- /**
- * 负责人ID搜索
- */
- public function searchAuthIdAttr($query, $value)
- {
- if(is_array($value)){
- $query->whereIn('auth_id', $value);
- }else if($value!=''){
- $query->where('auth_id', $value);
- }
- }
- /**
- * ID搜索
- */
- public function searchIdAttr($query, $value)
- {
- if (is_array($value)) {
- $query->whereIn('id', $value);
- } else if($value!=''){
- $query->where('id', $value);
- }
- }
- }
|