Browse Source

脚本格式化

wufeng 2 years ago
parent
commit
4522f3b590
1 changed files with 389 additions and 388 deletions
  1. 389 388
      app/command/ImportOrderFromCHandleData.php

+ 389 - 388
app/command/ImportOrderFromCHandleData.php

@@ -5,7 +5,8 @@ namespace app\command;
 
 use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
-use app\admin\model\GoodStockInfo;use app\admin\model\OrderImportFromC as OIFCModel;
+use app\admin\model\GoodStockInfo;
+use app\admin\model\OrderImportFromC as OIFCModel;
 use app\admin\model\ProcessOrder;
 use app\admin\model\Test1;
 use think\console\Command;
@@ -40,80 +41,80 @@ class ImportOrderFromCHandleData extends Command
 
 //        if (!$c_data_id) $output->writeln('没有符合条件的记录');
 //        else {
-            $order_import_from_c_db = new OIFCModel();
+        $order_import_from_c_db = new OIFCModel();
 
-            $c_data = $order_import_from_c_db
-                ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_relation])
+        $c_data = $order_import_from_c_db
+            ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_relation])
 //                ->lock(true)
-                ->field('id,createrid,creater')
-                ->findOrEmpty()
-                ->toArray();
+            ->field('id,createrid,creater')
+            ->findOrEmpty()
+            ->toArray();
 
-            if (!empty($c_data)) {
+        if (!empty($c_data)) {
 
-                Db::startTrans();
-                try {
+            Db::startTrans();
+            try {
 
-                    $standing_book_data = [];
+                $standing_book_data = [];
 
-                    //先找用户确认信息
+                //先找用户确认信息
+                $extend_data = Db::name('order_import_from_c_extend')
+                    ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 2])
+                    ->find();
+                if (empty($extend_data)) {
                     $extend_data = Db::name('order_import_from_c_extend')
-                        ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 2])
+                        ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 1])
                         ->find();
-                    if (empty($extend_data)) {
-                        $extend_data = Db::name('order_import_from_c_extend')
-                            ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 1])
-                            ->find();
-                    }
+                }
 
-                    if (empty($extend_data)) throw new Exception('没有对应的解析数据');
+                if (empty($extend_data)) throw new Exception('没有对应的解析数据');
 
-                    //复用sale::create()方法 -- start
+                //复用sale::create()方法 -- start
 
-                    $orderCode = makeNo("QR");
-                    $customer_code = $extend_data['customer_code'];
+                $orderCode = makeNo("QR");
+                $customer_code = $extend_data['customer_code'];
 
-                    $customer = Db::connect('mysql_sys')
-                        ->name("customer_info")
-                        ->where(["companyNo" => $customer_code])
-                        ->find();
+                $customer = Db::connect('mysql_sys')
+                    ->name("customer_info")
+                    ->where(["companyNo" => $customer_code])
+                    ->find();
 
-                    if ($customer == false) throw new Exception('未找到客户数据');
+                if ($customer == false) throw new Exception('未找到客户数据');
 
-                    $supplierNo = $extend_data['companyNo'];
-                    $supplier = Db::connect('mysql_sys')
-                        ->name("business")
-                        ->where(["companyNo" => $supplierNo])
-                        ->find();
-                    if ($supplier == false) throw new Exception('未找到平台供应商数据');
-
-                    $goodtype = 1;//1正常商品
-
-                    $sendtype = 1;//直接发货
-                    $platform_id = $extend_data['platform_id'];
-
-                    $platform_order = $extend_data['platform_code'];
-                    $good_num = $extend_data['num'];
-                    $arrtime = $extend_data['platform_time'];
-                    $paytime = $extend_data['addtime'];
-                    $workNo = $extend_data['po_code'];
-                    $ct = Db::name('good_platform')
-                        ->alias('a')
-                        ->join('good b', 'b.spuCode=a.spuCode', 'left')
-                        ->where(['a.skuCode' => $extend_data['skuCode'], 'a.exam_status' => 6])//exam_status==6已上线
-                        ->field("b.*,a.skuCode,a.spuCode,a.platform_code,a.plat_code")
-                        ->find();
-                    if ($ct == false) throw new Exception('未找到商品数据');
+                $supplierNo = $extend_data['companyNo'];
+                $supplier = Db::connect('mysql_sys')
+                    ->name("business")
+                    ->where(["companyNo" => $supplierNo])
+                    ->find();
+                if ($supplier == false) throw new Exception('未找到平台供应商数据');
+
+                $goodtype = 1;//1正常商品
+
+                $sendtype = 1;//直接发货
+                $platform_id = $extend_data['platform_id'];
+
+                $platform_order = $extend_data['platform_code'];
+                $good_num = $extend_data['num'];
+                $arrtime = $extend_data['platform_time'];
+                $paytime = $extend_data['addtime'];
+                $workNo = $extend_data['po_code'];
+                $ct = Db::name('good_platform')
+                    ->alias('a')
+                    ->join('good b', 'b.spuCode=a.spuCode', 'left')
+                    ->where(['a.skuCode' => $extend_data['skuCode'], 'a.exam_status' => 6])//exam_status==6已上线
+                    ->field("b.*,a.skuCode,a.spuCode,a.platform_code,a.plat_code")
+                    ->find();
+                if ($ct == false) throw new Exception('未找到商品数据');
 
-                    $goodinfo = $ct;
-                    $is_stock = $ct['is_stock'];
-                    $order_type = $is_stock == 1 ? 1 : 2;//1备库(库存品)2非库存品
-                    $order_source = 4;//4平台
-                    $spuCode = $ct['spuCode'];
-                    $skuCode = $ct['skuCode'];
-                    $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
+                $goodinfo = $ct;
+                $is_stock = $ct['is_stock'];
+                $order_type = $is_stock == 1 ? 1 : 2;//1备库(库存品)2非库存品
+                $order_source = 4;//4平台
+                $spuCode = $ct['spuCode'];
+                $skuCode = $ct['skuCode'];
+                $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
 
-                    if ($goodinfo['is_stock'] == 1) {
+                if ($goodinfo['is_stock'] == 1) {
 //                        $stock = Db::name("good_stock")
 //                            ->alias("a")
 //                            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
@@ -126,203 +127,203 @@ class ImportOrderFromCHandleData extends Command
 //				            if($stock_num <  $good_num){
 //				              throw new Exception('bn库存数量不足');
 //				            }
-			            $stock_num = Db::name("good_stock")->alias("a")
-			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
-			            ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
-			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
-			            ->sum('balance_num');
-			            if($stock_num < $good_num){
-			               throw new Exception('bn库存数量不足');
-			            }
-                        $origin_price = 0;
+                    $stock_num = Db::name("good_stock")->alias("a")
+                        ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+                        ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
+                        ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" => $supplierNo])
+                        ->sum('balance_num');
+                    if ($stock_num < $good_num) {
+                        throw new Exception('bn库存数量不足');
+                    }
+                    $origin_price = 0;
 
-                    } else {
+                } else {
 
-                        $origin = Db::name("good_nake")
-                            ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
-                            ->order("min_num desc")
-                            ->find();
-                        if ($origin == false) throw new Exception('未找到相关成本价格');
+                    $origin = Db::name("good_nake")
+                        ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
+                        ->order("min_num desc")
+                        ->find();
+                    if ($origin == false) throw new Exception('未找到相关成本价格');
 
-                        $origin_price = $origin['nake_total'];
+                    $origin_price = $origin['nake_total'];
 
-                    }
+                }
 
-                    $sale_price = $extend_data['price'];
-                    if ($goodtype == 1) {
-                        $good = Db::name("good_ladder")
-                            ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
-                            ->where([["min_num", "<=", $good_num]])
-                            ->order("min_num desc")
-                            ->find();
-                        if ($good == false) throw new Exception('未找到相关阶梯价格');
+                $sale_price = $extend_data['price'];
+                if ($goodtype == 1) {
+                    $good = Db::name("good_ladder")
+                        ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
+                        ->where([["min_num", "<=", $good_num]])
+                        ->order("min_num desc")
+                        ->find();
+                    if ($good == false) throw new Exception('未找到相关阶梯价格');
 
-                        //$sale_price = $good['sale_price']; //不改动售价
+                    //$sale_price = $good['sale_price']; //不改动售价
 
-                        //理论上不会出现实时金价的订单
-                        if ($ct['is_gold_price'] == 1 && $is_stock != 1) {
-                            $gold = Db::name("gold_price1")
-                                ->field('id,price')
-                                ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
-                                ->order("addtime desc")
-                                ->find();
+                    //理论上不会出现实时金价的订单
+                    if ($ct['is_gold_price'] == 1 && $is_stock != 1) {
+                        $gold = Db::name("gold_price1")
+                            ->field('id,price')
+                            ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
+                            ->order("addtime desc")
+                            ->find();
 
-                            //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
-                            $gold_sale_price = $ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num + $ct['noble_weight'] * $gold["price"] + $good['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
-                            if ($sale_price < $gold_sale_price) throw new Exception('价格不符合根据实时金价计算出的最终售价');
+                        //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
+                        $gold_sale_price = $ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num + $ct['noble_weight'] * $gold["price"] + $good['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
+                        if ($sale_price < $gold_sale_price) throw new Exception('价格不符合根据实时金价计算出的最终售价');
 
-                            $ct['cgd_gold_price'] = $gold['price'];
+                        $ct['cgd_gold_price'] = $gold['price'];
 
 //                $order_rate = Db::name("cat")->where(["id" => $ct['cat_id']])->value('order_rate');
 //                $budget = isset($order_rate) ? $order_rate / 100 : 0;
 
-                            // $saleprice = $total_fee / (1 - $budget);
-                        }
-
-                        if ($is_activity == 1) {
-                            $act = Db::name("activity_info")
-                                ->alias("a")
-                                ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
-                                ->where(["a.skuCode" => $skuCode, "a.activity_code" => $extend_data['activity_code'], "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
-                                ->find();
-                            if ($act == false) throw new Exception('未找到相关活动价');
-                            if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
-                            if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
-                            //$sale_price = $act['activity_price'];//不能改动价格
-                        }
+                        // $saleprice = $total_fee / (1 - $budget);
                     }
-                     $supplier_temp_info = Db::connect('mysql_sys')
-                         ->name('supplier')
-                        ->field('id,name,person,personid')
-                        ->where('code', $ct['supplierNo'])
-                        ->findOrEmpty();
-                    $cgd = [
-                        "supplierNo" => $ct['supplierNo'],
-                        "supplier_name" =>$supplier_temp_info['name'] ,
-                        "companyNo" => $supplierNo,
-                        "companyName" =>$supplier['company'] ,
-                        "orderCode" => $orderCode,
-                        "spuCode" => $ct['spuCode'],
-                        "skuCode" => $ct['skuCode'],
-                        "good_name" => $ct['good_name'],
-                        "sale_price" => $origin_price,
-                        "total_fee" => $origin_price * $good_num,
-                        "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
-                        "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
-                        "open_fee" => $ct['open_fee'],
-                        "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
-                        "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
-                        "demo_fee" => $ct['demo_fee'],
-                        "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
-                        "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
-                        "good_num" => $good_num,
-                        "good_type" => $goodtype,
-                        "order_type" => $order_type,
-                        "order_source" => $order_source,
-                        "createrid" =>$supplier_temp_info['personid'],
-                        "creater" =>$supplier_temp_info['person'],
-                        'send_way' => 2,
-                        'gold_price' => $ct['cgd_gold_price'],
-                        'good_createrid' => $goodinfo['createrid'],
-                        'good_creater' => $goodinfo['creater'],//商品创建人
-                        "weight"=>$ct['noble_weight']
-                    ];
 
-                    $send_num = $extend_data['num'];
-                    $remark = $extend_data['order_remark'];
-                    $rm = $c_data['createrid'];
-                    $ri = $c_data['creater'];
-
-
-                    $data = [
-                        "orderCode" => $orderCode,
-                        "good_code" => $spuCode,
-                        "skuCode" => $skuCode,
-                        "customer_code" => $customer_code,
-                        "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
-                        "good_num" => $good_num,
-                        "cat_id" => $goodinfo['cat_id'],
-                        "apply_id" => $rm,
-                        "apply_name" => $ri,
-                        "origin_price" => $origin_price,
-                        "sale_price" => $sale_price,
-                        "post_fee" => 0,
-                        "status" => 0,
-                        "send_num" => 0,
-                        "wsend_num" => $good_num,
-                        "send_status" => 1,
-                        "good_type" => $goodtype,
-                        "send_type" => $sendtype,
-                        "supplierNo" => $extend_data['companyNo'],
-                        "is_del" => 0,
-                        "zxNo" => "",
-                        "platform_order" => $platform_order,
-                        "platform_id" => $platform_id,
-                        "remark" => $remark,
-                        "is_stock" => $is_stock,
-                        "is_activity" => $is_activity === "" ? 0 : $is_activity,
-                        'activity_code' => $extend_data['activity_code'],
-                        "order_type" => $order_type,
-                        "order_source" => $order_source,
+                    if ($is_activity == 1) {
+                        $act = Db::name("activity_info")
+                            ->alias("a")
+                            ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
+                            ->where(["a.skuCode" => $skuCode, "a.activity_code" => $extend_data['activity_code'], "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
+                            ->find();
+                        if ($act == false) throw new Exception('未找到相关活动价');
+                        if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
+                        if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
+                        //$sale_price = $act['activity_price'];//不能改动价格
+                    }
+                }
+                $supplier_temp_info = Db::connect('mysql_sys')
+                    ->name('supplier')
+                    ->field('id,name,person,personid')
+                    ->where('code', $ct['supplierNo'])
+                    ->findOrEmpty();
+                $cgd = [
+                    "supplierNo" => $ct['supplierNo'],
+                    "supplier_name" => $supplier_temp_info['name'],
+                    "companyNo" => $supplierNo,
+                    "companyName" => $supplier['company'],
+                    "orderCode" => $orderCode,
+                    "spuCode" => $ct['spuCode'],
+                    "skuCode" => $ct['skuCode'],
+                    "good_name" => $ct['good_name'],
+                    "sale_price" => $origin_price,
+                    "total_fee" => $origin_price * $good_num,
+                    "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
+                    "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
+                    "open_fee" => $ct['open_fee'],
+                    "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
+                    "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
+                    "demo_fee" => $ct['demo_fee'],
+                    "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
+                    "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
+                    "good_num" => $good_num,
+                    "good_type" => $goodtype,
+                    "order_type" => $order_type,
+                    "order_source" => $order_source,
+                    "createrid" => $supplier_temp_info['personid'],
+                    "creater" => $supplier_temp_info['person'],
+                    'send_way' => 2,
+                    'gold_price' => $ct['cgd_gold_price'],
+                    'good_createrid' => $goodinfo['createrid'],
+                    'good_creater' => $goodinfo['creater'],//商品创建人
+                    "weight" => $ct['noble_weight']
+                ];
+
+                $send_num = $extend_data['num'];
+                $remark = $extend_data['order_remark'];
+                $rm = $c_data['createrid'];
+                $ri = $c_data['creater'];
+
+
+                $data = [
+                    "orderCode" => $orderCode,
+                    "good_code" => $spuCode,
+                    "skuCode" => $skuCode,
+                    "customer_code" => $customer_code,
+                    "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
+                    "good_num" => $good_num,
+                    "cat_id" => $goodinfo['cat_id'],
+                    "apply_id" => $rm,
+                    "apply_name" => $ri,
+                    "origin_price" => $origin_price,
+                    "sale_price" => $sale_price,
+                    "post_fee" => 0,
+                    "status" => 0,
+                    "send_num" => 0,
+                    "wsend_num" => $good_num,
+                    "send_status" => 1,
+                    "good_type" => $goodtype,
+                    "send_type" => $sendtype,
+                    "supplierNo" => $extend_data['companyNo'],
+                    "is_del" => 0,
+                    "zxNo" => "",
+                    "platform_order" => $platform_order,
+                    "platform_id" => $platform_id,
+                    "remark" => $remark,
+                    "is_stock" => $is_stock,
+                    "is_activity" => $is_activity === "" ? 0 : $is_activity,
+                    'activity_code' => $extend_data['activity_code'],
+                    "order_type" => $order_type,
+                    "order_source" => $order_source,
 //                "poNo"=>$poNo,
-                        'good_weight' => $ct['weight'],
-                        'gold_price' => $ct['cgd_gold_price'],
-                        'cost_price' => $ct['cost_fee'],
-                        'diff_weight' => 0,
-                        'diff_fee' => 0,
-                        "workNo" => $workNo,
-                        "addtime" => date("Y-m-d H:i:s"),
-                        "updatetime" => date("Y-m-d H:i:s"),
-                        'total_price' => round($sale_price * $good_num, 2),
-                        'cgderid' => $supplier_temp_info['personid'],
-                        'cgder' => $supplier_temp_info['person'],//采购员(供应商负责人)
-                        'good_createrid' => $goodinfo['createrid'],
-                        'good_creater' => $goodinfo['creater'],//商品创建人
-                    ];
-                    $paytime == "" ? "" : $data['paytime'] = $paytime;
-                    $datainfo = Db::name('sale')->insert($data, true);
-                    if ($datainfo > 0) {
-                        if ($is_activity == 1) {
-                            $actup = [
-                                "activity_stock" => $act['activity_stock'] - $good_num,
-                                "updatetime" => date("Y-m-d H:i:s")
-                            ];
-                            $actupp = Db::name("activity_info")
-                                ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
-                                ->save($actup);
-                            if ($actupp == false) throw new Exception('活动库存修改失败');
+                    'good_weight' => $ct['weight'],
+                    'gold_price' => $ct['cgd_gold_price'],
+                    'cost_price' => $ct['cost_fee'],
+                    'diff_weight' => 0,
+                    'diff_fee' => 0,
+                    "workNo" => $workNo,
+                    "addtime" => date("Y-m-d H:i:s"),
+                    "updatetime" => date("Y-m-d H:i:s"),
+                    'total_price' => round($sale_price * $good_num, 2),
+                    'cgderid' => $supplier_temp_info['personid'],
+                    'cgder' => $supplier_temp_info['person'],//采购员(供应商负责人)
+                    'good_createrid' => $goodinfo['createrid'],
+                    'good_creater' => $goodinfo['creater'],//商品创建人
+                ];
+                $paytime == "" ? "" : $data['paytime'] = $paytime;
+                $datainfo = Db::name('sale')->insert($data, true);
+                if ($datainfo > 0) {
+                    if ($is_activity == 1) {
+                        $actup = [
+                            "activity_stock" => $act['activity_stock'] - $good_num,
+                            "updatetime" => date("Y-m-d H:i:s")
+                        ];
+                        $actupp = Db::name("activity_info")
+                            ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
+                            ->save($actup);
+                        if ($actupp == false) throw new Exception('活动库存修改失败');
 
-                        }
+                    }
 
-                        //补充台账数据
-                        $standing_book_data = array_merge($standing_book_data, [
-                            'orderCode' => $orderCode,
-                            'spuCode' => $data['good_code'],
-                            'skuCode' => $data['skuCode'],
-                            'order_type' => $data['order_type'],
-                            'order_source' => $data['order_source'],
-                            'supplierNo' => $extend_data['supplierNo'],
-                            'companyNo' => $extend_data['companyNo'],
-                            'customer_code' => $data['customer_code'],
-                        ]);
-                        if ($is_stock == 0) {
-
-                            //非库存品
-                            $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
-                            if ($bol == false) throw new Exception('订单创建失败');
-
-                        } else {
-                            //库存品
+                    //补充台账数据
+                    $standing_book_data = array_merge($standing_book_data, [
+                        'orderCode' => $orderCode,
+                        'spuCode' => $data['good_code'],
+                        'skuCode' => $data['skuCode'],
+                        'order_type' => $data['order_type'],
+                        'order_source' => $data['order_source'],
+                        'supplierNo' => $extend_data['supplierNo'],
+                        'companyNo' => $extend_data['companyNo'],
+                        'customer_code' => $data['customer_code'],
+                    ]);
+                    if ($is_stock == 0) {
+
+                        //非库存品
+                        $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
+                        if ($bol == false) throw new Exception('订单创建失败');
+
+                    } else {
+                        //库存品
 //                            $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo, 'order_type' => $order_type, 'order_source' => $order_source,'good_createrid'=>$ct['createrid'],'good_creater'=>$ct['creater']], $standing_book_data);
 //                            if ($bol == false) throw new Exception('库存商品关联采购单失败');
-						 $stockid= Db::name("good_stock")->alias("a")
-			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
-			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
-			            ->column('a.id');
-	                        $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,intval($good_num));
-	                        if($stockinfo==false){
-	                             throw new Exception('库存商品更新库存失败');
-	                        }
+                        $stockid = Db::name("good_stock")->alias("a")
+                            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+                            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" => $supplierNo])
+                            ->column('a.id');
+                        $stockinfo = GoodStockInfo::OrderBn($orderCode, $stockid, intval($good_num));
+                        if ($stockinfo == false) {
+                            throw new Exception('库存商品更新库存失败');
+                        }
 
 //                            if (isset($stock)) {
 //                                $stck = [
@@ -344,166 +345,166 @@ class ImportOrderFromCHandleData extends Command
 //                                GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
 //                            }
 
-                        }
-                        if ($sendtype == 1) {
-                            $temp = [
-                                'orderCode' => $orderCode,
-                                'contactor' => $extend_data['contactor'],
-                                'mobile' => $extend_data['mobile'],
-                                'addr' => $extend_data['addr'],
-                                'addr_code' => $extend_data['addr_code'],
-                                'customer_code' => $customer_code,
-                                'receipt_quantity' => $extend_data['num'],//收货数量,
-                                'post_fee' => 0,
-                                'is_del' => 0,
-                                'addtime' => date("Y-m-d H:i:s"),
-                                'updatetime' => date("Y-m-d H:i:s"),
-                                'arrive_time' => $arrtime,
-                            ];
-                            $vmp = Db::name('order_addr')->insert($temp, true);
-                            if ($vmp > 0) {
-                            	 $num = $extend_data['num'];
-                                $outCode = makeNo("DF");
-                            	if($is_stock!=1){
-	                                    $order = Db::name("order_num")
-	                                    ->where(["orderCode" => $orderCode, "status" => 1])
-	                                    ->where([["wsend_num", ">=", 0]])
+                    }
+                    if ($sendtype == 1) {
+                        $temp = [
+                            'orderCode' => $orderCode,
+                            'contactor' => $extend_data['contactor'],
+                            'mobile' => $extend_data['mobile'],
+                            'addr' => $extend_data['addr'],
+                            'addr_code' => $extend_data['addr_code'],
+                            'customer_code' => $customer_code,
+                            'receipt_quantity' => $extend_data['num'],//收货数量,
+                            'post_fee' => 0,
+                            'is_del' => 0,
+                            'addtime' => date("Y-m-d H:i:s"),
+                            'updatetime' => date("Y-m-d H:i:s"),
+                            'arrive_time' => $arrtime,
+                        ];
+                        $vmp = Db::name('order_addr')->insert($temp, true);
+                        if ($vmp > 0) {
+                            $num = $extend_data['num'];
+                            $outCode = makeNo("DF");
+                            if ($is_stock != 1) {
+                                $order = Db::name("order_num")
+                                    ->where(["orderCode" => $orderCode, "status" => 1])
+                                    ->where([["wsend_num", ">=", 0]])
 //	                                    ->lock(true)
-	                                    ->find();
-	                                if ($order == false) throw new Exception('未找到可以发货得采购单数据');
-	                                $order['wsend_num'] -= $num;
-	                                $order['send_num'] += $num;
-	                                $or = Db::name("order_num")->save($order);
-	                                if ($or == false) throw new Exception('发货地址更新失败');
-
-	                                $tep = [
-	                                    "cgdNo" => $order['cgdNo'],
-	                                    "outCode" => $outCode,
-	                                    "send_num" => $num,
-	                                    "status" => 1,
-	                                    "addtime" => date("Y-m-d H:i:s"),
-	                                    "updatetime" => date("Y-m-d H:i:s")
-	                                ];
-	                                $sen = Db::name("order_send")->save($tep);
-	                                if ($sen == false) throw new Exception('发货地址添加创建失败');
-
-	                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
-	                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
-
-                            	}
-
-                                $out = [
-                                    "orderCode" => $orderCode,
+                                    ->find();
+                                if ($order == false) throw new Exception('未找到可以发货得采购单数据');
+                                $order['wsend_num'] -= $num;
+                                $order['send_num'] += $num;
+                                $or = Db::name("order_num")->save($order);
+                                if ($or == false) throw new Exception('发货地址更新失败');
+
+                                $tep = [
+                                    "cgdNo" => $order['cgdNo'],
                                     "outCode" => $outCode,
-                                    "apply_id" => $rm,
-                                    "apply_name" => $ri,
-                                    "addrid" => $vmp,
-                                    "post_name" => "",
-                                    "post_code" => "",
-                                    "post_fee" => 0,
-                                    "sendtime" => date("Y-m-d H:i:s"),
                                     "send_num" => $num,
-                                    "check_num" => 0,
-                                    "error_num" => 0,
-                                    "wsm_code" =>$is_stock==1?'': $cgdinfo['wsm_code'],
-                                    "order_type" => $order_type,
-                                    "status" => $is_stock == 1 ? 1 : 0,
+                                    "status" => 1,
                                     "addtime" => date("Y-m-d H:i:s"),
                                     "updatetime" => date("Y-m-d H:i:s")
                                 ];
-                                $ou = Db::name("order_out")->insertGetId($out);
-                                if ($ou == false) throw new Exception('发货地址添加创建失败');
-                                else {
-                                	    //修改状态,添加待办
-                                	    if ($is_stock==1){
-                                	    	$roleid = Config('app.wsm_cgder_role');
-		                            $uids = Db::name('user_role')
-		                                ->where('is_del', 0)
-		                                ->whereIn('roleid', $roleid)
-		                                ->column('uid');
-		                            $handle_user_list=implode(',', $uids);
-                                	    }
-
-                                    //修改状态,添加待办
-                                    ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
-                                        "order_code" => $outCode,//出库单号
-                                        "status" => 0,//这里的status是之前的值
-                                        "action_remark" => '',//备注
-                                        "action_type" => "create"//新建create,编辑edit,更改状态status
-                                    ], "CKD", 0, $out);
-
-                                    ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
-                                        "order_type" => 'CKD',
-                                        "order_code" => $outCode,//出库单号
-                                        "order_id" => $ou,
-                                        "order_status" => $is_stock == 1 ? 1 : 0,
-                                        "before_status" => 0,
-                                        'holder_id' =>  $rm,
-                                        'handle_user_list' =>$handle_user_list??""
-                                    ]);
-
-                                    $standing_book_data['outCode'] = $outCode;
+                                $sen = Db::name("order_send")->save($tep);
+                                if ($sen == false) throw new Exception('发货地址添加创建失败');
+
+                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
+                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
+
+                            }
+
+                            $out = [
+                                "orderCode" => $orderCode,
+                                "outCode" => $outCode,
+                                "apply_id" => $rm,
+                                "apply_name" => $ri,
+                                "addrid" => $vmp,
+                                "post_name" => "",
+                                "post_code" => "",
+                                "post_fee" => 0,
+                                "sendtime" => date("Y-m-d H:i:s"),
+                                "send_num" => $num,
+                                "check_num" => 0,
+                                "error_num" => 0,
+                                "wsm_code" => $is_stock == 1 ? '' : $cgdinfo['wsm_code'],
+                                "order_type" => $order_type,
+                                "status" => $is_stock == 1 ? 1 : 0,
+                                "addtime" => date("Y-m-d H:i:s"),
+                                "updatetime" => date("Y-m-d H:i:s")
+                            ];
+                            $ou = Db::name("order_out")->insertGetId($out);
+                            if ($ou == false) throw new Exception('发货地址添加创建失败');
+                            else {
+                                //修改状态,添加待办
+                                if ($is_stock == 1) {
+                                    $roleid = Config('app.wsm_cgder_role');
+                                    $uids = Db::name('user_role')
+                                        ->where('is_del', 0)
+                                        ->whereIn('roleid', $roleid)
+                                        ->column('uid');
+                                    $handle_user_list = implode(',', $uids);
                                 }
-                            } else throw new Exception('发货地址添加失败');
-                        }
-                    }
 
-                    //复用sale::create()方法 -- end
-
-                    //处理完成
-                    $order_import_from_c_db
-                        ->where('id', $c_data['id'])
-                        ->where('is_del', OIFCModel::$is_del_normal)
-                        ->save([
-                            'status' => $order_import_from_c_db::$status_success,
-                            'updatetime' => date('Y-m-d H:i:s'),
-                            'remark' => '',
-                            'updateid' => 0,
-                            'updater' => 'system',
-                            'orderCode' => $orderCode
-                        ]);
-
-                    //维护台账记录
-                    Db::name('standing_book')->insert(array_merge($standing_book_data, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
-
-                    //将采购单数据塞入到队列中
-                    if ($this->cgd_data) {
-                        $push_data = json_encode([
-                            'supplierNo' => $this->cgd_data['supplierNo'],
-                            'type' => 1,//1销售订单(采销的采购单),2上线结果
-                            'data' => [
-                                'cgdNo' => $this->cgd_data['cgdNo'],
-                                'spuCode' => $this->cgd_data['spuCode'],
-                                'good_name' => $this->cgd_data['good_name'],
-                                'good_num' => $this->cgd_data['good_num'],
-                                'good_price' => $this->cgd_data['good_price'],
-                                'total_fee' => $this->cgd_data['total_fee'],
-                                'weight' => $this->cgd_data['weight'],
-                                'addtime' => $this->cgd_data['addtime'],
-                            ],
-                        ], JSON_UNESCAPED_UNICODE);
-//                        Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+                                //修改状态,添加待办
+                                ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
+                                    "order_code" => $outCode,//出库单号
+                                    "status" => 0,//这里的status是之前的值
+                                    "action_remark" => '',//备注
+                                    "action_type" => "create"//新建create,编辑edit,更改状态status
+                                ], "CKD", 0, $out);
+
+                                ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
+                                    "order_type" => 'CKD',
+                                    "order_code" => $outCode,//出库单号
+                                    "order_id" => $ou,
+                                    "order_status" => $is_stock == 1 ? 1 : 0,
+                                    "before_status" => 0,
+                                    'holder_id' => $rm,
+                                    'handle_user_list' => $handle_user_list ?? ""
+                                ]);
+
+                                $standing_book_data['outCode'] = $outCode;
+                            }
+                        } else throw new Exception('发货地址添加失败');
                     }
+                }
 
-                    Db::commit();
-
-                    $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
-
-                } catch (\think\Exception $exception) {
-                    Db::rollback();
-                    $order_import_from_c_db
-                        ->where(['id' => $c_data['id'], 'status' => OIFCModel::$status_wait_relation])
-                        ->save([
-                            'status' => $order_import_from_c_db::$status_stock_not_enough,
-                            'updatetime' => date('Y-m-d H:i:s'),
-                            'remark' => $exception->getMessage(),
-                            'updateid' => 0,
-                            'updater' => 'system'
-                        ]);
-                    // 指令输出
-                    $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
+                //复用sale::create()方法 -- end
+
+                //处理完成
+                $order_import_from_c_db
+                    ->where('id', $c_data['id'])
+                    ->where('is_del', OIFCModel::$is_del_normal)
+                    ->save([
+                        'status' => $order_import_from_c_db::$status_success,
+                        'updatetime' => date('Y-m-d H:i:s'),
+                        'remark' => '',
+                        'updateid' => 0,
+                        'updater' => 'system',
+                        'orderCode' => $orderCode
+                    ]);
+
+                //维护台账记录
+                Db::name('standing_book')->insert(array_merge($standing_book_data, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
+
+                //将采购单数据塞入到队列中
+                if ($this->cgd_data) {
+                    $push_data = json_encode([
+                        'supplierNo' => $this->cgd_data['supplierNo'],
+                        'type' => 1,//1销售订单(采销的采购单),2上线结果
+                        'data' => [
+                            'cgdNo' => $this->cgd_data['cgdNo'],
+                            'spuCode' => $this->cgd_data['spuCode'],
+                            'good_name' => $this->cgd_data['good_name'],
+                            'good_num' => $this->cgd_data['good_num'],
+                            'good_price' => $this->cgd_data['good_price'],
+                            'total_fee' => $this->cgd_data['total_fee'],
+                            'weight' => $this->cgd_data['weight'],
+                            'addtime' => $this->cgd_data['addtime'],
+                        ],
+                    ], JSON_UNESCAPED_UNICODE);
+//                        Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
                 }
+
+                Db::commit();
+
+                $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
+
+            } catch (\think\Exception $exception) {
+                Db::rollback();
+                $order_import_from_c_db
+                    ->where(['id' => $c_data['id'], 'status' => OIFCModel::$status_wait_relation])
+                    ->save([
+                        'status' => $order_import_from_c_db::$status_stock_not_enough,
+                        'updatetime' => date('Y-m-d H:i:s'),
+                        'remark' => $exception->getMessage(),
+                        'updateid' => 0,
+                        'updater' => 'system'
+                    ]);
+                // 指令输出
+                $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
             }
+        }
 //        }
 
     }
@@ -546,7 +547,7 @@ class ImportOrderFromCHandleData extends Command
         }
 
         //判断该供应商是否开通了供应商账号
-        $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
+        $from_tag = checkHasAccountBySupplierNos([$data['supplierNo']]);
 
         $cg = [
             "cgdNo" => $cgdCode,
@@ -568,7 +569,7 @@ class ImportOrderFromCHandleData extends Command
             "demo_fee" => $data['demo_fee'],
             "nake_fee" => $data['nake_fee'],
             "delivery_fee" => $data['delivery_fee'],
-            "weight"=>$data['weight'],
+            "weight" => $data['weight'],
             "diff_weight" => "0",
             "diff_fee" => "0",
             "gold_price" => $data['gold_price'],
@@ -611,8 +612,8 @@ class ImportOrderFromCHandleData extends Command
                 "order_status" => $cg['status'],
                 "before_status" => 0,
                 'holder_id' => $data['createrid'],
-                'wait_id'=>$data['createrid'],
-                'wait_name'=>$data['creater'],
+                'wait_id' => $data['createrid'],
+                'wait_name' => $data['creater'],
             ]);
 
             $standing_book_data['cgdNo'] = $cgdCode;