AutoCancelGroupOrderListen.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace ln\listens;
  3. use app\common\repositories\store\order\StoreGroupOrderRepository;
  4. use ln\interfaces\ListenerInterface;
  5. use ln\services\TimerService;
  6. use Swoole\Timer;
  7. use think\facade\Log;
  8. class AutoCancelGroupOrderListen extends TimerService implements ListenerInterface
  9. {
  10. public function handle($event): void
  11. {
  12. $this->tick(60000, function () {
  13. $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
  14. request()->clearCache();
  15. $timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
  16. $time = date('Y-m-d H:i:s', strtotime("- $timer minutes"));
  17. $groupOrderIds = $storeGroupOrderRepository->getTimeOutIds($time);
  18. foreach ($groupOrderIds as $id) {
  19. try {
  20. $storeGroupOrderRepository->cancel($id);
  21. } catch (\Exception $e) {
  22. Log::info('自动关闭订单失败' . var_export($id, 1));
  23. }
  24. }
  25. });
  26. }
  27. }