Browse Source

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

wugg 2 years ago
parent
commit
deebf6d07d
1 changed files with 38 additions and 12 deletions
  1. 38 12
      app/admin/controller/Purch.php

+ 38 - 12
app/admin/controller/Purch.php

@@ -472,7 +472,7 @@ class Purch extends Base
             "good_code"=>$cg['spuCode'],
             "good_name"=>$cg['good_name'],
             "sale_price"=>$cg['good_price'],
-            "good_weight"=>$cg['weight'],
+            "good_weight"=>$cg['weight']*$cg['good_num'],
             "good_num"=>$cg['good_num'],
             "apply_id"=>$rid,
             "apply_name"=>$rname,
@@ -488,12 +488,7 @@ class Purch extends Base
         try{
             $item = Db::name("purchease_diff")->insert($data,true);
             if($item>0){
-//                $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
-//                ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
-//                $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
-//                ProcessOrder::AddProcess($this->post['token'],$process);
                 $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->find();
-
                 if($orderCode!=false){
                     $order = Db::name("sale")->where("orderCode", '=', $orderCode['orderCode'])->find();
                     if($order==false){
@@ -644,23 +639,54 @@ class Purch extends Base
         if(empty($cgd)){
             return error_show(1002,"采购单未找到");
         }
+        $salediff=Db::name("sale_diff")->where(["cgd_diffid"=>$dio['id']])->find();
+        if($salediff==false){
+            return error_show(1002,"销售工差单未找到");
+        }
         $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
         if($status===""){
             return error_show(1002,"参数status不能为空");
         }
-        $temp = $dio['status'];
+        Db::startTrans();
+        try{
+            $temp = $dio['status'];
             $dio['status']=$status;
             $dio['updatetime']=date("Y-m-d H:i:s");
             $item = Db::name("purchease_diff")->save($dio);
-         if ($item){
-//             $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
-//             ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
-//             $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
-//             ProcessOrder::AddProcess($this->post['token'],$process);
+            if ($item){
+                if($status==2){
+                    $cgd['diff_fee'] =$dio['diff_price'];
+                    $cgd['diff_weight'] =$dio['diff_weight'];
+                    $cgd['updatetime'] =date("Y-m-d H:i:s");
+                    $cgp=Db::name("purchease_order")->save($cgd);
+                    if($cgp==false){
+                        Db::rollback();
+                        return error_show(1002,"采购单更新失败");
+                    }
+                    if($salediff['is_act']==1){
+                        $saled=[
+                            "diff_fee"=>$salediff['diff_price'],
+                            "diff_weight"=>$salediff['diff_weight'],
+                            "updatetime"=>date("Y-m-d H:i:s")
+                        ];
+                        $up =Db::name("sale")->where(["orderCode"=>$salediff['orderCode']])->save($saled);
+                        if($up==false){
+                            Db::rollback();
+                            return error_show(1002,"销售单更新失败");
+                        }
+                    }
+                }
+                Db::commit();
                 return error_show(0,"更新成功");
             }else{
+                Db::rollback();
                 return error_show(1002,"更新失败");
             }
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1002,$e->getMessage()."|".$e->getLine());
+        }
+
 
     }