panlumeng 3 years ago
parent
commit
3060f4c233

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

@@ -28,7 +28,7 @@ class Consult extends BaseController
       $where=[['is_del',"=",0]];
       $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
       if ($zxNo !== "") {
-          $where['zxNo'] = $zxNo;
+          $where[] = ['zxNo','=',$zxNo];
       }
       $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
       if ($salesman !== "") {

+ 2 - 2
app/admin/controller/Listcustomer.php

@@ -27,8 +27,8 @@ class Listcustomer extends BaseController
         $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
         $where []= ['is_del',"=",0];
         $companyNo= isset($this->post['companyNo'])&&$this->post['companyNo']!=="" ? trim($this->post['companyNo']):"";
-        if($companyNo!="") {
-            $where[] = ["companyNo", "=", $companyNo];
+        if($companyNo!=""){
+            $where[]=["companyNo","like","%$companyNo%"];
         }
         $companyName= isset($this->post['companyName'])&&$this->post['companyName']!=="" ? trim($this->post['companyName']):"";
         if($companyName!=""){

+ 186 - 29
app/admin/controller/Sale.php

@@ -14,13 +14,6 @@ public function __construct(App $app)
     parent::__construct($app);
     $this->post=$this->request->post();
 }
-//            $str=Db::name('sale_info')->alias('a')->join("order_addr b","b.orderCode=a.orderCode","left")
-//                    ->join("good_stock c","c.wsm_code=a.wsm_code","left")
-//                    ->where(['b.is_del'=>0])->field('b.contactor,b.mobile,b.addr,b.arrive_time,c.good_type_code,c.usable_stock')->insertAll();
-
-//$temp =[];
-//$temp['good_type_code']="";
-//$temp['usable_stock']=$str['num'];
 public function create(){
     $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
     $orderCode=makeNo("CX");
@@ -45,23 +38,14 @@ public function create(){
     $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
     $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']) :"";
-//    $contactor=isset($this->post['contactor']) && $this->post['contactor'] !=="" ?trim($this->post['contactor']) :"";
-//    if($contactor==""){
-//        return error_show(1002,"联系人不能为空");
-//    }
-//    $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']) :"";
-//    if($mobile==""){
-//        return error_show(1002,"联系电话不能为空");
-//    }
-//    $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? intval($this->post['customer_code']) :"";
-//    $arrive_time=isset($this->post['arrive_time']) && $this->post['arrive_time'] ? $this->post['arrive_time']:date("Y-m-d H:i:s");
-//    if($arrive_time==""){
-//        return error_show(1002,"到货日期不能为空");
-//    }
     $va= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ?  $this->post['order_addr']:"";
     if($va==""){
         return error_show(1002,"参数order_addr不能为空");
     }
+    $vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ?  $this->post['good_stock']:"";
+    if($vi==""){
+        return error_show(1002,"参数good_stock不能为空");
+    }
     Db::startTrans();
       try {
         $data=[
@@ -83,7 +67,25 @@ public function create(){
         ];
         $datainfo = Db::name('sale')->insert($data,true);
         $vat=[];
+        $inn=[];
         if($datainfo>0){
+            foreach ($vi as $ion){
+                $iten=[];
+                $iten['orderCode']=$orderCode;
+                $iten['wsm_code']=$ion['wsm_code'];
+                $iten['stock_id']=$ion['stock_id'];
+                $iten['num']=$ion['num'];
+                $iten['status']=$ion['status'];
+                $iten['sale_price']=$ion['sale_price'];
+                $iten['addtime'] =date("Y-m-d H:i:s");
+                $iten['updatetime'] =date("Y-m-d H:i:s");
+                $inn[]=$iten;
+            }
+            if($vi['usable_stock']<$iten['num']){
+                Db::rollback();
+                return error_show(1002,"超出库存数量");
+            }
+            $vp= Db::name('sale_info')->insertAll($inn);
        foreach ($va as $value){
         $temp=[];
         $temp['orderCode']=$orderCode;
@@ -125,6 +127,10 @@ public function list(){
     if($status !==""){
         $where[]=['orderCode',"=",$status];
     }
+    $addtime = isset($this->post['addtime']) && $this->post['addtime'] !=="" ? $this->post['addtime'] :"";
+    if($addtime !=""){
+        $where[]= ["addtime",'<=',$addtime];
+    }
     $count = Db::name('sale')->where($where)->count();
     $total = ceil($count/$size);
     $page = $page >= $total ? $total : $page;
@@ -171,7 +177,10 @@ public function edit(){
     if($vr==""){
         return error_show(1002,"参数order_addr不能为空");
     }
-
+    $vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ?  $this->post['good_stock']:"";
+    if($vi==""){
+        return error_show(1002,"参数good_stock不能为空");
+    }
     Db::startTrans();
     try {
         $datn=[
@@ -193,6 +202,20 @@ public function edit(){
         $datninfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($datn);
         //$vat=[];
         if($datninfo>0){
+            foreach ($vi as $ion){
+                $iten=[];
+                isset($ion['id'])&&$ion['id']!=="" ? $iten['id'] = $ion['id']:'';
+                $iten['orderCode']=$etid['orderCode'];
+                $iten['wsm_code']=$ion['wsm_code'];
+                $iten['stock_id']=$ion['stock_id'];
+                $iten['num']=$ion['num'];
+                $iten['status']=$ion['status'];
+                $iten['sale_price']=$ion['sale_price'];
+                isset($ion['id'])&&$ion['id']!=="" ? '' : $iten['addtime'] =date("Y-m-d H:i:s");
+                $iten['updatetime'] =date("Y-m-d H:i:s");
+                //$inn[]=$iten;
+                $vp= Db::name('sale_info')->save($iten);
+            }
 
             foreach ($vr as $value){
                 $temp=[];
@@ -214,9 +237,9 @@ public function edit(){
                     Db::rollback();
                     return error_show(1002,"更新失败");
                 }
-                Db::commit();
-                return error_show(0,"更新成功");
             }
+            Db::commit();
+            return error_show(0,"更新成功");
         }
         Db::rollback();
         return error_show(1002,"更新失败");
@@ -230,17 +253,26 @@ public function info(){
     if($id==""){
         return error_show(1002,"参数id不能为空");
     }
-    $einfo = Db::name('sale')->alias('a')->join("order_addr b","b.orderCode=a.orderCode","left")
-        ->where(['a.id'=>$id,'a.is_del'=>0])->field('b.addr,b.contactor,b.mobile,b.arrive_time,a.*')->find();
+    $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :"";
+    if($wsm_code==""){
+        return error_show(1003,"仓库code不能存在");
+    }
+    $einfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->field('good_code,good_name,customer_code,orderCode')->find();
     if(empty($einfo)){
         return error_show(1002,"未找到销售订单数据");
     }
-    $fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode']])->select();
-    $einfo['item'][]=$fo;
+    $stok= Db::name('good_stock')->where(['wsm_code'=>$wsm_code,'is_del'=>0])->field('wsm_code')->find();
+    if(empty($stok)){
+        return error_show(0,"未找到商品数据");
+    }
+    $fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->field('addr,contactor,mobile,receipt_quantity,arrive_time')->select();
+    $st = Db::name('sale_info')->where(['wsm_code'=>$stok['wsm_code']])->field('wsm_code,num,sale_price')->select();
+    $stok['temp']=$st;
+    $einfo['item']=$fo;
     if(empty($einfo)){
         return error_show(1002,"未找到销售订单数据");
     }else{
-        return app_show(0,"获取成功",$einfo);
+        return app_show(0,"获取成功",[$einfo,$stok]);
     }
 }
 public function del(){
@@ -277,5 +309,130 @@ public function status(){
     $st = Db::name('sale')->save($dio);
     return error_show(0,"订单状态更新成功");
 }
-
+public function fee(){
+    $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
+    if($id==""){
+        return error_show(1002,"参数id不能为空");
+    }
+    $etid = Db::name("sale")->where(["id"=>$id,"is_del"=>0])->find();
+    if(empty($etid)){
+        return error_show(1002,"未找到数据");
+    }
+    $vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ?  $this->post['order_addr']:"";
+    if($vr==""){
+        return error_show(1002,"参数order_addr不能为空");
+    }
+    Db::startTrans();
+    try {
+        $data=[
+            "id"=>$id,
+            "status"=>2,
+            "is_del"=>0,
+            "updatetime"=>date("Y-m-d H:i:s")
+        ];
+        $datainfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($data);
+        if($datainfo){
+            foreach ($vr as $value){
+                $tm=[];
+                $tm['id'] = $value['id'];
+                $tm['orderCode']=$etid['orderCode'];
+                $tm['post_fee']=$value['post_fee'];
+                $tm['updatetime']=date("Y-m-d H:i:s");
+                $dn = Db::name('order_addr')->save($tm);
+                if($dn==false){
+                    Db::rollback();
+                    return error_show(1002,"更新失败");
+                }
+            }
+            Db::commit();
+            return error_show(0,"更新成功");
+        }
+        Db::rollback();
+        return error_show(1003,"更新失败");
+    }catch(\Exception $e){
+        Db::rollback();
+        return error_show(1005,$e->getMessage());
+    }
+}
+public function out(){
+    $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
+//    $orderCode= isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
+//    if($orderCode==""){
+//        return error_show(1002,"参数orderCode不能为空");
+//    }
+    $orderCode=makeNo("CK");
+    $outCode = isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
+    if($outCode==""){
+        return error_show(1002,"参数outcode不能为空");
+    }
+    $post_name= isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
+    if($post_name==""){
+        return error_show(1002,"物流公司不能为空");
+    }
+    $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :"";
+    if($post_code==""){
+        return error_show(1002,"物流单号不能为空");
+    }
+    $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? intval($this->post['post_fee']) :"";
+    if($post_fee==""){
+        return error_show(1002,"物流费用不能为空");
+    }
+    $apply_id =GetUserInfo($token);
+    if(empty($apply_id)||$apply_id['code']!=0){
+        return error_show(1002,"申请人数据不存在");
+    }
+    $rm= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
+    $ri= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
+    $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
+    $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
+    $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
+    $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
+    $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
+    $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"";
+    $data=[
+        "orderCode"=>$orderCode,
+        "outCode"=>$outCode,
+        "apply_id"=>$rm,
+        "apply_name"=>$ri,
+        "addrid"=>$addrid,
+        "post_name"=>$post_name,
+        "post_code"=>$post_code,
+        "post_fee"=>$post_fee,
+        "sendtime"=>$sendtime,
+        "send_num"=>$send_num,
+        "check_num"=>$check_num,
+        "error_num"=>$error_num,
+        "status"=>$status,
+        "addtime"=>date("Y-m-d H:i:s"),
+        "updatetime"=>date("Y-m-d H:i:s")
+    ];
+    $datainfo = Db::name('order_out')->insert($data);
+    if($datainfo){
+        return error_show(0,"创建成功");
+    }else{
+        return error_show(1003,"创建失败");
+    }
+}
+public function customer(){
+    $orderCode= isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
+    if(empty($orderCode)){
+        return error_show(1002,"销售订单编号不能为空");
+    }
+    $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] :"";
+    if($status==""){
+        return error_show(10002,"状态不能为空");
+    }
+    $codeinfo = Db::name('order_out')->where(['orderCode'=>$orderCode])->find();
+    if($codeinfo==""){
+        return error_show(1003,"未找到订单数据");
+    }
+    $codeinfo['status']=$status;
+    $codeinfo['updatetime']=date("Y-m-d H:i:s");
+    $cust = Db::name('order_out')->save($codeinfo);
+    if($cust){
+        return error_show(0,"销售订单更新成功");
+    }else{
+        return error_show(1003,"销售订单更新失败");
+    }
+}
 }

+ 3 - 0
app/admin/route/app.php

@@ -99,6 +99,9 @@ Route::rule('saleedit','admin/Sale/edit');
 Route::rule('saleinfo','admin/Sale/info');
 Route::rule('saledelect','admin/Sale/del');
 Route::rule('salestatus','admin/Sale/status');
+Route::rule('salefee','admin/Sale/fee');
+Route::rule('saleout','admin/Sale/out');
+Route::rule('salecustomer','admin/Sale/customer');
 
 Route::rule('checkflist','admin/Check/flist');
 Route::rule('checklist','admin/Check/list');