Browse Source

新增脚本,解析批量发货

wufeng 2 years ago
parent
commit
248fddb6fa
1 changed files with 60 additions and 0 deletions
  1. 60 0
      app/command/handleYzExpressData.php

+ 60 - 0
app/command/handleYzExpressData.php

@@ -0,0 +1,60 @@
+<?php declare (strict_types=1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Db;
+
+//处理有赞物流数据
+class handleYzExpressData extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('handle_yz_express_data')->setDescription('处理有赞物流数据');
+    }
+
+    //处理有赞订单数据
+    protected function execute(Input $input, Output $output)
+    {
+
+        $rs = Db::connect('mysql_yz')
+            ->table('yz_order_info')
+            ->field('i.id,i.orderCode')
+            ->alias('i')
+            ->leftJoin('yz_order_express e', 'e.tid=i.tid')
+            ->where('i.status', 6)
+            ->whereNull('e.id')
+            ->find();
+
+        if ($rs) {
+            //去查询对应的发货单信息
+            $out_rs = Db::name('order_out')
+                ->alias('o')
+                ->field('o.id,o.outCode,e.post_code,e.post_name')
+                ->leftJoin('express_data e', 'e.order_out_id=o.id')
+                ->where([
+                    'o.is_del' => 0,
+                    'o.orderCode' => $rs['orderCode']
+                ])
+                ->where('e.status', '>', 0)
+                ->find();
+
+            if ($out_rs) {
+
+                //回调有赞项目接口,尝试发货
+                $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $rs['orderCode'], 'out_stype' => $out_rs['post_name'], 'post_code' => $out_rs['post_code'], 'uid' => 0, 'uname' => '脚本', 'order_out' => $out_rs['outCode']]);
+                $res = json_decode($res, true);
+                halt($res);
+                if ($res['code'] != 0) $output->writeln('有赞发货失败,' . $res['message']);
+            }
+
+
+        }
+
+    }
+
+
+}