| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: sai <1430792918@qq.com>
- // +----------------------------------------------------------------------
- namespace plugin\saiadmin\basic;
- use think\Model;
- use think\model\concern\SoftDelete;
- /**
- * 模型基类
- * @package plugin\saiadmin\basic
- */
- class BaseModel extends Model
- {
- use SoftDelete;
- // 删除时间
- protected $deleteTime = 'delete_time';
- // 添加时间
- 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);
- }
- }
- }
|