Browse Source

Merge branch 'plm' of ssh://192.168.10.210:10022/wugg/stock into plm

panlumeng 3 years ago
parent
commit
fc1615f851
2 changed files with 133 additions and 0 deletions
  1. 132 0
      app/admin/controller/Salezx.php
  2. 1 0
      app/admin/route/app.php

+ 132 - 0
app/admin/controller/Salezx.php

@@ -357,4 +357,136 @@ class Salezx extends \app\BaseController
             return error_show(1005,$e->getMessage());
         }
     }
+
+    public function out(){
+        $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
+        $outCode=makeNo("CK");
+        $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
+        if($orderCode==""){
+            return error_show(1002,"参数orderCoder不能为空");
+        }
+        $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
+        if($der==""){
+            return error_show(1002,"未找到出库订单单号");
+        }
+       if($der['order_type']!=2){
+           return error_show(1002,"订单不是咨询单无法出库");
+       }
+        $wsm= Db::name('sale_info')->where(['orderCode'=>$der['orderCode']])->find();
+        if(empty($wsm)){
+            return error_show(1002,"未找到仓库信息");
+        }
+//        $stock= Db::name("good_stock")->where(["good_type_code"=>$der['good_code'],"wsm_code"=>$wsm['wsm_code']])
+//            ->find();
+//        if(empty($stock)){
+//            return error_show(1002,"未找到仓库库存信息");
+//        }
+        $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'] : "";
+        if($der['send_type']==1){
+            $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
+            $dr = Db::name('order_addr')->where(['id'=>$addrid,"orderCode"=>$orderCode,'is_del'=>0])->find();
+            if(empty($dr)){
+                return error_show(1003,"收货人信息未找到");
+            }
+            $send_num = $dr['receipt_quantity'];
+        }else{
+            $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
+            if($send_num==""){
+                return error_show(1002,"发货数量不能为空");
+            }
+        }
+//        if($send_num>$stock['usable_stock']){
+//            return error_show(1002,"超出可发货数量");
+//        }
+        $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
+        $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
+        Db::startTrans();
+        try {
+            $data=[
+                "wsm_code"=>$wsm['wsm_code'],
+                "orderCode"=>$orderCode,
+                "outCode"=>$outCode,
+                "order_type"=>$der['order_type'],
+                "apply_id"=>$rm,
+                "apply_name"=>$ri,
+                "addrid"=>$dr['id'],
+                "post_name"=>$post_name,
+                "post_code"=>$post_code,
+                "post_fee"=>$post_fee,
+                "sendtime"=>$sendtime,
+                "send_num"=>$send_num,
+                "check_num"=>0,
+                "error_num"=>0,
+                "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) {
+                if ($status==1) {
+
+                    $var = Db::name('sale_info')->where(['orderCode' =>$orderCode,'wsm_code'=>$wsm['wsm_code']])->find();
+                    //var_dump(Db::name('sale_info')->getLastSql());
+                    if($var==""){
+                        return error_show(1002,"未找到数据");
+                    }
+                    $send =Db::name("order_out")->where(["wsm_code"=>$wsm['wsm_code'],'orderCode'=>$orderCode])->sum("send_num");
+                    $der['send_num']+= $send;
+                    $der['wsend_num']-=$send ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
+                    $der['send_status']=$der['send_num']==0 ? 1 :($der['wsend_num']==0?3:2);
+                    $der['status']=$der['send_num']==0 ? 3 :($der['wsend_num']==0?5:4);
+                    $der['updatetime'] = date("Y-m-d H:i:s");
+                    $si = Db::name('sale')->save($der);
+                    if($si==false){
+                        Db::rollback();
+                        return error_show(1003,"更新失败");
+                    }
+                    $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'],'good_type_code'=>$der['good_code']])->find();
+                    if ($str == false) {
+                        Db::rollback();
+                        return error_show(1002, "商品数据未找到");
+                    }
+                    if ($var['num'] > $str['usable_stock']) {
+                        Db::rollback();
+                        return error_show(1002, "超出库存数量");
+                    }
+                    $str['wait_out_stock'] -= $var['num'];
+                    $str['intra_stock'] += $var['num'];
+                    $str['updatetime'] = date("Y-m-d H:i:s");
+                    $stre = Db::name('good_stock')->save($str);
+                    if ($stre == false) {
+                        Db::rollback();
+                        return error_show(1002, "状态更新失败");
+                    }
+                }
+
+                Db::commit();
+                return error_show(0,"创建成功");
+            }else{
+                Db::rollback();
+                return error_show(1003,"创建失败");
+            }
+        }catch (\Exception $e) {
+            Db::rollback();
+            return error_show(1005, $e->getMessage());
+        }
+    }
 }

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

@@ -252,6 +252,7 @@ Route::rule('reorderexam','admin/Reorder/exam');
 
 Route::rule('salezxcreate','admin/Salezx/create');
 Route::rule('salezxedit','admin/Salezx/edit');
+Route::rule('salezxout','admin/Salezx/out');
 
 Route::rule('saledifflist','admin/Sale/difflist');
 Route::rule('salediffcheck','admin/Sale/diffcheck');