63 lines
1.1 KiB
PHP
63 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\Price;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Coupon extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasDateTimeFormatter;
|
|
|
|
protected $casts = [
|
|
'amount' => Price::class,
|
|
'threshold'=>Price::class,
|
|
];
|
|
|
|
/**
|
|
* 此优惠券的使用范围
|
|
*
|
|
* @return void
|
|
*/
|
|
public function ranges()
|
|
{
|
|
return $this->hasMany(CouponRange::class, 'coupon_id');
|
|
}
|
|
|
|
/**
|
|
* 优惠券的发放任务
|
|
*/
|
|
public function sendTask()
|
|
{
|
|
return $this->hasMany(CouponSendTask::class, 'coupon_id');
|
|
}
|
|
|
|
/**
|
|
* 该优惠券下是否有发放任务
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasSendTask(): bool
|
|
{
|
|
return $this->sendTask()->exists();
|
|
}
|
|
|
|
public function receiveLog()
|
|
{
|
|
return $this->hasMany(UserCoupon::class, 'coupon_id');
|
|
}
|
|
|
|
/**
|
|
* 是否被领取过
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function hasReceived()
|
|
{
|
|
return $this->receiveLog()->exists();
|
|
}
|
|
}
|