hasMany(CouponCategory::class, 'coupon_id', 'goods_category_id'); } public function couponRules() { return $this->hasOne(CouponRules::class,'code','code'); } public function getVoucherStatusTextAttr($value,$data):string { $default = Cache::get('VOUCHER_STATUS'); if (!$default) { $status = DictData::whereIn('type_value', 'voucher_status')->column('name','value'); Cache::set('VOUCHER_STATUS', json_encode($status,true),5); } else { $status = json_decode($default,true); } return $status[$data['voucher_status']] ?? ''; } public function getDiscountRatioTextAttr($value,$data) { return !empty($data['discount_ratio'])?$data['discount_ratio']*10:''; } }