From ed4ce5bebe2fcb8d49390eab988d2431bdd6498f Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Wed, 6 Aug 2025 15:10:12 +0800 Subject: [PATCH] fix : coupon date --- app/Controller/Api/SystemController.php | 7 +++++ app/Cron/Coupon/UserCouponTask.php | 11 +++++-- app/Service/Api/System/TestService.php | 39 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/Service/Api/System/TestService.php diff --git a/app/Controller/Api/SystemController.php b/app/Controller/Api/SystemController.php index 5d621d6..a0ebe6c 100644 --- a/app/Controller/Api/SystemController.php +++ b/app/Controller/Api/SystemController.php @@ -12,6 +12,7 @@ use App\Service\Api\System\GetLeaderboardService; use App\Service\Api\System\MiniWxConfigService; use App\Service\Api\System\SiteListService; use App\Service\Api\System\SystemConfigService; +use App\Service\Api\System\TestService; use App\Service\Api\User\IndexService; use DateMalformedStringException; use Hyperf\HttpServer\Annotation\Controller; @@ -87,4 +88,10 @@ class SystemController extends AbstractController { return (new GetLeaderboardService)->handle(); } + + #[RequestMapping(path: "test", methods: "GET")] + public function test() + { + return (new TestService)->handle(); + } } diff --git a/app/Cron/Coupon/UserCouponTask.php b/app/Cron/Coupon/UserCouponTask.php index 2d26a30..00e5b7a 100644 --- a/app/Cron/Coupon/UserCouponTask.php +++ b/app/Cron/Coupon/UserCouponTask.php @@ -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()); diff --git a/app/Service/Api/System/TestService.php b/app/Service/Api/System/TestService.php new file mode 100644 index 0000000..9aced58 --- /dev/null +++ b/app/Service/Api/System/TestService.php @@ -0,0 +1,39 @@ +userCouponModel + ->where('status', CouponCode::COUPON_STATUS_UNUSED) + ->where('validity_end_time', '<', date('Y-m-d H:i:s')) + ->get(); + + $data = $data->toArray(); + + var_dump($data); + } +} \ No newline at end of file