fix : coupon date

This commit is contained in:
2025-08-06 15:10:12 +08:00
parent eb0ce8a347
commit ed4ce5bebe
3 changed files with 55 additions and 2 deletions

View File

@@ -16,6 +16,8 @@ use App\Model\UserCoupon;
use Exception;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
#[Crontab(rule: "* * * * *", name: "UserCouponTask", singleton: true , callback: "execute", memo: "每秒执行优惠券过期")]
class UserCouponTask
@@ -32,12 +34,17 @@ class UserCouponTask
#[Inject]
protected UserCoupon $userCouponModel;
public function execute()
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function execute(): void
{
try {
$this->userCouponModel
->whereTime('validity_end_time', '>', date('Y-m-d H:i:s'))
->where('status', CouponCode::COUPON_STATUS_UNUSED)
->where('validity_end_time', '<', date('Y-m-d H:i:s'))
->update(['status' => CouponCode::COUPON_STATUS_EXPIRE]);
}catch (Exception $e){
$this->log->error(__CLASS__.$e->getMessage());