post=$this->request->post(); } public function list(){ $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1"; $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10"; $where =[['is_del',"=",0]]; $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !== "" ? trim($this->post['allot_code']) : ""; if ($allot_code !== "") { // $where['allot_code'] = $allot_code; $where[]=['allot_code',"=",$allot_code]; } $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !== "" ? trim($this->post['wsm_out']) : ""; if ($wsm_out !== "") { //$where['wsm_out'] = $wsm_out; $where[]=['wsm_out',"=",$wsm_out]; } $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !== "" ? trim($this->post['wsm_in']) : ""; if ($wsm_in !== "") { // $where['wsm_in'] = $wsm_in; $where[]=['wsm_in',"=",$wsm_in]; } $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:""; if ($start !="") { //$where = ["addtime"=>Db::raw(">= '{$start}'")]; $where[]=['addtime',">=",$start]; } $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :""; if($end !=""){ // $where = ["addtime"=>Db::raw("<= '{$end}'")]; $where[]=['addtime',"<=",$end]; } $count = Db::name('allot_stock')->where($where)->count(); $total = ceil($count/$size); $page = $page >= $total ? $total : $page; $list = Db::name('allot_stock')//->alias('a')->join("good_stock b","b.wsm") ->where($where)->order("addtime desc")->page($page,$size)->select(); // var_dump(Db::name('allot_stock')->getLastSql()); return app_show(0,"获取成功",['count'=>$count,'list'=>$list]); } public function create(){ $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :""; $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :""; if($wsm_out==""){ return error_show(1002,"出库仓库编号不能为空"); } $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :""; if($wsm_in==""){ return error_show(1002,"入库仓库不能为空"); } // $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? trim($this->post['good_type_code']) :""; // if($good_type_code==""){ // return error_show(1002,"商品属性不能为空"); // } $allot_code=makeNo("XK"); // $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; // if($allot_code==""){ // 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_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : ""; $post_name = isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"" ; $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : ""; $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : ""; $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) : ""; $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) :"0"; if($status==""){ return error_show(1002,"状态不能为空"); } $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:""; if($dain==""){ return error_show(1002,"商品不能为空"); } Db::startTrans(); try { $data=[ "allot_code"=>$allot_code, "wsm_out"=>$wsm_out, "wsm_in"=>$wsm_in, "apply_name"=>$ri, "apply_id"=>$rm, "post_name"=>$post_name, "post_code"=>$post_code, "post_fee"=>$post_fee, "remark"=>$remark, "status"=>$status, "is_del"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; $pd=Db::name('allot_stock')->insert($data,true); $dm=[]; if($pd>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") ->join("warehouse_info v","v.wsm_code=c.wsm_code","left") ->join("supplier n","n.code=v.supplierNo","left") ->where(['c.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,n.name")->find(); // var_dump(Db::name("good_type")->getLastSql()); if (empty($st)) { Db::rollback(); return error_show(1003, "商品不能为空"); } $temp = []; $temp['good_name'] = $st['good_name']; $temp['allot_code'] =$allot_code; $temp['good_type_code'] = $value['good_code']; $temp['allot_num'] = $value['allot_num']; $temp['usable_num'] = 0; $temp['error_num'] = 0; $temp['error_remark'] = ""; $temp['stock_num'] = 0; $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $dm[]=$temp; $io = Db::name('allot_info')->insertAll($dm); //var_dump(Db::name('allot_info')->getLastSql()); if ($io) { DB::commit(); return error_show(0, "调拨创建成功"); } } } Db::rollback(); return error_show(1002,"调拨创建失败"); }catch(\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function info(){ $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :""; if($id==""){ return error_show(1002,"调拨编号不能为空"); } $str = Db::name('allot_stock') ->where(['id'=>$id,'is_del'=>0])->find(); $stv = Db::name('warehouse_info')->where(['supplierNo'=>$str['wsm_out'],'is_del'=>0])->field('supplierNo,wsm_code')->find(); $vr = Db::name('supplier')->where(['code'=>$stv['supplierNo'],'is_del'=>0])->field('name,code')->find(); $st = Db::name('warehouse_info')->where(['supplierNo'=>$str['wsm_in'],'is_del'=>0])->field('supplierNo,wsm_code')->find(); $var = Db::name('supplier')->where(['code'=>$st['supplierNo'],'is_del'=>0])->field('name,code')->find(); $str ['wsm_out_name']=$vr['name']; $str ['wsm_in_name']=$var['name']; // $str = Db::name('allot_stock')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_out","left") // ->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()); if(empty($str)){ return error_show(1003,"未找到调拨数据"); } $vmp = Db::name('allot_info')->where(['allot_code'=>$str['allot_code']])->select(); $str['item']=$vmp; if(empty($str)){ return error_show(1002,"未找到调拨编号"); }else{ return app_show(0,"获取成功",$str); } } public function edit(){ $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :""; $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :""; if($id===""){ return error_show(1002,"参数id不能为空"); } $etid = Db::name("allot_stock")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($etid)){ return error_show(1002,"未找到数据"); } $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; $post_name = isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :""; $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :""; $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_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : ""; $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"" ; if($wsm_out==""){ return error_show(1002,"出库仓库不能为空"); } $wsm_in= isset($this->post['wsm_in']) && $this->post['wsm_in'] !=="" ? trim($this->post['wsm_in']) :"" ; if($wsm_in==""){ 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,"状态不能为空"); } $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:""; if($dain==""){ return error_show(1002,"商品不能为空"); } Db::startTrans(); try{ $data=[ "allot_code"=>$allot_code, "apply_id"=>$rm, "apply_name"=>$ri, "wsm_out"=>$wsm_out, "wsm_in"=>$wsm_in, "post_fee"=>$post_fee, "post_name"=>$post_name, "post_code"=>$post_code, "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") ->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)) { Db::rollback(); return error_show(1003, "商品不能为空"); } $temp = []; isset($value['id']) ? $temp['id'] = $value['id']:''; $temp['good_name'] = $st['good_name']; $temp['good_type_code'] = $value['good_code']; $temp['allot_num'] = $value['allot_num']; $temp['usable_num'] = 0; $temp['error_num'] = 0; $temp['error_remark'] = ""; $temp['allot_code'] = $etid['allot_code']; $temp['stock_num'] = 0; 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, "调拨更新成功"); } } } Db::rollback(); return error_show(1003, "调拨更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function del(){ $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :""; if($id===""){ return error_show(1004,"参数id不能为空"); } $str= Db::name('allot_stock')->where(['id'=>$id,'is_del'=>0])->find(); if(empty($str)){ return error_show(1002,"未找到数据"); } $end = Db::name('allot_stock')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]); if($end){ return error_show(0,"删除成功"); }else{ return error_show(1002,"删除失败"); } } public function status(){ $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"" ; if($id==""){ return error_show(1002,"调拨编号不能为空"); } $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :""; $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :""; if($status===""){ return error_show(1002,"审核状态不能为空"); } $st = Db::name('allot_stock')->where(['id'=>$id,"is_del"=>0])->find(); if(empty($st)){ return error_show(1002,"调拨信息未找到"); } Db::startTrans(); try{ $st['remark']=$remark; $st['status']=$status; $st['updatetime']= date('Y-m-d H:i:s'); $sv = Db::name('allot_stock')->save($st); if($sv){ if($status==2){ $vmp = Db::name('allot_info')->where(['allot_code'=>$st['allot_code']])->select(); foreach ($vmp as $value){ $stock = Db::name("good_stock")->where(["good_type_code"=>$value['good_type_code'],"wsm_code"=>$st['wsm_out'],"is_del"=>0])->find(); //var_dump($value['allot_num'],$stock['usable_stock']); if($value['allot_num']>$stock['usable_stock']){ return error_show(1003,"超出库存数量"); } $stock['usable_stock']-=$value['allot_num']; $stock['wait_out_stock']+=$value['allot_num']; $stock['total_stock']=$stock['wait_out_stock']+$stock['usable_stock']; $stock['updatetime']= date('Y-m-d H:i:s'); $Db = Db::name('good_stock')->update($stock); //var_dump(Db::name('good_stock')->getLastSql()); if($Db==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 getont(){ $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; if(empty($allot_code)){ return error_show(1002,"调拨单编号不能为空"); } $al = Db::name('allot_stock')->where(['allot_code'=>$allot_code,"is_del"=>0])->find(); if($al==""){ return error_show(1003,"调拨编号未找到"); } $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'] !=="" ? trim($this->post['post_fee']) :"" ; if($post_fee===""){ return error_show(1002,"物流费用不能为空"); } Db::startTrans(); try { $data=[ "allot_code"=>$allot_code, "post_name"=>$post_name, "post_code"=>$post_code, "post_fee"=>$post_fee, "status"=>3, "is_del"=>0, "updatetime"=>date("Y-m-d H:i:s"), ]; $datainfo = Db::name('allot_stock')->where(['allot_code'=>$allot_code])->update($data); if($datainfo){ $vnp = Db::name('allot_info')->where(['allot_code'=>$al['allot_code']])->select(); var_dump(Db::name('allot_info')->getLastSql()); foreach ($vnp as $value){ $stock = Db::name("good_stock")->where(["good_type_code"=>$value['good_type_code'],"wsm_code"=>$al['wsm_out'],"is_del"=>0])->find(); if($stock['wait_out_stock']<$value['allot_num']){ return error_show(1006,"超出库存数量"); } $stock['wait_out_stock']-=$value['allot_num']; $stock['intra_stock']+=$value['allot_num']; $stock['total_stock']=$stock['wait_out_stock']+$stock['usable_stock']; $stock['updatetime']= date('Y-m-d H:i:s'); $dr = Db::name('good_stock')->update($stock); if($dr==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 getin(){ $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; if(empty($allot_code)){ return error_show(1002,"调拨单编号不能为空"); } $al = Db::name('allot_stock')->where(['allot_code'=>$allot_code,"is_del"=>0])->find(); if($al==""){ return error_show(1003,"调拨编号未找到"); } $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:""; if($dain==""){ return error_show(1002,"商品不能为空"); } Db::startTrans(); try { $data=[ "allot_code"=>$allot_code, "is_del"=>0, "status"=>4, "updatetime"=>date("Y-m-d H:i:s"), ]; $datainfo = Db::name('allot_stock')->where(['allot_code'=>$allot_code,"is_del"=>0])->save($data); if($datainfo>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' => $al['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,c.wsm_code,c.usable_stock,c.good_type_code")->find(); //var_dump(Db::name("good_type")->getLastSql()); if (empty($st)) { Db::rollback(); return error_show(1003, "商品不能为空"); } $temp = []; $temp['usable_num'] = $value['usable_num']; $temp['error_num'] = $value['error_num']; $temp['error_remark'] = $value['error_remark']; $temp['updatetime'] = date("Y-m-d H:i:s"); $np = Db::name('allot_info')->where(['good_type_code'=>$value['good_type_code'],'allot_code'=> $al['allot_code']])->save($temp); $stock = Db::name("good_stock")->where(["good_type_code"=>$np['allot_code'],"wsm_code"=>$al['wsm_out'],"is_del"=>0])->find(); if($stock['intra_stock']<$np['allot_num']){ return error_show(1002,"超出库存数量"); } $stock['intra_stock']-=$np['allot_num']; $stock['wait_in_stock']+=$np['allot_num']; $stock['updatetime']= date('Y-m-d H:i:s'); $stock['total_stock']=$stock['wait_out_stock']+$stock['usable_stock']; $dr = Db::name('good_stock')->update($stock); if ($dr==false) { Db::rollback(); return error_show(0, "入库验货更新失败"); } Db::commit(); return error_show(1003, "入库验货更新成功"); } } Db::rollback(); return error_show(1002, "入库验货更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } /*验货审核*/ public function vesio(){ $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; if(empty($allot_code)){ return error_show(1002,"调拨单编号不能为空"); } $al = Db::name('allot_stock')->where(['allot_code'=>$allot_code,"is_del"=>0])->find(); if($al==""){ return error_show(1003,"调拨编号未找到"); } $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:""; if($dain==""){ return error_show(1002,"商品不能为空"); } Db::startTrans(); try { $data=[ "allot_code"=>$allot_code, "status"=>5, "is_del"=>0, "updatetime"=>date("Y-m-d H:i:s"), ]; $datainfo = Db::name('allot_stock')->where(['allot_code'=>$allot_code,"is_del"=>0])->save($data); if($datainfo>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' => $al['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,c.wsm_code,c.usable_stock")->find(); // var_dump(Db::name("good_type")->getLastSql()); if (empty($st)) { Db::rollback(); return error_show(1003, "商品不能为空"); } $temp = []; $temp['stock_num'] = $value['stock_num']; $temp['updatetime'] = date("Y-m-d H:i:s"); $np = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code']])->save($temp); $stock = Db::name("good_stock")->where(["good_type_code"=>$np['allot_code'],"wsm_code"=>$datainfo['wsm_in'],"is_del"=>0])->find(); if($stock['wait_in_stock'<$np['allot_num']]){ return error_show(1002,"超出库存数量"); } $stock['wait_in_stock']-=$np['allot_num']; $stock['usable_stock']+=$np['allot_num']; $stock['total_stock']=$stock['wait_out_stock']+$stock['usable_stock']; $dr = Db::name('good_stock')->update([$stock,"updatetime"=>date('Y-m-d H:i:s')]); if ($dr==false) { Db::rollback(); return error_show(0, "验货更新失败"); } Db::commit(); return error_show(1003, "验货更新成功"); } } Db::rollback(); return error_show(1003, "验货更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } }