Lessonslot.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. 'is_show_text'
  23. ];
  24. protected static function init()
  25. {
  26. self::beforeInsert(function ($row) {
  27. $row->endtime = $row->starttime + ($row->hours * 3600);
  28. });
  29. self::beforeUpdate(function ($row){
  30. $row->endtime = $row->starttime + ($row->hours * 3600);
  31. });
  32. }
  33. public function getStatusList()
  34. {
  35. return ['0' => __('Status 0'), '20' => __('Status 20'), '30' => __('Status 30')];
  36. }
  37. public function getNoticeStatusList()
  38. {
  39. return ['0' => __('Notice_status 0'), '1' => __('Notice_status 1')];
  40. }
  41. public function getIsShowList()
  42. {
  43. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  44. }
  45. public function getStarttimeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
  48. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  49. }
  50. public function getEndtimeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
  53. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  58. $list = $this->getStatusList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getNoticeStatusTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['notice_status']) ? $data['notice_status'] : '');
  64. $list = $this->getNoticeStatusList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function getFinishtimeTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
  70. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  71. }
  72. public function getCancelTimeTextAttr($value, $data)
  73. {
  74. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  75. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  76. }
  77. protected function setStarttimeAttr($value)
  78. {
  79. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  80. }
  81. protected function setEndtimeAttr($value)
  82. {
  83. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  84. }
  85. protected function setFinishtimeAttr($value)
  86. {
  87. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  88. }
  89. protected function setCancelTimeAttr($value)
  90. {
  91. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  92. }
  93. public function getIsShowTextAttr($value, $data)
  94. {
  95. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  96. $list = $this->getIsShowList();
  97. return isset($list[$value]) ? $list[$value] : '';
  98. }
  99. public function coach()
  100. {
  101. return $this->belongsTo('Coach', 'coach_ids', 'id', [], 'LEFT')->setEagerlyType(0);
  102. }
  103. public function lesson()
  104. {
  105. return $this->belongsTo('Lesson', 'lesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
  106. }
  107. public function danceroom()
  108. {
  109. return $this->belongsTo('Danceroom', 'danceroom_id', 'id', [], 'LEFT')->setEagerlyType(0);
  110. }
  111. }