Ver Fonte

物流对接

kevin_zhangl há 3 anos atrás
pai
commit
e99c8db16c

+ 5 - 1
common/components/SwooleAsyncTimer.php

@@ -48,6 +48,8 @@ class SwooleAsyncTimer extends SwooleAsyncTimerComponent implements SocketInterf
     public function timerCallback($timerId, $server){
         // 自动封期
         AutoClosePeriod::instance()->autoClose();
+        // 自动发送订单
+        TaskFunc::autoSendLogistics();
         // 自动执行任务队列中的任务
         Queue::instance()->consumeTask();
 
@@ -67,8 +69,10 @@ class SwooleAsyncTimer extends SwooleAsyncTimerComponent implements SocketInterf
             Queue::instance()->initRedis();
             // 初始化备份历史奖金数据表
 //            TaskFunc::initAutoBakBalance();
-            // 自动发送订单信息
+            // 初始化发送订单物流信息表
             TaskFunc::initAutoOrderLogistics();
+
+            echo '初始化swoole任务———— initAutoOrderLogistics' . PHP_EOL;
         }
     }
 

+ 10 - 9
common/libs/taskQueue/TaskFunc.php

@@ -41,22 +41,23 @@ class TaskFunc
         print_r('执行到测试任务'.PHP_EOL);
     }
 
+    /**
+     * 初始化订单物流任务
+     */
     public static function initAutoOrderLogistics()
     {
         // 查看数据库中是否存在未开始的发送订单的任务,如果没有就添加一个新任务
-//        $taskQueue = TaskQueue::find()->where('TYPE = :TYPE AND CONTENT = :CONTENT AND STARTED_AT > :STARTED_AT', [':TYPE' => Queue::TYPE_FUNC, ':CONTENT' => TaskFunc::class . '::autoSendLogistics', ':STARTED_AT' => Date::nowTime()])->asArray()->exists();
-//        if (!$taskQueue) {
-//            // 获取站点配置中的备份时间
-//            $config = Cache::getSystemConfig();
-//            $backupTime = (int)$config['sendOrderTime']['VALUE'];
-//            Queue::instance()->addTask(Queue::TYPE_FUNC, TaskFunc::class . '::autoSendLogistics', [], Queue::LOOP_TYPE_DAY, $backupTime . ':00', 0);
-//        }
-        self::autoSendLogistics();
+        $taskQueue = TaskQueue::find()->where('TYPE = :TYPE AND CONTENT = :CONTENT AND STARTED_AT > :STARTED_AT', [':TYPE' => Queue::TYPE_FUNC, ':CONTENT' => TaskFunc::class . '::autoSendLogistics', ':STARTED_AT' => Date::nowTime()])->asArray()->exists();
+        if (!$taskQueue) {
+            // 获取站点配置中的发送订单时间
+            $config = Cache::getSystemConfig();
+            $sendTime = (int)$config['sendOrderTime']['VALUE'];
+            Queue::instance()->addTask(Queue::TYPE_FUNC, TaskFunc::class . '::autoSendLogistics', [], Queue::LOOP_TYPE_DAY, $sendTime . ':00', 0);
+        }
     }
 
     /**
      * 自动发送订单到物流站
-     * @return void
      */
     public static function autoSendLogistics(){
         $form = new OrderLogisticsForm();

+ 5 - 7
common/models/forms/OrderLogisticsForm.php

@@ -36,6 +36,7 @@ class OrderLogisticsForm extends Model
                 ->send();
         } catch(\Exception $e) {
             LoggerTool::info('taskAutoSendEmail Exception!' . $e->getMessage());
+            return false;
         }
 
         return true;
@@ -49,12 +50,9 @@ class OrderLogisticsForm extends Model
         // 查询符合条件的订单
         $orderListData = Order::find()
             ->select('SN')
-            ->where(
-                'STATUS = :STATUS AND CREATED_AT > :CREATED_AT',
-                [':STATUS' => \Yii::$app->params['orderStatus']['paid']['value'], ':CREATED_AT' => strtotime('-100 days')]
-            )
+            ->where('STATUS = :STATUS AND CREATED_AT > :CREATED_AT', [':STATUS' => \Yii::$app->params['orderStatus']['paid']['value'], ':CREATED_AT' => strtotime('-100 days')])
             ->asArray()
-            ->limit(10)
+            ->limit(500)
             ->all();
 
         // 生成Excel
@@ -77,7 +75,7 @@ class OrderLogisticsForm extends Model
     }
 
     /**
-     * 生成复杂的路径
+     * 生成路径
      * @param mixed ...$params
      * @return string
      */
@@ -91,7 +89,7 @@ class OrderLogisticsForm extends Model
     }
 
     /**
-     * 获取文件名
+     * 生成文件名
      */
     public function getFileName($ext = '.csv'): string
     {