<?php namespace app\manystore\model\school\classes\activity; use app\admin\model\manystore\Shop; use app\manystore\model\Manystore; use think\Model; use traits\model\SoftDelete; class ActivityAuth extends Model { use SoftDelete; // 表名 protected $name = 'school_classes_activity_auth'; // 自动写入时间戳字段 protected $autoWriteTimestamp = 'int'; // 定义时间戳字段名 protected $createTime = 'createtime'; protected $updateTime = 'updatetime'; protected $deleteTime = 'deletetime'; // 追加属性 protected $append = [ 'address_type_text', 'start_time_text', 'end_time_text', 'sign_start_time_text', 'sign_end_time_text', 'status_text', 'recommend_text', 'hot_text', 'new_text', 'selfhot_text', 'auth_status_text', 'expirestatus_text', 'add_type_text', 'auth_time_text', 'has_expire', ]; public function getHasExpireList() { return ['1' => __('Has_expire 1'), '2' => __('Has_expire 2')]; } public function getHasExpireAttr($value, $data) { $end_time = (isset($data['end_time']) ? $data['end_time'] : ''); if(!$end_time) return '2'; if( $end_time < time()) { return '1'; }else{ return '2'; } } protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); // $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => 0]); }); } public function getAddressTypeList() { return ['1' => __('Address_type 1'), '2' => __('Address_type 2')]; } public function getStatusList() { return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')]; } public function getRecommendList() { return ['0' => __('Recommend 0'), '1' => __('Recommend 1')]; } public function getHotList() { return ['0' => __('Hot 0'), '1' => __('Hot 1')]; } public function getNewList() { return ['0' => __('New 0'), '1' => __('New 1')]; } public function getSelfhotList() { return ['0' => __('Selfhot 0'), '1' => __('Selfhot 1')]; } public function getAuthStatusList() { return ['0' => __('Auth_status 0'), '1' => __('Auth_status 1'), '2' => __('Auth_status 2')]; } public function getExpirestatusList() { return ['1' => __('Expirestatus 1'), '2' => __('Expirestatus 2')]; } public function getAddTypeList() { return ['1' => __('Add_type 1'), '2' => __('Add_type 2')]; } public function getAddressTypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['address_type']) ? $data['address_type'] : ''); $list = $this->getAddressTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getStartTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getEndTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getSignStartTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['sign_start_time']) ? $data['sign_start_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getSignEndTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['sign_end_time']) ? $data['sign_end_time'] : ''); 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 getRecommendTextAttr($value, $data) { $value = $value ? $value : (isset($data['recommend']) ? $data['recommend'] : ''); $list = $this->getRecommendList(); return isset($list[$value]) ? $list[$value] : ''; } public function getHotTextAttr($value, $data) { $value = $value ? $value : (isset($data['hot']) ? $data['hot'] : ''); $list = $this->getHotList(); return isset($list[$value]) ? $list[$value] : ''; } public function getNewTextAttr($value, $data) { $value = $value ? $value : (isset($data['new']) ? $data['new'] : ''); $list = $this->getNewList(); return isset($list[$value]) ? $list[$value] : ''; } public function getSelfhotTextAttr($value, $data) { $value = $value ? $value : (isset($data['selfhot']) ? $data['selfhot'] : ''); $list = $this->getSelfhotList(); return isset($list[$value]) ? $list[$value] : ''; } public function getAuthStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['auth_status']) ? $data['auth_status'] : ''); $list = $this->getAuthStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getExpirestatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['expirestatus']) ? $data['expirestatus'] : ''); $list = $this->getExpirestatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getAddTypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['add_type']) ? $data['add_type'] : ''); $list = $this->getAddTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getAuthTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['auth_time']) ? $data['auth_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 setSignStartTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } protected function setSignEndTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } protected function setAuthTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } public function schoolclassesactivity() { return $this->belongsTo(Activity::class, 'classes_activity_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function manystore() { return $this->belongsTo(Manystore::class, 'manystore_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function manystoreshop() { return $this->belongsTo(Shop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0); } }