diff --git a/app/Cron/Coupon/UserCouponTask.php b/app/Cron/Coupon/UserCouponTask.php new file mode 100644 index 0000000..e6908ff --- /dev/null +++ b/app/Cron/Coupon/UserCouponTask.php @@ -0,0 +1,45 @@ +userCouponModel + ->whereTime('validity_end_time', '<', date('Y-m-d H:i:s')) + ->where('status', CouponCode::COUPON_STATUS_UNUSED) + ->update(['status' => CouponCode::COUPON_STATUS_EXPIRE]); + }catch (Exception $e){ + $this->log->error(__CLASS__.$e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Service/ServiceTrait/Api/CouponTrait.php b/app/Service/ServiceTrait/Api/CouponTrait.php index 11f2323..017b7a6 100644 --- a/app/Service/ServiceTrait/Api/CouponTrait.php +++ b/app/Service/ServiceTrait/Api/CouponTrait.php @@ -33,8 +33,10 @@ trait CouponTrait $couponInfo = $this->userCouponModel->where('id', $orderInfo->coupon_id)->where('user_id',$orderInfo->user_id)->first(); if (empty($couponInfo)) return; + if ($couponInfo->status != CouponCode::COUPON_STATUS_USED) return; $couponInfo->status = CouponCode::COUPON_STATUS_UNUSED; + $couponInfo->use_time = null; if (date('Y-m-d H:i:s') > $couponInfo->validity_end_time) $couponInfo->status = CouponCode::COUPON_STATUS_EXPIRE;