123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Lessonslot extends Model
- {
-
-
- // 表名
- protected $table = 'lesson_slot';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'starttime_text',
- 'endtime_text',
- 'status_text',
- 'notice_status_text',
- 'finishtime_text',
- 'cancel_time_text',
- 'is_show_text'
- ];
-
- protected static function init()
- {
- self::beforeInsert(function ($row) {
- $row->endtime = $row->starttime + ($row->hours * 3600);
- });
- self::beforeUpdate(function ($row){
- $row->endtime = $row->starttime + ($row->hours * 3600);
- });
- }
-
- public function getStatusList()
- {
- return ['0' => __('Status 0'), '20' => __('Status 20'), '30' => __('Status 30')];
- }
- public function getNoticeStatusList()
- {
- return ['0' => __('Notice_status 0'), '1' => __('Notice_status 1')];
- }
- public function getIsShowList()
- {
- return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
- }
- public function getStarttimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getEndtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getNoticeStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['notice_status']) ? $data['notice_status'] : '');
- $list = $this->getNoticeStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getFinishtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getCancelTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setStarttimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setEndtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setFinishtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setCancelTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function getIsShowTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
- $list = $this->getIsShowList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function coach()
- {
- return $this->belongsTo('Coach', 'coach_ids', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function lesson()
- {
- return $this->belongsTo('Lesson', 'lesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function danceroom()
- {
- return $this->belongsTo('Danceroom', 'danceroom_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|