增加发券规则
This commit is contained in:
@@ -4,6 +4,7 @@ namespace XuanChen\Coupon\Action\ysd;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
class YsdGrant extends Init
|
||||
@@ -13,7 +14,7 @@ class YsdGrant extends Init
|
||||
{
|
||||
try {
|
||||
|
||||
$activity = Activity::where('code', $this->activityId)->first();
|
||||
$activity = Activity::withCount('coupons')->where('code', $this->activityId)->first();
|
||||
if (!$activity) {
|
||||
return '发券失败,没有找到这个活动。';
|
||||
}
|
||||
@@ -21,6 +22,14 @@ class YsdGrant extends Init
|
||||
if (!$activity->status) {
|
||||
return '发券失败,活动已经关闭。';
|
||||
}
|
||||
|
||||
if ($activity->type == Activity::TYPE_SCOPE && Carbon::now()->gt($activity->end_at)) {
|
||||
return '发券失败,此活动已经结束。';
|
||||
}
|
||||
|
||||
if ($activity->total > 0 && $activity->coupons_count >= $activity->total) {
|
||||
return '发券失败,已达到可发券总数。';
|
||||
}
|
||||
|
||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
||||
if (!$outlet) {
|
||||
|
||||
Reference in New Issue
Block a user