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'] !== "" ? intval($this->post['allot_code']) : ""; if ($allot_code !== "") { $where['allot_code'] = $allot_code; } $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !== "" ? intval($this->post['wsm_out']) : ""; if ($wsm_out !== "") { $where['wsm_out'] = $wsm_out; } $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !== "" ? intval($this->post['wsm_in']) : ""; if ($wsm_in !== "") { $where['wsm_in'] = $wsm_in; } $addtime = isset($this->post['addtime']) && $this->post['addtime'] !== "" ? intval($this->post['addtime']) : ""; if ($addtime !== "") { $where['addtime'] = $addtime; } $count = Db::name('allot_stock')->count(); $total = ceil($count/$size); $page = $page >= $total ? $total : $page; $list = Db::name('allot_stock')->where($where)->page($page,$size)->select(); return app_show(0,"获取成功",['count'=>$count,'list'=>$list]); } // $good_name= isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :""; // $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; // $usable_num = isset($this->post['usable_num']) && $this->post['usable_num'] !=="" ? intval($this->post['allot_code']) :"0"; // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? intval($this->post['error_num']) :"0"; // $error_remark = isset($this->post['error_remark']) && $this->post['error_remark'] !=="" ? trim($this->post['error_remark']) :""; // $stock_num = isset($this->post['stock_num']) && $this->post['error_num'] !=="" ? intval($this->post['error_num']) : "0"; public function create(){ $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_num = isset($this->post['allot_num']) && $this->post['allot_num'] !=="" ? intval($this->post['allot_num']):""; if($allot_num==""){ return error_show(1002,"出库数量不能为空"); } $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !=="" ? trim($this->post['allot_code']) :""; $apply_name= isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :""; $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ; $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"; $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"=>$apply_name, "apply_id"=>$apply_id, "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); if($pd>0){ $pdinfo=[ "good_type_code"=>$good_type_code, "allot_num"=>$allot_num, // "good_name"=>$good_name, "allot_code"=>$allot_code, // "usable_num"=>$usable_num, // "error_num"=>$error_num, // "error_remark"=>$error_remark, // "stock_num"=>$stock_num, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; $cpd = Db::name('allot_info')->insert($pdinfo); if($cpd){ DB::commit(); 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,"调拨编号不能为空"); } $fio = Db::name('allot_stock')->alias('a')->join("allot_info b","a.allot_code=b.allot_code","left") ->where(['a.id'=>$id,'a.is_del'=>0])->field("a.allot_code,a.apply_id,a.apply_name,a.wsm_out,a.wsm_in,a.post_fee,a.status,a.addtime, b.good_type_code,b.allot_code,b.allot_num") ->find(); if(empty($fio)){ return error_show(1002,"未找到调拨编号"); }else{ return app_show(0,"获取成功",$fio); } } public function edit(){ $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']) :""; if($allot_code==""){ return error_show(1002,"调拨单编号不能为空"); } // $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? intval($this->post['apply_id']) :"" ; // if($apply_id==""){ // return error_show(1002,"申请人id不能为空"); // } // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']) :"" ; // if($apply_name==""){ // return error_show(1002,"申请人名称不能为空"); // } $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']) :"" ; if($post_fee==""){ 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,"商品不能为空"); } try{ $data=[ "allot_code"=>$allot_code, // "apply_id"=>$apply_id, // "apply_name"=>$apply_name, "wsm_out"=>$wsm_out, "wsm_in"=>$wsm_in, "post_fee"=>$post_fee, "status"=>$status, "updatetime"=>date('Y-m-d H:i:s'), ]; $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data); $dn = []; 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(); if (empty($st)) { Db::rollback(); return error_show(1003, "商品不能为空"); } $temp = []; $temp['id'] = $value['id']; $temp['good_name'] = $st['good_name']; $temp['good_type_code'] = $value['good_type_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; $temp['updatetime'] = date("Y-m-d H:i:s"); $dn [] = $temp; $np = Db::name('allot_info')->save(['updatetime' => date('Y-m-d H:i:s')]); $io = db::name('allot_info')->insertAll($dn); if ($io) { Db::commit(); return error_show(0, "调拨更新成功"); } } } Db::rollback(); return error_show(1003, "调拨更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } }