SendSvipCouponListen.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\listens;
  12. use crmeb\interfaces\ListenerInterface;
  13. use crmeb\jobs\CloseSvipCouponJob;
  14. use crmeb\jobs\SendSvipCouponJob;
  15. use crmeb\services\TimerService;
  16. use think\facade\Cache;
  17. use think\facade\Queue;
  18. class SendSvipCouponListen extends TimerService implements ListenerInterface
  19. {
  20. public function handle($event): void
  21. {
  22. $this->tick(1000 * 60 * 60 * 23, function () {
  23. $day = date('d', time());
  24. if ((int)$day === 1) {
  25. Queue::push(SendSvipCouponJob::class, []);
  26. }
  27. $nuxt = strtotime(date('Y-m-01', time()) . ' +1 month');
  28. $last = strtotime(date('Y-m-d', $nuxt) . " -1 day");
  29. if ($last - time() < 300) {
  30. Queue::push(CloseSvipCouponJob ::class, []);
  31. }
  32. });
  33. }
  34. }