Training.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\common\model\training;
  3. use think\Model;
  4. class Training extends Model
  5. {
  6. // 表名
  7. protected $name = 'training';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text'
  17. ];
  18. public function getStatusList()
  19. {
  20. return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
  21. }
  22. public function getStatusTextAttr($value, $data)
  23. {
  24. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  25. $list = $this->getStatusList();
  26. return isset($list[$value]) ? $list[$value] : '';
  27. }
  28. public static function lst($where)
  29. {
  30. $model = new self;
  31. if(isset($where['cid']) && $where['cid']>0) $model->where('cid',$where['cid']);
  32. if(isset($where['status']) && $where['status']>-2) $model->where('status',$where['status']);
  33. $model = $model->where('reg_start','<',date("Y-m-d H:i:s"))->where('reg_end','>',date("Y-m-d H:i:s"));
  34. $data = $model->order('id desc')->page($where['page'],$where['limit'])->field("id,title,image,info,reg_start,reg_end,max_number,number")->select();
  35. foreach ($data as &$v)
  36. {
  37. $v['is_create'] = TrainingInfo::where('training_id',$v['id'])->where('user_id',$where['user_id'])->find();
  38. }
  39. return $data;
  40. }
  41. public static function info($cid,$id)
  42. {
  43. $info = self::where('cid',$cid)->where('id',$id)->find();
  44. if(!$info)return self::setErrorInfo('非法数据');
  45. $info['list'] = TrainingInfo::where('training_id',$info['id'])->select();
  46. return $info;
  47. }
  48. }