__('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) { if (!$row['weigh']) { $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 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 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] : ''; } 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); } public function manystore() { return $this->belongsTo(Manystore::class, 'manystore_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function shop() { return $this->belongsTo(Shop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0); } }