TrainingInfo.php 1.8 KB

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