Browse Source

定时任务关闭订单的有效期

Yahoo 4 years ago
parent
commit
05927356b7
2 changed files with 9 additions and 9 deletions
  1. 4 4
      app/console/service/Order.php
  2. 5 5
      app/console/task/Order.php

+ 4 - 4
app/console/service/Order.php

@@ -30,15 +30,15 @@ class Order extends BaseService
     /**
      * 未支付订单自动关闭
      * @param int $storeId
-     * @param int $closeDays 自定关闭订单天数
+     * @param int $closeHours 自定关闭订单有效期 (小时)
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function closeEvent(int $storeId, int $closeDays)
+    public function closeEvent(int $storeId, int $closeHours)
     {
         // 截止时间
-        $deadlineTime = time() - ((int)$closeDays * 86400);
+        $deadlineTime = time() - ((int)$closeHours * 60 * 60);
         // 查询截止时间未支付的订单
         $model = new OrderModel;
         $list = $model->getListByClose($storeId, $deadlineTime);
@@ -55,7 +55,7 @@ class Order extends BaseService
         // 记录日志
         Tools::taskLogs('Order', 'closeEvent', [
             'storeId' => $storeId,
-            'closeDays' => $closeDays,
+            'closeHours' => $closeHours,
             'deadlineTime' => $deadlineTime,
             'orderIds' => helper::jsonEncode($orderIds)
         ]);

+ 5 - 5
app/console/task/Order.php

@@ -43,7 +43,7 @@ class Order extends Task
     {
         ['storeId' => $this->storeId] = $param;
         $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
-            // echo $this->taskKey . PHP_EOL;
+            echo $this->taskKey . PHP_EOL;
             // 未支付订单自动关闭
             $this->closeEvent();
             // 已发货订单自动确认收货
@@ -61,12 +61,12 @@ class Order extends Task
      */
     private function closeEvent()
     {
-        // 自动关闭订单的天数
-        $closeDays = (int)$this->getTradeSetting()['close_days'];
+        // 自动关闭订单的有效期
+        $closeHours = (int)$this->getTradeSetting()['closeHours'];
         // 执行自动关闭
-        if ($closeDays > 0) {
+        if ($closeHours > 0) {
             $service = new OrderService;
-            $service->closeEvent($this->storeId, $closeDays);
+            $service->closeEvent($this->storeId, $closeHours);
         }
     }