Ver Fonte

批量发货

wufeng há 2 anos atrás
pai
commit
c59ab0a54a
2 ficheiros alterados com 40 adições e 30 exclusões
  1. 7 0
      app/admin/controller/Sale.php
  2. 33 30
      app/command/handleYzExpressData.php

+ 7 - 0
app/admin/controller/Sale.php

@@ -7,6 +7,7 @@ use app\admin\model\ProcessOrder;
 use Exception;
 use think\App;
 use think\facade\Cache;
+use think\facade\Config;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 use think\facade\Validate;
@@ -4296,6 +4297,12 @@ class Sale extends Base
 
             if (!empty($good_data)) GoodLog::LogAdd(['id' => $createrid, 'nickname' => $creater], $good_data, "CKD");
 
+            //将有赞平台的订单编码入队列
+            if (isset($sale_infos[$order_out_infos[$value['outCode']]['order_source']]) && $sale_infos[$order_out_infos[$value['outCode']]['order_source']] == 5) {
+                Cache::store("redis")->handler()->lPush(Config::get('app.yz_express_queue_key'), $order_out_infos[$value['outCode']]['orderCode']);
+            }
+
+
             Db::commit();
 
             return app_show(0, '发货成功');

+ 33 - 30
app/command/handleYzExpressData.php

@@ -5,6 +5,9 @@ namespace app\command;
 use think\console\Command;
 use think\console\Input;
 use think\console\Output;
+use think\Exception;
+use think\facade\Cache;
+use think\facade\Config;
 use think\facade\Db;
 
 //处理有赞物流数据
@@ -20,38 +23,38 @@ class handleYzExpressData extends Command
     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']);
-            }
+        try {
+
+
+            $orderCode = Cache::store('redis')->handler()->rpop(Config::get('app.yz_express_queue_key'));
+
+            if ($orderCode) {
+                //去查询对应的发货单信息
+                $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' => $orderCode
+                    ])
+                    ->where('e.status', '>', 0)
+                    ->find();
+
+                if ($out_rs) {
 
+                    //回调有赞项目接口,尝试发货
+                    $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $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);
+
+                    if ($res['code'] != 0) $output->writeln('有赞发货失败,' . $res['message']);
+                }
+
+
+            }
 
+        } catch (Exception $exception) {
+            $output->writeln('处理失败,' . $exception->getMessage());
         }
 
     }