AuthTakeOrderListen.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\StoreOrderRepository;
  13. use app\common\repositories\store\order\StoreOrderStatusRepository;
  14. use crmeb\interfaces\ListenerInterface;
  15. use crmeb\jobs\OrderReplyJob;
  16. use crmeb\services\TimerService;
  17. use Swoole\Timer;
  18. use think\facade\Log;
  19. use think\facade\Queue;
  20. class AuthTakeOrderListen extends TimerService implements ListenerInterface
  21. {
  22. public function handle($event): void
  23. {
  24. $this->tick(1000 * 60 * 60, function () {
  25. $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  26. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  27. request()->clearCache();
  28. $timer = ((int)systemConfig('auto_take_order_timer')) ?: 15;
  29. $time = date('Y-m-d H:i:s', strtotime("- $timer day"));
  30. $ids = $storeOrderStatusRepository->getTimeoutDeliveryOrder($time);
  31. foreach ($ids as $id) {
  32. try {
  33. $storeOrderRepository->takeOrder($id);
  34. Queue::push(OrderReplyJob::class, $id);
  35. } catch (\Exception $e) {
  36. Log::error('自动收货失败:' . $e->getMessage());
  37. }
  38. }
  39. });
  40. }
  41. }