PickupOrderRefund.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\console\task;
  13. use app\console\service\Order as OrderService;
  14. use app\common\model\Order as OrderModel;
  15. /**
  16. * 定时任务:自提订单超时未核销系统退款
  17. * Class PickupOrderRefund
  18. * @package app\console\task
  19. */
  20. class PickupOrderRefund extends Task
  21. {
  22. // 当前任务唯一标识
  23. private $taskKey = 'PickupOrderRefund';
  24. // 任务执行间隔时长 (单位:秒)
  25. protected $taskExpire = 30;
  26. // 当前商城ID
  27. private $storeId;
  28. /**
  29. * 任务处理
  30. * @param array $param
  31. * @throws \think\Exception
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function handle(array $param)
  37. {
  38. // log_record([
  39. // 'name' => '超时未自提订单自动退款',
  40. // 'data' => 1111
  41. // ]);
  42. ['storeId' => $this->storeId] = $param;
  43. $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
  44. // echo $this->taskKey . PHP_EOL;
  45. $this->refundPickupEvent();
  46. });
  47. }
  48. /**
  49. * 超时未自提订单自动退款
  50. */
  51. private function refundPickupEvent()
  52. {
  53. // log_record([
  54. // 'name' => '超时未自提订单自动退款',
  55. // 'data' => '222'
  56. // ]);
  57. // 自动关闭自提订单的分钟数
  58. $closeMinutes = OrderModel::getPickupDeadline(); // 提交订单2天后
  59. log_record([
  60. 'name' => '超时未自提订单自动退款',
  61. 'data' => $closeMinutes
  62. ]);
  63. // 执行自动关闭
  64. if ($closeMinutes > 0) {
  65. $service = new OrderService;
  66. $service->refundPickupEvent($this->storeId, $closeMinutes);
  67. }
  68. }
  69. }