AuthCancelPresellOrderListen.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 app\common\repositories\store\order\PresellOrderRepository;
  13. use crmeb\interfaces\ListenerInterface;
  14. use crmeb\services\TimerService;
  15. use Swoole\Timer;
  16. use think\facade\Log;
  17. class AuthCancelPresellOrderListen extends TimerService implements ListenerInterface
  18. {
  19. public function handle($event): void
  20. {
  21. $this->tick(1000 * 60 * 1.5, function () {
  22. $presellOrderRepository = app()->make(PresellOrderRepository::class);
  23. $ids = $presellOrderRepository->getTimeOutIds(date('Y-m-d H:i:s'));
  24. foreach ($ids as $id) {
  25. try {
  26. $presellOrderRepository->cancel($id);
  27. } catch (\Exception $e) {
  28. Log::info('自动关闭尾款订单失败' . var_export($id, 1));
  29. }
  30. }
  31. });
  32. }
  33. }