UserCoupon.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\timer\controller;
  13. use cores\BaseTimer;
  14. use app\timer\service\UserCoupon as UserCouponService;
  15. /**
  16. * 定时任务:设置优惠券过期状态
  17. * Class UserCoupon
  18. * @package app\timer\controller
  19. */
  20. class UserCoupon extends BaseTimer
  21. {
  22. // 当前任务唯一标识
  23. protected string $taskKey = 'UserCoupon';
  24. // 任务执行间隔时长 (单位:秒)
  25. protected int $taskExpire = 60 * 30;
  26. /**
  27. * 任务处理
  28. * @param array $param
  29. */
  30. public function handle(array $param)
  31. {
  32. ['storeId' => $this->storeId] = $param;
  33. $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
  34. echo $this->taskKey . PHP_EOL;
  35. // 设置优惠券过期状态
  36. $this->setExpired();
  37. });
  38. }
  39. /**
  40. * 设置优惠券过期状态
  41. */
  42. private function setExpired()
  43. {
  44. $service = new UserCouponService;
  45. $service->setExpired($this->storeId);
  46. }
  47. }