6
0
Fork 0

修改券规则表字段

release
李静 2021-12-15 14:13:35 +08:00
parent 553906ac34
commit fee8470096
2 changed files with 48 additions and 1 deletions

View File

@ -11,8 +11,55 @@ class CouponRange extends Model
use HasFactory;
use HasDateTimeFormatter;
public const TYPE_CATEGORY = 1;
public const TYPE_PRODUCT = 2;
/**
* 仅查询可用的券规则
*/
public function scopeIsEnable()
{
return $this->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);
}
}

View File

@ -18,7 +18,7 @@ class CreateCouponRangesTable extends Migration
$table->unsignedBigInteger('coupon_id')->comment('优惠券ID');
$table->unsignedTinyInteger('type')->default(0)->comment('类型1商品分类,2sku商品');
$table->text('ranges')->comment('范围IDS');
$table->unsignedTinyInteger('status')->default(0)->comment('0未启用1启用');
$table->boolean('is_enable')->default(false)->comment('是否启用');
$table->timestamps();
});
}