wugg před 3 roky
rodič
revize
529a293e0c
2 změnil soubory, kde provedl 292 přidání a 115 odebrání
  1. 1 1
      app/admin/controller/Consult.php
  2. 291 114
      app/admin/controller/Sale.php

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

@@ -528,7 +528,7 @@ class Consult extends BaseController
         if($zxinfo==false){
             return error_show(1004,"未找到信息数据");
         }
-        if($zxinfo['status']!==1){
+        if($zxinfo['status']!=1){
             return error_show(1004,"任务未进行");
         }
         $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";

+ 291 - 114
app/admin/controller/Sale.php

@@ -21,141 +21,318 @@ class Sale extends BaseController
 
     public function create()
     {
-        $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
-        $orderCode = makeNo("CX");
-        $good_code = $this->post['good_code'] && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
-        if ($good_code == "") {
-            return error_show(1002, "商品code不能为空");
+        $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
+        $orderCode=makeNo("CX");
+        $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
+        if($customer_code==""){
+            return error_show(1002,"客户code不能为空");
         }
+
+        $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
+        if($customer==false){
+            return error_show(1004,"未找到客户数据");
+        }
+        $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
+        if($supplierNo==""){
+            return error_show(1002,"参数supplierNo不能为空");
+        }
+        $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find();
+        if($supplier==false){
+            return error_show(1004,"未找到平台供应商数据");
+        }
+        $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"1";
+        $order_type =isset($this->post['order_type']) && $this->post['order_type'] !=="" ?intval($this->post['order_type'])
+            :"1";
+        $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?intval($this->post['sendtype']):"";
+        if($sendtype==''){
+            return error_show(1004,"参数sendtype不能为空");
+        }
+        $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):"";
+        if($platform_id==''){
+            return error_show(1004,"参数platform_id不能为空");
+        }
+        $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :"";
+        if($zxinfoNo=="" &&$order_type!==1){
+            return error_show(1002,"参数 zxinfoNo 不能为空");
+        }
+        $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
+        if($platform_order==''){
+            return error_show(1004,"参数platform_order不能为空");
+        }
+        $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
+        if($good_code==''){
+            return error_show(1004,"参数good_code不能为空");
+        }
+        $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
+        if($good_num===''){
+            return error_show(1004,"参数good_num不能为空");
+        }
+        if($order_type==3|| $order_type==4){
+            $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
+            if($good==false){
+                return error_show(1004,"未找到商品数据");
+            }
+            $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->find();
+            if($goodinfo==false){
+                return error_show(1004,"未找到商品数据");
+            }
+            $is_stock=0;
+            $cgd=[
+                "supplierNo"=>$good['supplierNo'],
+                "companyNo"=>$supplierNo,
+                "spuCode"=>$good_code,
+                "good_name"=>$good['good_name'],
+                "sale_price"=>$goodinfo['sale_price'],
+                "total_fee"=>$goodinfo['total_fee'],
+                "pakge_fee"=>$goodinfo['pakge_fee'],
+                "cert_fee"=>$goodinfo['cert_fee'],
+                "open_fee"=>$goodinfo['open_fee'],
+                "delivery_fee"=>$goodinfo['delivery_fee'],
+                "mark_fee"=>$goodinfo['mark_fee'],
+                "demo_fee"=>$goodinfo['demo_fee'],
+                "good_num"=>$good_num,
+                "good_type"=>$goodtype,
+                "order_type"=>$order_type,
+            ];
+        }else{
         $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
             ->where(['a.skuCode' => $good_code])->find();
-        if ($ct == "") {
-            return error_show(1002, "未找到商品数据");
-        }
-        $customer_code = $this->post['customer_code'] && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
-        if ($customer_code == "") {
-            return error_show(1002, "客户code不能为空");
-        }
-        $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
-        if ($customer == false) {
-            return error_show(1004, "未找到客户数据");
-        }
-        $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
-        if ($supplierNo == "") {
-            return error_show(1002, "参数supplierNo不能为空");
-        }
-        $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
-        if ($supplier == false) {
-            return error_show(1004, "未找到平台供应商数据");
+            if ($ct == "") {
+                return error_show(1002, "未找到商品数据");
+            }
+            $is_stock=$ct['is_stock'];
+            $cgd=[
+                "supplierNo"=>$ct['supplierNo'],
+                "companyNo"=>$supplierNo,
+                "spuCode"=>$good_code,
+                "good_name"=>$ct['good_name'],
+                "sale_price"=>$ct['sale_price'],
+                "total_fee"=>$ct['total_fee'],
+                "pakge_fee"=>$ct['pakge_fee'],
+                "cert_fee"=>$ct['cert_fee'],
+                "open_fee"=>$ct['open_fee'],
+                "delivery_fee"=>$ct['delivery_fee'],
+                "mark_fee"=>$ct['mark_fee'],
+                "demo_fee"=>$ct['demo_fee'],
+                "good_num"=>$good_num,
+                "good_type"=>$goodtype,
+                "order_type"=>$order_type,
+            ];
         }
-        $apply_id = GetUserInfo($token);
-        if (empty($apply_id) || $apply_id['code'] != 0) {
-            return error_show(1002, "申请人数据不存在");
+
+        if($order_type==1){
+            $is_activity= isset($this->post['is_activity'])&&$this->post['is_activity']!=="" ?$this->post['is_activity']:"";
+            if($is_activity===""){
+                return error_show(1002, "参数is_activity不能为空");
+            }
+
         }
-        $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
-        $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
-        $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
-        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
-        $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
-        if ($va == "") {
-            return error_show(1002, "参数order_addr不能为空");
+
+//        if($goodtype===''){
+//            return error_show(1004,"参数goodtype不能为空");
+//        }
+        $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
+        if($arrtime==""){
+            return error_show(1004,"参数arrtime不能为空");
+        }
+        $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
+        if($sendtype==1){
+            $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
+            if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
+                return error_show(1004,"参数addrlist不能为空");
+            }
         }
-        $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
-        if ($vi == "") {
-            return error_show(1002, "参数 good_stock 不能为空");
+        $proofid= isset($this->post['proof_id'])&&$this->post['proof_id']===""?intval($this->post['proof_id']):"0";
+
+        $apply_id =GetUserInfo($token);
+        if(empty($apply_id)||$apply_id['code']!=0){
+            return error_show(1002,"申请人数据不存在");
         }
-        $good_num = intval(array_sum(array_column($vi, "num")));
+        $rm= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
+        $ri= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
         Db::startTrans();
         try {
-            $data = [
-                "orderCode" => $orderCode,
-                "good_code" => $good_code,
-                "customer_code" => $customer_code,
-                "good_name" => $ct['good_name'],
-                "good_num" => $good_num,
-                "apply_id" => $rm,
-                "apply_name" => $ri,
-                "origin_price" => $ct['original_price'],
-                "sale_price" => $ct['original_price'],
-                "post_fee" => $post_fee,
-                "status" => $status,
-                "supplierNo" => $supplierNo,
-                "send_num" => 0,
-                "wsend_num" => $good_num,
-                "send_status" => 1,
-                "is_del" => 0,
-                "addtime" => date("Y-m-d H:i:s"),
-                "updatetime" => date("Y-m-d H:i:s"),
-                'total_price' => $ct['original_price'] * $good_num,
+            $data=[
+                "orderCode"=>$orderCode,
+                "good_code"=>$good_code,
+                "customer_code"=>$customer_code,
+                "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
+                "good_num/"=>$good_num,
+                "cat_id"=>$goodinfo['cat_id'],
+                "apply_id"=>$rm,
+                "apply_name"=>$ri,
+                "origin_price"=>$goodinfo['total_fee'],
+                "sale_price"=>$goodinfo['sale_price'],
+                "post_fee"=>0,
+                "status"=>0,
+                "send_num"=>0,
+                "wsend_num"=>$good_num,
+                "send_status"=>1,
+                "good_type"=>$goodtype,
+                "send_type"=>$sendtype,
+                "supplierNo"=>$supplierNo,
+                "is_del"=>0,
+                "zxNo"=>$zxinfoNo,
+                "platform_order"=>$platform_order,
+                "platform_id"=>$platform_id,
+                "remark"=>$remark,
+                "proof_id"=>$proofid,
+                "order_type"=>$order_type,
+                "addtime"=>date("Y-m-d H:i:s"),
+                "updatetime"=>date("Y-m-d H:i:s"),
+                'total_price'=>round($goodinfo['sale_price']*$good_num,2),
             ];
-            $datainfo = Db::name('sale')->insert($data, true);
-            $vat = [];
-            $inn = [];
-            if ($datainfo > 0) {
-                $st = ["order_code"=>$orderCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
-                ActionLog::logAdd($this->post['token'],$st,"XSQRD",$status,$data);
-                $order=["order_type"=>'XSQRD',"order_code"=>$orderCode,"order_id"=>$datainfo,"order_status"=>$status];
-                ProcessOrder::AddProcess($this->post['token'],$order);
-                foreach ($vi as $ion) {
-                    $iten = [];
-                    $iten['orderCode'] = $orderCode;
-                    $iten['wsm_code'] = $ion['wsm_code'];
-                    $iten['stock_id'] = "";
-                    $iten['num'] = $ion['num'];
-                    $iten['status'] = 0;
-                    $iten['sale_price'] = $ct['original_price'];
-                    $iten['addtime'] = date("Y-m-d H:i:s");
-                    $iten['updatetime'] = date("Y-m-d H:i:s");
-                    $inn[] = $iten;
+            $datainfo = Db::name('sale')->insert($data,true);
+            if($datainfo>0){
+                if($is_stock==0){
+                    $bol=$this->createCgd($cgd);
                 }
-//            if($vi['usable_stock']<$iten['num']){
-//                Db::rollback();
-//                return error_show(1002,"超出库存数量");
-//            }
-                $vp = Db::name('sale_info')->insertAll($inn);
-                if ($vp == "") {
+                if($bol==false){
                     Db::rollback();
-                    return error_show(1002, "添加失败");
+                    return error_show(1002,"咨询订单创建失败");
                 }
-                foreach ($va as $value) {
-                    $temp = [];
-                    $addrs = [];
-                    if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
-                        $addrs['provice_code'] = $value['addr_code'][0];
-                        $addrs['city_code'] = $value['addr_code'][1];
-                        $addrs['area_code'] = $value['addr_code'][2];
-                        $addr = json_encode($addrs);
-                    } else {
-                        $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
+                if($sendtype!=2){
+                    foreach ($addrlist as $value){
+                        $temp=[];
+                        $addrs=[];
+                        if($value['addr_code']!==''&&is_array($value['addr_code'])){
+                            $addrs['provice_code'] = $value['addr_code'][0];
+                            $addrs['city_code'] = $value['addr_code'][1];
+                            $addrs['area_code'] = $value['addr_code'][2];
+                            $addr = json_encode($addrs);
+                        }else{
+                            $addr = isset($value['addr_code'])?$value['addr_code']:'';
+                        }
+                        $temp['orderCode']=$orderCode;
+                        $temp['contactor']=$value['contactor'];
+                        $temp['mobile'] = $value['mobile'];
+                        $temp['addr'] = $value['addr'];
+                        $temp['addr_code']=$addr;
+                        $temp['customer_code'] =$customer_code;
+                        $temp['receipt_quantity']=$value['receipt_quantity'];
+                        $temp['post_fee'] =0;
+                        $temp['is_del'] =0;
+                        $temp['addtime'] =date("Y-m-d H:i:s");
+                        $temp['updatetime'] =date("Y-m-d H:i:s");
+                        $temp['arrive_time']=$arrtime;
+                        $vmp = Db::name('order_addr')->insert($temp,true);
+                        if($vmp>0){
+                            $outCode=makeNo("CK");
+                            $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"=>$value['receipt_quantity'],
+                                "check_num"=>0,
+                                "error_num"=>0,
+                                "wsm_code"=>"",
+                                "order_type"=>$order_type,
+                                "status"=>0,
+                                "addtime"=>date("Y-m-d H:i:s"),
+                                "updatetime"=>date("Y-m-d H:i:s")
+                            ];
+                            $ou =Db::name("order_out")->insert($out);
+                            if($ou==false){
+                                Db::rollback();
+                                return error_show(1002,"咨询订单创建失败");
+                            }
+                        }else{
+                            Db::rollback();
+                            return error_show(1002,"咨询订单创建失败");
+                        }
                     }
-                    $temp['orderCode'] = $orderCode;
-                    $temp['contactor'] = $value['contactor'];
-                    $temp['mobile'] = $value['mobile'];
-                    $temp['addr'] = $value['addr'];
-                    $temp['addr_code'] = $addr;
-                    $temp['customer_code'] = $customer_code;
-                    $temp['receipt_quantity'] = $value['receipt_quantity'];
-                    $temp['post_fee'] = 0;
-                    $temp['is_del'] = 0;
-                    $temp['addtime'] = date("Y-m-d H:i:s");
-                    $temp['updatetime'] = date("Y-m-d H:i:s");
-                    $temp['arrive_time'] = date("Y-m-d H:i:s");
-                    $vat[] = $temp;
-                }
-                $vmp = Db::name('order_addr')->insertAll($vat);
-                if ($vmp) {
-                    Db::commit();
-                    return error_show(0, "销售订单创建成功");
                 }
+                Db::commit();
+                return error_show(0,"咨询订单创建成功");
             }
             Db::rollback();
-            return error_show(1002, "销售订单创建失败");
-        } catch (\Exception $e) {
+            return error_show(1002,"咨询订单创建失败");
+        }catch(\Exception $e){
             Db::rollback();
-            return error_show(1005, $e->getMessage());
+            return error_show(1005,$e->getMessage());
         }
     }
+    public function createCgd($data){
+        $cgdCode = makeNo("CG");
+        $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
+        if($supplier==false){
+            return false;
+        }
+        $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"is_del"=>0])->find();
+        if($wsm==false){
+            $wsm_code = makeNo("WSM");
+            $inwsm=[
+                "wsm_code"=>$wsm_code,
+                "name"=>$supplier['name'],
+                "wsm_type"=>2,
+                "supplierNo"=>$supplier['code'],
+                "addr"=>"",
+                "addrs_code"=>"",
+                "contactor"=>0,
+                "contactor_name"=>0,
+                "mobile"=>"",
+                "position"=>"",
+                "companyNo"=>$data['companyNo'],
+                "status"=>1,
+                "is_del"=>0,
+                "addtime"=>date("Y-m-d H:i:s"),
+                "updatetime"=>date("Y-m-d H:i:s")
+            ];
+            $in = Db::name("warehouse_info")->insert($inwsm);
+            if($in==false){
+                return false;
+            }
+        }else{
+            $wsm_code =$wsm['wsm_code'];
+        }
+        $cg =["cgdNo"=>$cgdCode,
+            "bkcode"=>"",
+            "wsm_code"=>$wsm_code,
+            "cgder"=>$supplier['person'],
+            "cgder_id"=>$supplier['personid'],
+            "good_code"=>$data['spuCode'],
+            "good_name"=>$data['good_name'],
+            "good_num"=>$data['good_num'],
+            "good_price"=>$data['sale_price'],
+            "total_fee"=>$data['total_fee'],
+            "pakge_fee"=>$data['pakge_fee'],
+            "cert_fee"=>$data['cert_fee'],
+            "open_fee"=>$data['open_fee'],
+            "delivery_fee"=>$data['delivery_fee'],
+            "mark_fee"=>$data['mark_fee'],
+            "demo_fee"=>$data['demo_fee'],
+            #"weight"=>$data['weight'],
+            "diff_weight"=>"0",
+            "diff_fee"=>"0",
+            "gold_price"=>"0",
+            "supplierNo"=>$data['supplierNo'],
+            "supplier_name"=>$supplier['name'],
+            "send_status"=>1,
+            "send_num"=>"0",
+            "wsend_num"=>$data['good_num'],
+            "remark"=>"",
+            "status"=>0,
+            "lasttime"=>date("Y-m-d H:i:s"),
+            "is_del"=>0,
+            "order_type"=>$data['order_type'],
+            "good_type"=>$data['good_type'],
+            "addtime"=>date("Y-m-d H:i:s"),
+            "updatetime"=>date("Y-m-d H:i:s")
+        ];
+        $up =Db::name("purchease_order")->insert($cg);
+        if($up){
+            return true;
+        }else{
+            return false;
+        }
 
+    }
     public function list()
     {
         $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";