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); } }