1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\common\model\training;
- use think\Model;
- class Training extends Model
- {
-
-
- // 表名
- protected $name = 'training';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'status_text'
- ];
-
-
- public function getStatusList()
- {
- return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public static function lst($where)
- {
- $model = new self;
- if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
- if(isset($where['status']) && $where['status']>-2) $model->where('status',$where['status']);
- $model = $model->where('reg_start','<',date("Y-m-d H:i:s"))->where('reg_end','>',date("Y-m-d H:i:s"));
- $data = $model->order('id desc')->page($where['page'],$where['limit'])->field("id,title,image,info,reg_start,reg_end,max_number,number")->select();
- return $data;
- }
- public static function info($cid,$id)
- {
- $info = self::where('cid',$cid)->where('id',$id)->find();
- if(!$info)return self::setErrorInfo('非法数据');
- $info['list'] = TrainingInfo::where('training_id',$info['id'])->select();
- return $info;
- }
- }
|