Lessonslot.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Lessonslot extends Model
  5. {
  6. // 表名
  7. protected $table = 'lesson_slot';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'starttime_text',
  17. 'endtime_text',
  18. 'status_text',
  19. 'notice_status_text',
  20. 'finishtime_text',
  21. 'cancel_time_text'
  22. ];
  23. public function getStatusList()
  24. {
  25. return ['0' => __('Status 0'), '20' => __('Status 20'), '30' => __('Status 30')];
  26. }
  27. public function getNoticeStatusList()
  28. {
  29. return ['0' => __('Notice_status 0'), '1' => __('Notice_status 1')];
  30. }
  31. public function getStarttimeTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  34. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  35. }
  36. public function getEndtimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getStatusTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  44. $list = $this->getStatusList();
  45. return isset($list[$value]) ? $list[$value] : '';
  46. }
  47. public function getNoticeStatusTextAttr($value, $data)
  48. {
  49. $value = $value ? $value : (isset($data['notice_status']) ? $data['notice_status'] : '');
  50. $list = $this->getNoticeStatusList();
  51. return isset($list[$value]) ? $list[$value] : '';
  52. }
  53. public function getFinishtimeTextAttr($value, $data)
  54. {
  55. $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
  56. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  57. }
  58. public function getCancelTimeTextAttr($value, $data)
  59. {
  60. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  61. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  62. }
  63. protected function setStarttimeAttr($value)
  64. {
  65. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  66. }
  67. protected function setEndtimeAttr($value)
  68. {
  69. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  70. }
  71. protected function setFinishtimeAttr($value)
  72. {
  73. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  74. }
  75. protected function setCancelTimeAttr($value)
  76. {
  77. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  78. }
  79. public function coach()
  80. {
  81. return $this->belongsTo('Coach', 'coach_ids', 'id', [], 'LEFT')->setEagerlyType(0);
  82. }
  83. public function lesson()
  84. {
  85. return $this->belongsTo('Lesson', 'lesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  86. }
  87. }