Browse Source

物流信息脚本优化

wufeng 2 years ago
parent
commit
36be2acfd1
1 changed files with 14 additions and 3 deletions
  1. 14 3
      app/command/getLogisticsInformationByKuaidi.php

+ 14 - 3
app/command/getLogisticsInformationByKuaidi.php

@@ -28,13 +28,13 @@ class getLogisticsInformationByKuaidi extends Command
             ->where('oo.status', 2)//status==2 已发货待收货
             ->leftJoin('order_addr oa', 'oa.id=oo.addrid AND oa.is_del=0')
             ->lock(true)
-            ->field('oo.id,oo.post_code,oo.updatetime,oa.mobile')
+            ->field('oo.id,oo.post_code,oo.updatetime,oa.mobile,oo.post_name')
             ->cursor();
 
         if (empty($order_out_list)) $output->writeln('没有符合条件的记录');
         else {
             foreach ($order_out_list as $order_out) {
-                $this->_handlePostData($order_out['id'], $order_out['post_code'], $order_out['mobile']);
+                $this->_handlePostData($order_out['id'], $order_out['post_code'], $order_out['mobile'], $order_out['post_name']);
             }
             $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
         }
@@ -45,7 +45,8 @@ class getLogisticsInformationByKuaidi extends Command
     //@param string order_out_id 发货单ID
     //@param string post_data 快递单号
     //@param string mobile 收货人手机号,目前只有顺丰需要
-    private function _handlePostData(int $order_out_id = 0, string $post_code = '', string $mobile = '')
+    //@param string post_name 物流公司
+    private function _handlePostData(int $order_out_id = 0, string $post_code = '', string $mobile = '', string $post_name = '')
     {
 
         $remark = [0 => '物流单号暂无结果', 3 => '在途', 4 => '揽件', 5 => '疑难', 6 => '签收', 7 => '退签', 8 => '派件', 9 => '退回'];
@@ -97,6 +98,16 @@ class getLogisticsInformationByKuaidi extends Command
                     ]);
             }
 
+            //更新物流公司
+            if ($post_name == '') {
+                Db::name('order_out')
+                    ->where(['post_code' => $post_code, 'id' => $order_out_id])
+                    ->update([
+                        'post_name' => $post_name,
+                        'updatetime' => date('Y-m-d H:i:s'),
+                    ]);
+            }
+
             Db::commit();
             return true;
         } catch (Exception $exception) {