wugg 3 years ago
parent
commit
3e4248fbf8
1 changed files with 24 additions and 12 deletions
  1. 24 12
      app/admin/controller/Allot.php

+ 24 - 12
app/admin/controller/Allot.php

@@ -233,8 +233,18 @@ class Allot extends BaseController
 //            ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,")
 //            ->where(['a.id'=>$id,'a.is_del'=>0])->find();
        // var_dump( Db::name('allot_stock')->getLastSql());
-        $vmp = Db::name('allot_info')->where(['allot_code'=>$str['allot_code'],'is_del'=>0])->select();
-        $str['item']=$vmp;
+
+        $vmp = Db::name('allot_info')->where(['allot_code'=>$str['allot_code']])->select();
+
+            $data=[];
+        foreach ($vmp as $k=>$value){
+            $s =Db::name('good_stock')->where(['good_type_code'=>$value['good_type_code'],'wsm_code'=>$str['wsm_out']])->find();
+            if($str['status']==0) {
+                $value['usable_num'] = $s['usable_stock'];
+            }
+            $data[]=$value;
+        }
+        $str['item']=$data;
         if(empty($str)){
             return error_show(1002,"未找到调拨编号");
         }else{
@@ -269,10 +279,10 @@ class Allot extends BaseController
             return error_show(1002,"入库仓库不能为空");
         }
         $post_fee= isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"" ;
-        $status= isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']) :"" ;
-        if($status==""){
-            return error_show(1002,"状态不能为空");
-        }
+//        $status= isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']) :"" ;
+//        if($status==""){
+//            return error_show(1002,"状态不能为空");
+//        }
         $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
         if($dain==""){
             return error_show(1002,"商品不能为空");
@@ -288,14 +298,14 @@ class Allot extends BaseController
                 "post_fee"=>$post_fee,
                 "post_name"=>$post_name,
                 "post_code"=>$post_code,
-                "status"=>$status,
+//                "status"=>$status,
                 "updatetime"=>date('Y-m-d H:i:s'),
             ];
             $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data);
             if($da>0) {
                 foreach ($dain as $value) {
                     $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
-                        ->join("good_stock c", "c.good_type_code = b.type_code", "left")->where(['wsm_code' => $wsm_out, 'good_type_code' => $value['type_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
+                        ->join("good_stock c", "c.good_type_code = b.type_code", "left")->where(['wsm_code' => $wsm_out, 'good_type_code' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
                         ->field("b.type_code,a.good_name,a.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock")->find();
                   // var_dump(Db::name("good_type")->getLastSql());
                     if (empty($st)) {
@@ -321,11 +331,13 @@ class Allot extends BaseController
                     isset($value['id']) ? '' :$temp['addtime'] = date("Y-m-d H:i:s");
                     $temp['updatetime'] = date("Y-m-d H:i:s");
                     $np = Db::name('allot_info')->save($temp);
-                if ($np) {
-                    Db::commit();
-                    return error_show(0, "调拨更新成功");
-                }
+                    if ($np==false) {
+                        Db::rollback();
+                        return error_show(1003, "调拨更新失败");
+                    }
                 }
+                Db::commit();
+                return error_show(0, "调拨更新成功");
             }
             Db::rollback();
             return error_show(1003, "调拨更新失败");