'秒杀','group_buy'=>'团购','new_product'=>'新品']; public static $_CATEGORY = [1=>'订单']; public static $_TYPE = [1=>'全平台',2=>'线上', 3=>'线下']; public static $_ISNEWUSER = [1=>'是',2=>'否']; public static $_DISCOUNTTYPE = [1=>'金额',2=>'打折(%)']; public static $_ACTIVETYPE = [1=>'领取活动',2=>'转发活动',3=>'返券专用']; public static $_STATUS = [ -1=> '已删除', 0=>'草稿', 1=>'正常',2=>'已领完',3=>'禁用']; /* 添加转换字段 */ protected $appends = [ 'status_text', 'type_text', 'category_text', 'is_new_user_text', 'discount_type_text', 'active_type_text', 'start_time_text', 'end_time_text', 'usable_start_time_text', 'usable_end_time_text', // 'receive_type_text', 'created_at_text', 'updated_at_text', 'activity_available_text' ]; protected $casts = [ 'market_ids'=>'array', 'category_ids'=>'array', 'tags'=>'array', 'activity_available'=>'array' ]; public function getStatusTextAttribute() { $value = $this->status; return isset(self::$_STATUS[$value])?self::$_STATUS[$value]:''; } public function getTypeTextAttribute() { $value = $this->type; return isset(self::$_TYPE[$value])?self::$_TYPE[$value]:''; } public function getCategoryTextAttribute() { $value = $this->category; return isset(self::$_CATEGORY[$value])?self::$_CATEGORY[$value]:''; } public function getIsNewUserTextAttribute() { $value = $this->is_new_user; return isset(self::$_ISNEWUSER[$value])?self::$_ISNEWUSER[$value]:''; } public function getDiscountTypeTextAttribute() { $value = $this->discount_type; return isset(self::$_DISCOUNTTYPE[$value])?self::$_DISCOUNTTYPE[$value]:''; } public function getActiveTypeTextAttribute() { $value = $this->active_type; return isset(self::$_ACTIVETYPE[$value])?self::$_ACTIVETYPE[$value]:''; } public function getActivityAvailableTextAttribute() { $value = $this->activity_available; // return isset(self::$_ACTIVITY_AVAILABLE[$value])?self::$_ACTIVITY_AVAILABLE[$value]:''; return ''; } public function getStartTimeTextAttribute() { $value = $this->start_time; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getEndTimeTextAttribute() { $value = $this->usable_start_time; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUsableStartTimeTextAttribute() { $value = $this->start_time; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUsableEndTimeTextAttribute() { $value = $this->usable_end_time; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getCreatedAtTextAttribute() { $value = $this->created_at; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUpdatedAtTextAttribute() { $value = $this->updated_at; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getReceiveTypeTextAttribute() { $id = $this->getKey(); $receive = SettingModel::where('receive_type.system_coupon_user_id',$id) ->join('ims_system_coupon_user_receivetype as receive_type','receive_type.receive_type','ims_system_coupon_setting.id','inner') ->first('name'); return $receive ? $receive['name'] : ''; } //关联领取方式表 public function receiveType() { return $this->hasOne(ReceiveTypeModel::class,'coupon_id','id'); } // 设置 protected function setStartTimeAttribute($value) { $this->attributes['start_time'] = strtotime($value); } protected function setEndTimeAttribute($value) { $this->attributes['end_time'] = strtotime($value); } protected function setUsableStarttimeAttribute($value) { $this->attributes['usable_start_time'] = strtotime($value); } protected function setUsableEndTimeAttribute($value) { $this->attributes['usable_end_time'] = strtotime($value); } /** * 根据id获取单条数据 */ public static function getInfo($id,$field = '*') { return self::select($field)->find($id); } }