AuthTakeOrderListen.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 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. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  26. request()->clearCache();
  27. /**
  28. * 设置自动确认收获的时间默认为 15
  29. * 查询确认收货 15天前发货,再向前查询15天;
  30. * 超过这个时间未处理的订单将不做处理,
  31. * 比如:发货时间 10-1 ; 自动确认时间:15天,当10-15日查询的范围:9-15 ~ 10-15 期间未处理订单,9-15日以前订单不做处理
  32. */
  33. $timer = ((int)systemConfig('auto_take_order_timer')) ?: 15;
  34. $end = date('Y-m-d H:i:s', strtotime("- $timer day"));
  35. $start = date('Y-m-d H:i:s', strtotime("- 15 day",strtotime($end)));
  36. $ids = app()->make(StoreOrderStatusRepository::class)->getTimeoutDeliveryOrder($start,$end);
  37. foreach ($ids as $id) {
  38. try {
  39. $storeOrderRepository->takeOrder($id);
  40. Queue::push(OrderReplyJob::class, $id);
  41. } catch (\Exception $e) {
  42. Log::error('自动收货失败:['. $id .']'. $e->getMessage());
  43. }
  44. }
  45. });
  46. }
  47. }