修改券规则表字段
parent
553906ac34
commit
fee8470096
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue