1 ]; /** * 仅查询可用的券规则 */ public function scopeIsEnable($query) { return $query->where('is_enable', true); } public function coupon() { return $this->belongsTo(Coupon::class, 'coupon_id'); } /** * 确认券规则是否仅分类可用 * * @return bool */ public function isTypeCategory() { return $this->type === static::TYPE_CATEGORY; } /** * 确认券规则是否仅商品可用 * * @return bool */ public function isTypeProduct() { return $this->type === static::TYPE_PRODUCT; } /** * 获取此规则的范围IDs * * @return array */ public function getRangeIdsAttribute(): array { $value = $this->attributes['ranges']; if ((string) $value === '') { return []; } return explode(',', $value); } }