123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?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();
- foreach ($data as &$v)
- {
- $v['is_create'] = TrainingInfo::where('training_id',$v['id'])->where('user_id',$where['user_id'])->find();
- }
- 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;
- }
- }
|