Переглянути джерело

Merge branch 'wugg' of wugg/phpstock into version1.5

wugg 2 роки тому
батько
коміт
537f74bc8f
1 змінених файлів з 77 додано та 2 видалено
  1. 77 2
      app/admin/controller/Orderback.php

+ 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"];