wugg 2 years ago
parent
commit
d356ce8a83

+ 61 - 21
app/admin/controller/Activity.php

@@ -117,33 +117,73 @@ class Activity extends Base
         $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
         $where = [["a.is_del", "=", 0]];
         $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
-        if ($good_code != "") {
-            $where[] = ['a.good_code', "like", "%$good_code%"];
-        }
+        if ($good_code != "") $where[] = ['a.good_code', "like", "%$good_code%"];
         $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
-        if ($good_name != "") {
-            $where[] = ['a.good_name', "like", "%$good_name%"];
-        }
-
+        if ($good_name != "") $where[] = ['a.good_name', "like", "%$good_name%"];
         $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
-        if($status!=""){
-            $where[]=['a.status',"=",$status];
-        }
+        if($status!="") $where[]=['a.status',"=",$status];
         $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
-        if ($supplierNo != "") {
-            $where[] = ['a.supplierNo', "like", "%$supplierNo%"];
-        }
+        if ($supplierNo != "") $where[] = ['a.supplierNo', "like", "%$supplierNo%"];
         $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
-        if ($name != "") {
-            $where[] = ['b.name', "like", "%$name%"];
-        }
-        $count = Db::name('good_zixun')->alias("a")->join("supplier b","b.code=a.supplierNo","left")
-            ->where($where)->count();
+        if ($name != "") $where[] = ['b.name', "like", "%$name%"];
+
+        $count = Db::name('good_zixun')
+            ->alias("a")
+            ->join("supplier b","b.code=a.supplierNo","left")
+            ->where($where)
+            ->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
-        $list = Db::name('good_zixun')->alias("a")->join("supplier b","b.code=a.supplierNo","left")
-            ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.name")->select();
-        return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
+        $list = Db::name('good_zixun')
+            ->alias("a")
+            ->join("supplier b","b.code=a.supplierNo","left")
+            ->where($where)
+            ->page($page,$size)
+            ->order("a.addtime desc")
+            ->field("a.*,b.name")
+            ->select()
+            ->toArray();
+//halt($list);
+        $data=[];
+        //分类/规格/品牌 等字段取出对应文字
+        foreach ($list as $value){
+            $value['cat_info']= made($value['cat_id'],[]);
+            $platform = Db::name("platform")->where(["id"=>$value['platform_id']])->find();
+            $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
+            $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
+            $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
+            $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
+            $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
+            $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
+            $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
+            $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
+//            $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
+//            $value['company'] = isset($company['company'])?$company['company']:"";
+            $value['stock_total'] = Db::name("good_stock")->where(['spuCode'=>$value['spuCode'],"is_del"=>0])->sum("usable_stock");
+//            $value['status']=$value['exam_status'];
+//            $value['exclusive']=makeExcluse($value['is_exclusive']);
+            $value['good_info_img']=$value['good_info_img'];
+            $value['good_img']=$value['good_img'];
+            $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
+            $speclist=[];
+            if(!empty($spec)){
+                foreach ($spec as $val){
+                    $temp=[];
+                    $temp['spec_id']=$val['spec_id'];
+                    $temp['spec_value_id']=$val['spec_value_id'];
+                    $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
+                    $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
+                    $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
+                    $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
+                    $speclist[]=$temp;
+                }
+            }
+            $value['specinfo']=$speclist;
+            $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
+            $data[]=$value;
+        }
+
+        return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
     }
 
     public function create(){

+ 62 - 32
app/admin/controller/Consult.php

@@ -730,10 +730,12 @@ class Consult extends Base
         }else{
 
             if($nake_fee){
-                $saleprice = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee / (1 - $budget);
+                $saleprice = ($open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee +
+                    $nake_fee)/ (1 - $budget);
                 $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
             }else{
-                $saleprice = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee / (1 - $budget);
+                $saleprice = ($open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee) /
+                    (1 - $budget);
                 $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee;
             }
 
@@ -1258,7 +1260,7 @@ class Consult extends Base
                 "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
                 "after_price"=>$bargain_price,
                 "exam_info"=>"",
-                "status"=>1,
+                "status"=>0,
                 "is_del"=>0,
                 "creater"=>$creater,
                 "createrid"=>$createrid,
@@ -1386,7 +1388,7 @@ class Consult extends Base
             return error_show(1004,"未找到咨询单数据");
         }
         $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
-        if($status==''){
+        if($status===''){
             return error_show(1005,"参数status不能为空");
         }
         $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
@@ -1406,20 +1408,21 @@ class Consult extends Base
         }else{
 
             if($bids['nake_fee']!=0){
-                $saleprice = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee']/ (1 - $budget);
-                $rate_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee']/ (1 - $rate);
-                $money_price =$bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee']/ (1 - $money_rate);
-                $lower_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee'] / (1 - $lower_rate);
+                $saleprice = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee'])/ (1 - $budget);
+                $rate_price = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee'])/ (1 - $rate);
+                $money_price =($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee'])/ (1 - $money_rate);
+                $lower_price = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] +  $bids['nake_fee']) / (1 - $lower_rate);
 
             }else{
-                $saleprice =  $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] / (1 - $budget);
-                $rate_price =$bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee']/ (1 - $rate);
-                $money_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] / (1 - $money_rate);
-                $lower_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'] / (1 - $lower_rate);
+                $saleprice = ($bids['open_fee']/$coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee']) / (1 - $budget);
+                $rate_price =($bids['open_fee'] /$coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'])/ (1 - $rate);
+                $money_price =($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee']) / (1 - $money_rate);
+                $lower_price = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+  $bids['cert_fee'])/ (1 - $lower_rate);
 
             }
 
         }
+        $ra_status = $info['status'];
         if($status==1){
             if($info['status']==0){
                 if($info['after_price']<$rate_price){
@@ -1427,18 +1430,16 @@ class Consult extends Base
                 }else{
                     $info['status']=1;
                 }
-            }
-            if($info['status']==2){
+            }elseif($info['status']==2){
                $info['status']=4;
-            }
-            if($info['status']==4||$info['status']==5){
+            }elseif($info['status']==4||$info['status']==5){
                 if($info['after_price']<$money_price){
                     $info['status']=7;
                 }else{
                     $info['status']=6;
                 }
-            }
-            if($info['status']==7){
+            }elseif($info['status']==7){
+                $info['lower_price'] =$lower_price;
                 if($info['after_price']<$lower_price){
                     $info['status']=10;
                 }else{
@@ -1448,14 +1449,12 @@ class Consult extends Base
         }else{
             if($info['status']==0){
                     $info['status']=3;
-            }
-            if($info['status']==2){
-                $info['status']=5;
-            }
-            if($info['status']==4||$info['status']==5){
+            }elseif($info['status']==2){
+                $info['status']=4;
+            }elseif($info['status']==4||$info['status']==5){
               $info['status']=8;
-            }
-            if($info['status']==7){
+            }elseif($info['status']==7){
+                $info['lower_price'] =$lower_price;
                 $info['status']=11;
             }
         }
@@ -1473,8 +1472,8 @@ class Consult extends Base
         Db::startTrans();
         try{
             $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
-            $examinfo[]=["status"=>$status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
-            $info['status'] =$status;
+            $examinfo[]=["status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
+//            $info['status'] =$status;
             $info['remark'] =$remark;
             $info['exam_info']=json_encode($examinfo) ;
             $info['updatetime'] =date("Y-m-d H:i:s");
@@ -1532,7 +1531,7 @@ class Consult extends Base
         $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
         $info['before_rate'] = $info['before_rate']*100;
         $info['after_rate'] = $info['after_rate']*100;
-        $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_encode($info['exam_info']):"";
+        $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
         if($bidinfos['brand_id']!=0){
             $info['brand_id'] = $bidinfos['brand_id'];
             $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
@@ -1547,6 +1546,7 @@ class Consult extends Base
         $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
         $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
         $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
+        $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
         $info['budget'] =$budget;
         $god=[
             "metal_id"=>$bidinfos['metal_id'],
@@ -1566,6 +1566,15 @@ class Consult extends Base
                 $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
                     ->find();
                 $info['gold_price'] =$gold['price'];
+                $lower_price = ($bidinfos['open_fee'] / $consultinfos['num'] + $bidinfos['weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
+
+            }else{
+                if($bidinfos['nake_fee']!=0){
+                          $lower_price =($bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+  $bidinfos['cert_fee'] +  $bidinfos['nake_fee']) / (1 - $lower_rate);
+
+                }else{
+                       $lower_price = ($bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+  $bidinfos['cert_fee'])/ (1 - $lower_rate);
+                }
             }
         $info['cost_desc'] =$bidinfos['cost_desc'];
         $info['work_day'] =$bidinfos['work_day'];
@@ -1611,7 +1620,9 @@ class Consult extends Base
         $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
         $info['sale_price'] =round($bidinfos['sale_price'],2);
         $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
-
+        if($info['status']==7){
+            $info['lower_price'] =round($lower_price,2);
+        }
         //获取议价原因
         if ($info['result_info_id'] != 0) {
             $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
@@ -1804,9 +1815,28 @@ class Consult extends Base
                 "cost_fee"=>$value["cost_fee"],
                 "num"=>$bidinfo["num"],
             ];
-            if($value['is_gold_price']==1){
-                $price = GoldPrice($god, $budget/100);
-                $value['sale_price'] =round($price,2);
+            if ($value['is_gold_price'] == 1 ) {
+                $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
+                    ->find();
+
+                //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
+                //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
+                $saleprice = ($value["open_fee"]/ $bidinfo['num'] + $value["weight"] * $gold["price"] + $value["cost_fee"] * $value["weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
+
+//                //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
+//                $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
+
+            }else{
+
+                if($value["nake_fee"]){
+                    $saleprice = ($value["open_fee"]/ $bidinfo['num']+$value["cost_fee"] * $value["weight"]+  $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
+
+                }else{
+                    $saleprice = ($value["open_fee"]/ $bidinfo['num']+$value["cost_fee"] * $value["weight"]+  $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
+                        (1 - $budget);
+
+                }
+
             }
             $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
 

+ 1 - 1
app/admin/controller/Good.php

@@ -707,7 +707,7 @@ class Good extends Base
             ->where($condition)
             ->where('whi.wsm_type','<>',2)//2表示虚拟仓,虚拟仓不参与
             ->leftJoin('warehouse_info whi','whi.wsm_code=gs.wsm_code AND whi.is_del=0')
-            ->field("sum(gs.wait_in_stock) as wait_in_stock,sum(gs.wait_out_stock) as wait_out_stock ,sum(gs.usable_stock) as usable_stock,sum(gs.intra_stock) as intra_stock,sum(gs.total_stock) as total_stock,sum(gs.warn_stock) as warn_stock")
+            ->field("sum(gs.wait_in_stock) as wait_in_stock,sum(gs.wait_out_stock) as wait_out_stock ,sum(gs.usable_stock) as usable_stock,sum(gs.intra_stock) as intra_stock,sum(gs.usable_stock+gs.wait_out_stock) as total_stock,sum(gs.warn_stock) as warn_stock")
             ->find();
         return app_show(0,"获取成功",$statlist);
     }

+ 332 - 41
app/admin/controller/OrderImport.php

@@ -4,6 +4,7 @@ namespace app\admin\controller;
 
 use app\admin\model\OrderImportFromC as OIFCModel;
 use Exception;
+use think\facade\Config;
 use think\facade\Db;
 use think\facade\Validate;
 
@@ -29,34 +30,11 @@ class OrderImport extends Base
             $createrid = isset($user["data"]['id']) ? $userinfo["data"]['id'] : 0;
             $creater = isset($user["data"]['nickname']) ? $userinfo["data"]['nickname'] : "";
 
-
-            $val = Validate::rule([
-                'platform_code|平台订单号' => 'require|length:0,255',
-                'po_code|其他单号' => 'length:0,255',
-                'platform_time|平台下单时间' => 'require|date',
-                'sale_source|销售渠道' => 'require|length:0,255',
-                'good_code|商品编号' => 'require|length:0,255',
-                'price|单价' => 'require|float',
-                'num|数量' => 'require|number',
-                'before_discount_all_price|优惠前总金额' => 'require|float',
-                'discount_price|优惠金额' => 'require|float',
-                'after_price|商品优惠后金额' => 'require|float',
-                'activity_name|优惠活动名称' => 'require|length:0,255',
-                'mode|收费模式' => 'require|length:0,255',
-                'order_remark|订单备注' => 'length:0,255',
-                'contactor|收货人' => 'require|length:0,255',
-                'mobile|联系电话' => 'require|length:0,20',
-                'addr|联系地址' => 'require|length:0,255',
-            ]);
-
             $insert_data = [];
             foreach ($param['list'] as $key => $value) {
-                if (!$val->check($value)) throw new \think\Exception('第' . (string)($key + 1) . '行数据格式有问题,' . $val->getError());
-                else {
-                    $value['createrid'] = $createrid;
-                    $value['creater'] = $creater;
-                    $insert_data[] = $value;
-                }
+                $value['createrid'] = $createrid;
+                $value['creater'] = $creater;
+                $insert_data[] = $value;
             }
 
             $res = Db::name('order_import_from_c')
@@ -90,7 +68,7 @@ class OrderImport extends Base
             'platform_time_end' => '',
             'addtime_start' => '',
             'addtime_end' => '',
-            'good_code' => '',
+            'plat_code' => '',
             'page' => 1,
             'size' => 15,
         ], 'post', 'trim');
@@ -101,7 +79,7 @@ class OrderImport extends Base
         if ($param['po_code']) $where[] = ['c.po_code', 'like', '%' . $param['po_code'] . '%'];
         if ($param['platform_time_start'] && $param['platform_time_end']) $where[] = ['c.platform_time', 'between', [$param['platform_time_start'], $param['platform_time_end']]];
         if ($param['addtime_start'] && $param['addtime_end']) $where[] = ['c.addtime', 'between', [$param['addtime_start'], $param['addtime_end']]];
-        if ($param['good_code']) $where[] = ['c.good_code', 'like', '%' . $param['good_code'] . '%'];
+        if ($param['plat_code']) $where[] = ['c.plat_code', 'like', '%' . $param['plat_code'] . '%'];
 
         $db = OIFCModel::alias('c')->where($where);
 
@@ -119,43 +97,356 @@ class OrderImport extends Base
     //查看订单录入详情
     public function getImportInfo()
     {
-
         $id = $this->request->post('id/d', 0, 'trim');
 
         $info = OIFCModel::alias('c')
-            ->field('c.*,ce.*,b.company,ci.companyName CustomerCompanyName,s.name supplierName')
+            ->field('c.*,ce.*,b.company,ci.companyName CustomerCompanyName,s.name supplierName,a.activity_code')
             ->leftJoin('order_import_from_c_extend ce', 'ce.order_import_from_c_id=c.id')
             ->leftJoin('business b', 'b.companyNo=ce.companyNo AND b.is_del=0')
             ->leftJoin('customer_info ci', 'ci.companyNo=ce.customer_code AND ci.is_del=0')
             ->leftJoin('supplier s', 's.code=ce.supplierNo AND s.is_del=0')
+            ->leftJoin('activity_info a', 'a.id=ce.activity_id AND a.is_del=0')
             ->where('c.id', $id)
             ->find();
 
-        $info['platform_names'] = Db::name('platform')
-            ->whereIn('platform_code', $info['platform_codes'])
-            ->where(['is_del' => 0, 'status' => 1])
-            ->column('platform_name');
-
-        $info['addr_name'] = GetAddr($info['addr_code']);
-
-
-        return app_show(0, '请求成功', $info);
+        if (!empty($info)) {
+            $info['platform_names'] = Db::name('platform')
+                ->whereIn('platform_code', $info['platform_codes'])
+                ->where(['is_del' => 0, 'status' => 1])
+                ->column('platform_name');
+
+            $info['addr_name'] = GetAddr($info['addr_code']);
+
+            $res['id'] = $info['id'];
+            $res['status'] = $info['status'];
+            $res['createrid'] = $info['createrid'];
+            $res['creater'] = $info['creater'];
+            $res['updateid'] = $info['updateid'];
+            $res['updater'] = $info['updater'];
+
+            //导入字段
+            $res['import'] = [
+                'platform_code' => $info['platform_code'],
+                'platform_time' => $info['platform_time'],
+                'plat_code' => $info['plat_code'],
+                'sale_source' => $info['sale_source'],
+                'price' => $info['price'],
+                'num' => $info['num'],
+                'before_discount_all_price' => $info['before_discount_all_price'],
+                'activity_name' => $info['activity_name'],
+                'mode' => $info['mode'],
+                'order_remark' => $info['order_remark'],
+                'contactor' => $info['contactor'],
+                'mobile' => $info['mobile'],
+                'addr' => $info['addr'],
+            ];
+            //确认字段
+            $res['confirm'] = $info;
+
+            //用户编辑字段
+            $user_update = Db::name('order_import_from_c_extend')
+                ->alias('ce')
+                ->field('ce.*,b.company,ci.companyName CustomerCompanyName,s.name supplierName,a.activity_code')
+                ->leftJoin('business b', 'b.companyNo=ce.companyNo AND b.is_del=0')
+                ->leftJoin('customer_info ci', 'ci.companyNo=ce.customer_code AND ci.is_del=0')
+                ->leftJoin('supplier s', 's.code=ce.supplierNo AND s.is_del=0')
+                ->leftJoin('activity_info a', 'a.id=ce.activity_id AND a.is_del=0')
+                ->where(['ce.order_import_from_c_id' => $id, 'ce.is_del' => 1])
+                ->order('ce.addtime', 'desc')
+                ->find();
+
+            if (empty($user_update)) $res['user_update'] = $res['confirm'];
+            else $res['user_update'] = array_merge($res['confirm'], $user_update);
+
+            return app_show(0, '请求成功', $res);
+
+        } else  return error_show(1005, '系统尚未解析完成,无法查看详情,请等待');
 
     }
 
     //用户确认订单数据(编辑)
     public function confirmImportData()
     {
+        //每次编辑,都新增一条记录到extend表,同时原纪录作废,确保同一个order_import_from_c_id下只有一个正常的记录
+        $param = $this->request->only([
+            'id',
+            'platform_code',
+            'po_code',
+            'platform_time',
+            'sale_source',
+            'plat_code',
+            'price',
+            'num',
+            'before_discount_all_price',
+            'activity_id',
+            'activity_name',
+            'mode',
+            'order_remark',
+            'contactor',
+            'mobile',
+            'addr',
+            'addr_code',
+        ], 'post', 'trim');
+
+        $val = Validate::rule([
+            'id' => 'require',
+            'platform_code' => 'require',
+            'po_code' => 'require',
+            'platform_time' => 'require',
+            'sale_source' => 'require',
+            'plat_code' => 'require',
+            'price' => 'require',
+            'num' => 'require',
+            'before_discount_all_price' => 'require',
+            'mode' => 'require',
+            'contactor' => 'require',
+            'mobile' => 'require',
+            'addr' => 'require',
+            'addr_code' => 'require',
+        ]);
+
+        if (!$val->check($param)) return error_show(1004, $val->getError());
+
+        Db::startTrans();
+        try {
+
+            $rs = Db::name('order_import_from_c')
+                ->where(['id' => $param['id'], 'is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_confirm])
+                ->find();
+            if (empty($rs)) throw new \think\Exception('该记录不存在或不允许用户确认');
+
+            $userinfo = GetUserInfo($param['token']);
+
+            Db::name('order_import_from_c')
+                ->where(['id' => $param['id'], 'is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_confirm])
+                ->update([
+                    'platform_code' => $param['platform_code'],
+                    'po_code' => $param['po_code'],
+                    'platform_time' => $param['platform_time'],
+                    'sale_source' => $param['sale_source'],
+                    'plat_code' => $param['plat_code'],
+                    'price' => $param['price'],
+                    'num' => $param['num'],
+                    'before_discount_all_price' => $param['before_discount_all_price'],
+                    'activity_name' => $param['activity_name'],
+                    'mode' => $param['mode'],
+                    'order_remark' => $param['order_remark'],
+                    'contactor' => $param['contactor'],
+                    'mobile' => $param['mobile'],
+                    'addr' => $param['addr'],
+                    'status' => OIFCModel::$status_wait_relation,
+                    'updatetime' => date('Y-m-d H:i:s')
+                ]);
+
+            Db::name('order_import_from_c_extend')
+                ->where(['order_import_from_c_id' => $param['id'], 'is_del' => 0])
+                ->update(['is_del' => 1]);
+
+            Db::name('order_import_from_c_extend')
+                ->insert([
+                    'order_import_from_c_id' => $param['id'],
+                    'addr_code' => $param['addr_code'],
+                    'activity_id' => $param['activity_id'],
+                    'addtime' => date('Y-m-d H:i:s'),
+                    'createrid' => isset($user["data"]['id']) ? $userinfo["data"]['id'] : 0,
+                    'creater' => isset($user["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
+                ]);
+
+            Db::commit();
+
+            return app_show(0, '修改成功');
+
+        } catch (\think\Exception $exception) {
+
+            Db::rollback();
+
+            return error_show(1004, $exception->getMessage());
+        }
+
     }
 
     //批量关联库存
     public function relationStockBatch()
     {
+
+        $param = $this->request->only(['ids', 'plat_code'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'ids' => 'require',
+            'plat_code|平台商品编号' => 'require',
+        ]);
+
+        if (!$val->check($param)) return error_show(1004, $val->getError());
+
+        $info = Db::name('order_import_from_c_extend')
+            ->field('id,spuCode,companyNo')
+            ->whereIn('id', $param['ids'])
+            ->find();
+
+        //判断库存是否充足
+        $num = Db::name('order_import_from_c')
+            ->whereIn('id', $param['ids'])
+            ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
+            ->sum('num');
+        $wsm_code = Db::name('warehouse_info')
+            ->where(['companyNo' => $info['companyNo'], 'is_del' => 0])
+            ->value('wsm_code');
+        $usable_stock = Db::name('good_stock')
+            ->where(['spuCode' => $info['spuCode'], 'wsm_code' => $wsm_code, 'is_del' => 0])
+            ->value('usable_stock', 0);
+
+        if ($usable_stock < $num) return error_show(1005, '可用库存只有' . $usable_stock . ',库存不足,关联失败');
+        else {
+
+            $userinfo = GetUserInfo($this->post['token']);
+
+            $res = Db::name('order_import_from_c')
+                ->whereIn('id', $param['ids'])
+                ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
+                ->update([
+                    'status' => OIFCModel::$status_wait_relation,
+                    'updatetime' => date('Y-m-d H:i:s'),
+                    'updateid' => isset($user["data"]['id']) ? $userinfo["data"]['id'] : 0,
+                    'updater' => isset($user["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
+                ]);
+
+            if ($res) return app_show(0, '批量关联库存成功');
+            else return error_show(1005, '批量关联库存失败');
+        }
+    }
+
+    //【辅助1】获取线上商品详情
+    public function getOnlineGoodInfoByPlatcode()
+    {
+        $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] != "" ? trim($this->post['plat_code']) : "";
+        if ($plat_code == "") {
+            return error_show(1005, "参数plat_code不能为空");
+        }
+        $good_platform = Db::name("good_platform")->where(['plat_code' => $plat_code, "is_del" => 0])->find();
+        if ($good_platform == false) {
+            return error_show(1004, "未找到商品数据");
+        }
+        $data = Db::name("good")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->find();
+        if ($data == false) {
+            return error_show(1004, "未找到商品数据");
+        }
+        $plat = Db::name("platform")->where(["id" => $good_platform['platform_code']])->find();
+        $data['skuCode'] = $good_platform['skuCode'];
+        $data['platform_code'] = $good_platform['platform_code'];
+        $data['platform_code_en'] = isset($plat['platform_code']) ? $plat['platform_code'] : "";
+        $data['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
+        $data['online_reason'] = $good_platform['online_reason'];
+        $data['online_time'] = $good_platform['online_time'];
+        $data['online_remark'] = $good_platform['online_remark'];
+        $data['exam_status'] = $good_platform['exam_status'];
+        $data['is_online'] = $good_platform['is_online'];
+        $data['plat_code'] = $good_platform['plat_code'];
+        $data['exclusive'] = makeExcluse($data['is_exclusive']);
+        $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
+        $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
+        $data['cat_info'] = made($data['cat_id'], []);
+        $spec = Db::name("good_spec")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
+        $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
+        $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
+
+        $noble = Config::get('noble');
+        $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $noble[$data['noble_metal']] : "";
+        $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
+        $data['company'] = isset($company['company']) ? $company['company'] : "";
+        if ($data['brand_id'] != 0) {
+            $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
+            $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
+        } else {
+            $data["brand_name"] = "";
+            $data["brand_id"] = "";
+        }
+        $data['origin_place_cn'] = "";
+        $data['delivery_place_cn'] = "";
+        if ($data['delivery_place'] !== "") {
+            $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
+            list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['delivery_place']);
+            $data['delivery_place_cn'] = GetAddr(json_encode($place));
+        }
+        if ($data['origin_place'] !== "") {
+            $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
+            list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['origin_place']);
+            $data['origin_place_cn'] = GetAddr(json_encode($place));
+        }
+        $excluse = makeExcluse($data['is_exclusive']);
+        $data['exclusive'] = $excluse;
+        $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : [];
+        $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
+        $speclist = [];
+        if (!empty($spec)) {
+            foreach ($spec as $value) {
+                $temp = [];
+                $temp['id'] = $value['id'];
+                $temp['spuCode'] = $value['spuCode'];
+                $temp['spec_id'] = $value['spec_id'];
+                $temp['spec_value_id'] = $value['spec_value_id'];
+                $temp['is_del'] = $value['is_del'];
+                $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
+                $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
+                $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                $speclist[] = $temp;
+            }
+        }
+        $data["speclist"] = empty($speclist) ? [] : $speclist;
+        $ladder = Db::name("good_ladder")->where(['skuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
+        $data["ladderlist"] = !empty($ladder) ? $ladder : [];
+        $nakelist = Db::name("good_nake")->where(['spuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
+
+        $cat_top_list = made($data['cat_id']);
+        $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
+        $nakearry = [];
+        if (!empty($nakelist)) {
+
+            //实时金价
+            $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
+            foreach ($nakelist as $value) {
+                $value['sale_price'] = $value['nake_total'];
+
+                //计算最终售价
+                if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
+                    //普通商品:直接用财务提交的售价字段;
+                    //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
+                    $value['sale_price'] = ($data['weight'] * $gold_price + $value['cost_fee'] * $data['weight'] + $value['package_fee'] + $value['mark_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['other_fee']);
+                }
+                $nakearry[] = $value;
+            }
+        }
+        $proof = Db::name("good_proof")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
+        $data['proof'] = isset($proof) && $proof != false ? $proof : [];
+        $data["nakelist"] = $nakearry;
+
+        //补充采购员字段
+        //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
+        $temp_basic_info = Db::name('good_basic')
+            ->field('id,createrid purchase_id,creater purchase')
+            ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
+            ->find();
+        $data['purchase_id'] = $temp_basic_info['purchase_id'];
+        $data['purchase'] = $temp_basic_info['purchase'];
+
+        return app_show(0, "获取成功", $data);
     }
 
-    //【脚本】批量解析用户导入的数据
-    public function analysisDataBatchBySystem()
+    //【辅助2】接口2-获取销售渠道备选数据:入参所在平台Id,响应:销售渠道备选数据
+    public function getSourceDataByPlatformId()
     {
+
+        $platform_id = $this->request->post('platform_id/d', 0, 'trim');
+
+        $list = Db::name('platform_source')
+            ->field('id,platform_id,source')
+            ->where(['is_del' => 0, 'platform_id' => $platform_id])
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+
+        return app_show(0, '获取成功', $list);
+
     }
 
 

+ 77 - 2
app/admin/controller/Orderback.php

@@ -4,6 +4,7 @@
 namespace app\Admin\controller;
 
 use app\admin\model\ActionLog;
+use app\admin\model\GoodLog;
 use app\admin\model\ProcessOrder;
 use think\App;
 use think\Exception;
@@ -378,12 +379,87 @@ class Orderback extends \app\BaseController
         try {
 
             $info = Db::name("order_back")
-                ->field('id,order_type,status')
+                ->field('id,order_type,status,outCode,spuCode,return_num')
                 ->where(['thNo' => $param['thNo'], 'is_del' => 0])
                 ->find();
 
             if (empty($info)) throw new Exception('未找到数据');
 
+            if($param['can_sell_num']!=0&& $param['can_sell_wsm']!=''){
+                    $stock = Db::name("good_stock")->where(["spuCode"=>$info['spuCode'],'wsm_code'=>$param['can_sell_wsm']])->find();
+                    if(empty($stock)) {
+                        $stock=[
+                            "spuCode"=>$info['spuCode'],
+                            "wsm_code"=>$param['can_sell_wsm'],
+                            "usable_stock"=>0,
+                            "wait_out_stock"=>0,
+                            "wait_in_stock"=>0,
+                            "total_stock"=>0,
+                            "addtime"=>date("Y-m-d H:i:s"),
+                            "updatetime"=>date("Y-m-d H:i:s"),
+                        ];
+//                        $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
+                    }else{
+//                        $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+                    }
+                    $stock['usable_stock']+=$param['can_sell_num'];
+                    $stock['updatetime']=date("Y-m-d H:i:s");
+                    $st_up = Db::name("good_stock")->save($stock);
+                    if($st_up==false){
+                        return error_show(1005,'可售商品入库失败');
+                    }
+                $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>$stock['id'],"type"=>1,'stock'=>$param['can_sell_num'],"stock_name"=>"usable_stock"];
+                GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
+             }
+            if($param['defective_num']!=0&& $param['defective_wsm']!=''){
+                $defective = Db::name("good_stock")->where(["spuCode"=>$info['spuCode'],'wsm_code'=>$param['defective_wsm']])->find();
+                if(empty($defective)) {
+                    $defective=[
+                        "spuCode"=>$info['spuCode'],
+                        "wsm_code"=>$param['defective_wsm'],
+                        "usable_stock"=>0,
+                        "wait_out_stock"=>0,
+                        "wait_in_stock"=>0,
+                        "total_stock"=>0,
+                        "addtime"=>date("Y-m-d H:i:s"),
+                        "updatetime"=>date("Y-m-d H:i:s"),
+                    ];
+                    $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
+                }else{
+                    $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+                }
+                $defective['usable_stock']+=$param['defective_num'];
+                $defective['updatetime'] = date("Y-m-d H:i:s");
+                $upd=  Db::name("good_stock")->save($defective);
+                if($upd==false){
+                    Db::rollback();
+                    return error_show(1005,'次品商品入库失败');
+                }
+                $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>isset($defective['id'])? $defective['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$param['defective_num'],"stock_name"=>"usable_stock"];
+                GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
+            }
+            if($info['is_receive']!=1){
+                $send=Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
+                if($send==false){
+                    Db::rollback();
+                    return error_show(1005,'未找到对应的发货单');
+                }
+                $stock_send = Db::name("good_stock")->where(["spuCode"=>$info['spuCode'],'wsm_code'=>$send['wsm_code']])->find();
+                if($stock_send==false){
+                    Db::rollback();
+                    return error_show(1004,'未找到商品库存数据');
+                }
+
+                $stock_send['intra_stock']-=$info['return_num'];
+                $stock_send['updatetime']=date("Y-m-d H:i:s");
+                $st_up = Db::name("good_stock")->save($stock_send);
+                if($st_up==false){
+                    return error_show(1005,'可售商品入库失败');
+                }
+                $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>$stock_send['id'],"type"=>2,'stock'=>$info['return_num'],"stock_name"=>"intra_stock"];
+                GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
+            }
+
             $update_data = ['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')];
 
             //status==4通过,其他值表示驳回
@@ -401,7 +477,6 @@ class Orderback extends \app\BaseController
                 ->update($update_data);
 
             if ($res) {
-
                 $stn = ["order_code" => $param['thNo'], "status" => $param['status'], "action_remark" => '', "action_type" => "edit"];
                 ActionLog::logAdd($this->post['token'], $stn, $info['order_type'] == 2 ? "ZXCKTHD" : "CKTHD", $info['status'], $stn);
                 $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => $info['order_type'] == 2 ? "ZXCKTHD" : "CKTHD"];

+ 1 - 0
app/admin/controller/Reorder.php

@@ -196,6 +196,7 @@ class Reorder extends \app\BaseController
         $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
         $info['is_stock']=isset($goon['is_stock'])?$goon['is_stock']:'0';
        $info['good_code'] = isset($orderinfo['good_code'])?$orderinfo['good_code']:'';
+       $info['skuCode'] = isset($orderinfo['skuCode'])?$orderinfo['skuCode']:'';
        $info['good_name'] = isset($orderinfo['good_name'])?$orderinfo['good_name']:'';
        $info['good_num'] = isset($orderinfo['good_num'])?$orderinfo['good_num']:'';
        $info['sale_price'] = isset($orderinfo['sale_price'])?$orderinfo['sale_price']:'0';

+ 5 - 4
app/admin/model/OrderImportFromC.php

@@ -16,9 +16,10 @@ class OrderImportFromC extends Model
     public static $is_del_normal = 0;
     public static $is_del_delete = 1;
 
-    public static $status_wait_validate = 1;//系统验证数据中
-    public static $status_wait_confirm = 2;//待确认订单信息
-    public static $status_wait_relation = 3;//信息已确认待关联库存
-    public static $status_success = 4;//订单录入成功
+    public static $status_wait_validate = 1;//待系统验证
+    public static $status_wait_confirm = 2;//待用户确认订单信息
+    public static $status_wait_relation = 3;//待处理(待关联库存)
+    public static $status_stock_not_enough = 4;//库存不足
+    public static $status_success = 5;//订单录入成功
 
 }

+ 5 - 1
app/admin/route/app.php

@@ -470,4 +470,8 @@ Route::rule("plancheck","admin/Version/planCheck");
 Route::rule('getdata','admin/Data/index');//数据看板,获取相关统计数据
 Route::rule('orderimport','admin/OrderImport/import');//C端订单导入
 Route::rule('orderimportlist','admin/OrderImport/getImportList');//C端订单列表
-Route::rule('orderimportinfo','admin/OrderImport/getImportInfo');//C端订单详情
+Route::rule('orderimportinfo','admin/OrderImport/getImportInfo');//C端订单详情
+Route::rule('getonlinegoodinfo','admin/OrderImport/getOnlineGoodInfoByPlatcode');//获取线上商品详情
+Route::rule('getsourcedata','admin/OrderImport/getSourceDataByPlatformId');//获取销售渠道备选数据
+Route::rule('confirmimportdata','admin/OrderImport/confirmImportData');//用户确认
+Route::rule('relationstockbatch','admin/OrderImport/relationStockBatch');//用户批量关联库存

+ 162 - 0
app/command/ImportOrderFromCAnalysisData.php

@@ -0,0 +1,162 @@
+<?php
+declare (strict_types=1);
+
+namespace app\command;
+
+use app\admin\model\OrderImportFromC as OIFCModel;
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Db;
+use think\facade\Validate;
+
+//C端订单导入-数据解析
+class ImportOrderFromCAnalysisData extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('analysisData')
+            ->setDescription('批量解析C端导入的订单数据');
+    }
+
+
+    //【脚本1】解析用户导入的数据
+    protected function execute(Input $input, Output $output)
+    {
+        //解析信息存到extend表,其中customer_code字段根据订单编号去customer_info查,其他根据商品编号查询
+
+        Db::startTrans();
+        try {
+
+            $order_import_from_c_db = Db::name('order_import_from_c');
+
+            $order_import_from_c_extend_db = Db::name('order_import_from_c_extend');
+//        $customer_info_db = Db::name('customer_info')->field('companyNo')->where(['is_del' => 0]);
+
+            $rs = $order_import_from_c_db
+                ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_validate])
+                ->find();
+
+            //1.数据校验
+            $val = Validate::rule([
+                'platform_code|平台订单号' => 'require',
+                'platform_time|平台下单时间' => 'require|date',
+                'sale_source|销售渠道' => 'require',
+                'plat_code|平台商品编号' => 'require',
+                'price|单价' => 'require|float',
+                'num|数量' => 'require|number',
+                'before_discount_all_price|优惠前总金额' => 'require|float',
+                'mode|收费模式' => 'require',
+                'contactor|收货人' => 'require',
+                'mobile|联系电话' => 'require',
+                'addr|联系地址' => 'require',
+            ]);
+
+            $update_c_data = [
+                'updatetime' => date('Y-m-d H:i:s'),
+                'updateid' => 0,
+                'updater' => 'system',
+            ];
+            if (!$val->check($rs)) {
+                $update_c_data['status'] = OIFCModel::$status_wait_confirm;
+                $update_c_data['remark'] = '数据格式不对,' . $val->getError();
+            }
+
+            $extend_insert_data = [
+                'order_import_from_c_id' => $rs['id'],
+                'createrid' => 0,
+                'creater' => 'system',
+                'discount_reason' => $rs['activity_name']
+            ];
+
+            //组织extend的数据
+            $good_platform_info = Db::name('good_platform')
+                ->field('id,spuCode,platform_code,skuCode')
+                ->where(['is_del' => 0])
+                ->where('plat_code', $rs['plat_code'])
+                ->find();
+
+            //商品信息
+            if (!empty($good_platform_info)) {
+                $extend_insert_data['spuCode'] = $good_platform_info['spuCode'];
+                $extend_insert_data['platform_codes'] = $good_platform_info['platform_code'];
+
+                $good_info = Db::name('good')
+                    ->field('good_name,companyNo,supplierNo')
+                    ->where(['is_del' => 0])
+                    ->where('spuCode', $extend_insert_data['spuCode'])
+                    ->find();
+                if (!empty($good_info)) {
+                    $extend_insert_data['companyNo'] = $good_info['companyNo'];
+                    $extend_insert_data['supplierNo'] = $good_info['supplierNo'];
+                    $extend_insert_data['good_name'] = $good_info['good_name'];
+                } else {
+                    $update_c_data['status'] = OIFCModel::$status_wait_confirm;
+                    $update_c_data['remark'] = isset($update_c_data['remark']) ? $update_c_data['remark'] . ',在上线商品表中查不到spuCode对应的商品信息' : '在上线商品表中查不到spuCode对应的商品信息';
+                }
+
+            } else {
+                $update_c_data['status'] = OIFCModel::$status_wait_confirm;
+                $update_c_data['remark'] = isset($update_c_data['remark']) ? $update_c_data['remark'] . ',在商品平台表中查不到平台商品编号对应的spuCode' : '在商品平台表中查不到平台商品编号对应的spuCode';
+            }
+
+            //活动信息
+            $extend_insert_data['activity_id'] = Db::name('good_activity')
+                ->where(['activity_name' => $rs['activity_name'], 'is_del' => 0])
+                ->value('id', 0);
+
+            //企业客户
+            $co_id = Db::name('platform')
+                ->alias('p')
+                ->leftJoin('customer_org1 co', 'co.name=p.platform_name AND co.is_del=0')
+                ->where('p.platform_code', $rs['platform_code'])
+                ->value('co.id', 0);
+
+            if ($co_id) {
+                $customer_code = Db::name('customer_info')
+                    ->where(['itemid' => $co_id, 'companyName' => '客户', 'is_del' => 0])
+                    ->value('companyNo', '');
+
+                if ($customer_code) {
+                    $extend_insert_data['customer_code'] = $customer_code;
+                } else {
+                    $update_c_data['status'] = OIFCModel::$status_wait_confirm;
+                    $update_c_data['remark'] = isset($update_c_data['remark']) ? $update_c_data['remark'] . ',在企业客户管理组织中找不到对应的企业' : '在企业客户管理组织中找不到对应的企业';
+                }
+
+            } else {
+                $update_c_data['status'] = OIFCModel::$status_wait_confirm;
+                $update_c_data['remark'] = isset($update_c_data['remark']) ? $update_c_data['remark'] . ',在企业客户管理组织中找不到平台名称对应的组织' : '在企业客户管理组织中找不到平台名称对应的组织';
+            }
+
+
+            $order_import_from_c_extend_db->insertGetId($extend_insert_data);
+
+            if (!isset($update_c_data['status'])) $update_c_data['status'] = OIFCModel::$status_wait_relation;
+
+            $order_import_from_c_db
+                ->where([
+                    'id' => $rs['id'],
+                    'is_del' => OIFCModel::$is_del_normal,
+                    'status' => OIFCModel::$status_wait_validate
+                ])->update($update_c_data);
+
+            Db::commit();
+
+            // 指令输出
+            $output->writeln('解析成功');
+
+        } catch (\think\Exception $exception) {
+            Db::rollback();
+            // 指令输出
+            $output->writeln('解析失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
+        }
+
+
+    }
+
+
+}