12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\common\model\training;
- use think\Model;
- class TrainingInfo extends Model
- {
-
-
- // 表名
- protected $name = 'training_info';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'status_text',
- 'sendtime_text'
- ];
-
-
- public function getStatusList()
- {
- return ['0' => __('Status 0'), '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 function getSendtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['sendtime']) ? $data['sendtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setSendtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public static function lst($where)
- {
- $model = new self;
- if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
- if(isset($where['user_id']) && $where['user_id']>0) $model->where('user_id',$where['user_id']);
- if(isset($where['training_id']) && $where['training_id']>0) $model->where('training_id',$where['training_id']);
- $data = $model->order('id desc')->page($where['page'],$where['limit'])->select();
- foreach ($data as &$v)
- {
- $v['training'] = Training::where('id',$v['training_id'])->find();
- }
- return $data;
- }
- }
|