post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1"; $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10"; $where = [['a.is_del', "=", 0]]; $allot_code = isset($this->post['allot_code']) && $this->post['allot_code'] !== "" ? trim($this->post['allot_code']) : ""; if ($allot_code !== "") { // $where['a.allot_code'] = $allot_code; $where[] = ['a.allot_code', "=", $allot_code]; } // $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !== "" ? trim($this->post['wsm_out']) : ""; // if ($wsm_out !== "") { //$where['a.wsm_out'] = $wsm_out; // $where[]=['a.wsm_out',"=",$wsm_out]; // } // $wsm_in = isset($this->post['wsm_in']) && $this->post['wsm_in'] !== "" ? trim($this->post['wsm_in']) : ""; // if ($wsm_in !== "") { // $where['a.wsm_in'] = $wsm_in; // $where[]=['a.wsm_in',"=",$wsm_in]; // } $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : ""; if ($start != "") { //$where = ["a.addtime"=>Db::raw(">= '{$start}'")]; $where[] = ['a.addtime', ">=", $start]; } $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : ""; if ($end != "") { // $where = ["a.addtime"=>Db::raw("<= '{$end}'")]; $where[] = ['a.addtime', "<=", $end]; } // $out_supplierNo =isset($this->post['wsm_out_supplierNo']) &&$this->post['wsm_out_supplierNo'] !=="" ? trim($this->post['wsm_out_supplierNo']):""; // if($out_supplierNo!=""){ // $supplier = Db::name("supplier")->where(["code"=>$out_supplierNo])->find(); // if(empty($supplier)){ // return error_show(1004,"未找到出库供应商信息"); // } // $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"wsm_type"=>1,"supplierNo"=>$out_supplierNo])->column("wsm_code"); //$condtion["a.c.wsm_code"] = $wsmcode; // $where[]=['a.wsm_out',"in",$wsmcode]; // } // $out_companyNo = isset($this->post['out_companyNo']) && $this->post['out_companyNo'] !== "" ? trim($this->post['out_companyNo']) : ""; // if ($out_companyNo !== "") { // $where[]=["a.out_companyNo","=",$out_companyNo]; // } // $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !== "" ? trim($this->post['in_companyNo']) : ""; // if ($in_companyNo !== "") { // $where[]=["a.in_companyNo","=",$in_companyNo]; // } // $in_supplierNo =isset($this->post['wsm_in_supplierNo']) &&$this->post['wsm_in_supplierNo'] !=="" ? trim($this->post['wsm_in_supplierNo']):""; // if($in_supplierNo!=""){ // $supplier = Db::name("supplier")->where(["code"=>$in_supplierNo])->find(); // if(empty($supplier)){ // return error_show(1004,"未找到入库供应商信息"); // } // $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"wsm_type"=>1,"supplierNo"=>$in_supplierNo])->column("wsm_code"); //$condtion["c.wsm_code"] = $wsmcode; // $where[]=['a.wsm_in',"in",$wsmcode]; // } $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : ""; if ($status !== "") { $where[] = ['a.status', "=", $status]; } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)]; // $role = $this->checkDataShare(); // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['a.apply_id', 'in', $role[DataGroupModel::$type_全部]]; $role = $this->checkDataShare(); // $hand = resign_hand_user($this->uid,0); // if (!empty($role[DataGroupModel::$type_全部])) { // $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部])); // $where[] = ['a.apply_id', 'in',$arr]; // } $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : ""; //if($relaComNo!="") $where[]=['a.in_companyNo|a.out_companyNo','=', $relaComNo]; $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] != "" ? trim($this->post['wsm_code']) : ""; $type = isset($this->post['type']) && $this->post['type'] != "" ? intval($this->post['type']) : ""; switch ($type) { case 1: //入库 if ($relaComNo !== '') $where[] = ['a.in_companyNo', '=', $relaComNo]; if ($wsm_code !== '') $where[] = ['a.wsm_in', '=', $wsm_code]; break; case 2: //出库 if ($relaComNo !== '') $where[] = ['a.out_companyNo', '=', $relaComNo]; if ($wsm_code !== '') $where[] = ['a.wsm_out', '=', $wsm_code]; break; case 3: //入库和出库 if ($relaComNo !== '') $where[] = ['a.in_companyNo|a.out_companyNo', '=', $relaComNo]; if ($wsm_code !== '') $where[] = ['a.wsm_in|a.wsm_out', '=', $wsm_code]; break; } $count = Db::name('allot_stock') ->alias('a') // ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0") ->where($where) ->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('allot_stock') ->alias('a') ->where($where) ->order("a.addtime desc") ->page($page, $size) ->select() ->toArray(); // var_dump(Db::name('allot_stock')->getLastSql()); $all_createrid = array_column($list, 'apply_id'); $item = get_company_name_by_uid($all_createrid); $userCommon = \app\admin\common\User::getIns(); $data = []; foreach ($list as $value) { $db = Db::name('warehouse_info') ->alias('a') // ->join("supplier b","b.code=a.supplierNo","left") // ->join("business bus","bus.companyNo=a.companyNo","left") // ->field("a.name,a.wsm_code,b.name rname,b.code,bus.company") ->field("a.name,a.wsm_code,a.supplierNo,a.companyNo") ->where(['a.wsm_code' => $value['wsm_out'], 'a.is_del' => 0]) ->find(); $value['name'] = isset($db['name']) ? $db['name'] : ""; $value['wsm_code'] = isset($db['wsm_code']) ? $db['wsm_code'] : ""; $dc = Db::name('warehouse_info') ->alias('a') // ->join("business bus","bus.companyNo=a.companyNo","left") // ->join("supplier b","b.code=a.supplierNo","left") // ->field("a.name,a.wsm_code,b.name tname,b.code,bus.company") ->field("a.name,a.wsm_code,a.supplierNo,a.companyNo") ->where(['a.wsm_code' => $value['wsm_in'], 'a.is_del' => 0]) ->find(); $names = $userCommon->handle('getCodeAndName', ['code' => [$db['supplierNo'], $db['companyNo'], $dc['supplierNo'], $dc['companyNo']]]); $value['rname'] = $names['data'][$db['supplierNo']] ?? '';//isset($db['rname']) ? $db['rname'] : ""; $value['code'] = $db['supplierNo']; $value['out_company_name'] = $names['data'][$db['companyNo']] ?? '';//isset($db['company']) ? $db['company'] : ""; $value['wsm_in_name'] = isset($dc['name']) ? $dc['name'] : ""; $value['wsm_in_code'] = isset($dc['wsm_code']) ? $dc['wsm_code'] : ""; $value['tname'] = $names['data'][$dc['supplierNo']] ?? '';//isset($dc['tname']) ? $dc['tname']:""; $value['rcode'] = isset($dc['supplierNo']) ? $dc['supplierNo'] : ""; $value['in_company_name'] = $names['data'][$dc['companyNo']] ?? '';//isset($dc['company']) ? $dc['company']:""; $value['company_name'] = $item[$value['apply_id']] ?? ''; //是否具有编辑权限 $value['is_allow_update'] = 0; if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1; $data [] = $value; } return app_show(0, "获取成功", ['count' => $count, 'list' => $data]); } 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,"入库仓库不能为空"); } //根据出入库的仓库编码,查出对应的公司、业务公司 $warehouse_temp_info = Db::name('warehouse_info') ->where(['is_del' => 0, 'status' => 1]) ->whereIn('wsm_code', [$wsm_out, $wsm_in]) ->column('supplierNo,companyNo', 'wsm_code');//supplierNo所属供货商,companyNo业务企业 $allot_code=makeNo("XK"); $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_id["data"]['nickname']) ? $apply_id["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, "out_companyNo"=>$warehouse_temp_info[$wsm_out]['companyNo'], "in_companyNo"=>$warehouse_temp_info[$wsm_in]['companyNo'], "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_stock_info")->alias("a") ->leftJoin("good_stock d" ,"d.id=a.stockid") ->leftJoin("good b" ,"d.spuCode=b.spuCode") ->where(['wsm_code' => $wsm_out, 'a.bnCode' => $value['bnCode'], 'd.is_del' => 0]) ->field("d.spuCode,wsm_code,d.usable_stock,d.wait_out_stock,d.wait_in_stock,b.good_name,a.total_num,a.balance_num,a.origin_price") ->find(); if (empty($st)) { Db::rollback(); return error_show(1003, "商品不能为空"); } if($value['allot_num']>$st['balance_num']){ Db::rollback(); return error_show(2000,"库存数量不足"); } $temp = []; $temp['good_name'] = $st['good_name']; $temp['allot_code'] =$allot_code; $temp['bnCode'] =$value['bnCode']; $temp['good_type_code'] = $st['spuCode']; $temp['origin_price'] = $st['origin_price']; $temp['allot_num'] = $value['allot_num']; $temp['usable_num'] =$st['balance_num']; $temp['error_num'] = 0; $temp['error_remark'] = ""; $temp['stock_num'] = 0; $temp['error_code']=""; $temp['good_num']=$st['balance_num']; $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); if ($io) { $order = ["order_code"=>$allot_code,"status"=>$status,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd($this->post['token'],$order,"DBD",$status,$this->post); $process = ["order_code" => $allot_code, "order_id" => $pd, "order_status" => $status, "order_type" => 'DBD', "before_status" => 0, 'holder_id' => $data['apply_id']]; ProcessOrder::AddProcess($token,$process); 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,"参数id不能为空"); } $str = Db::name('allot_stock') ->where(['id'=>$id,'is_del'=>0])->find(); if(empty($str)){ return error_show(1003,"未找到调拨数据"); } $stv = Db::name('warehouse_info')->where(['wsm_code'=>$str['wsm_out'],'is_del'=>0])->field('companyNo,wsm_code,name')->find(); if(empty($stv)){ return error_show(1002,"未找到仓库数据"); } $st = Db::name('warehouse_info')->where(['wsm_code'=>$str['wsm_in'],'is_del'=>0])->field('companyNo,wsm_code,name')->find(); if(empty($st)){ return error_show(1003,"未找到仓库数据"); } $user = \app\admin\common\User::getIns(); $supplie=$user->handle("getCodeAndName",["code"=>[$stv['companyNo'],$st['companyNo']]]); if($supplie['code']!=0 || empty($supplie['data'])) return error_show(1001,"未找到供应商数据"); $vr = ["name"=>$supplie['data'][$stv['companyNo']],"code"=>$stv['companyNo']]; $var = ["name"=>$supplie['data'][$st['companyNo']],"code"=>$st['companyNo']]; // $vr = Db::name('supplier')->where(['code'=>$stv['supplierNo'],'is_del'=>0])->field('name,code as rcode')->find(); // if(empty($vr)){ // return error_show(1001,"未找到供应商数据"); // } // $var = Db::name('supplier')->where(['code'=>$st['supplierNo'],'is_del'=>0])->field('name,code')->find(); // if(empty($var)){ // return error_show(1004,"未找到供应商数据"); // } // var_dump(Db::name('supplier')->getLastSql()); $str ['wsm_out_name']=$vr['name']; $str ['wsm_in_name']=$var['name']; $str ['ckc_name']=$stv['name']; $str ['ckr_name']=$st['name']; $str['out_code']=$vr['code']; $str['in_code']=$var['code']; // $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()); $vmp = Db::name('allot_info')->where(['allot_code'=>$str['allot_code'],'is_del'=>0])->select(); $data=[]; foreach ($vmp as $k=>$value){ $s = Db::name("good_stock_info")->alias("a") ->leftJoin("good_stock d" ,"d.id=a.stockid") ->where(['wsm_code' => $str['wsm_out'], 'a.bnCode' => $value['bnCode'], 'd.is_del' => 0]) ->field("a.balance_num,a.origin_price") ->find(); if($str['status']<=1) { $value['usable_num'] = $s['balance_num']??0; } $value['error_msg']=""; $value['good_code']=$value['spuCode']=$value['good_type_code']; if($value['error_code']!=""){ $msg =Db::name("result_info")->where(['result_code'=>$value['error_code'],"is_del"=>0])->find(); $value['error_msg']=$value['error_code_name']= isset($msg['result']) &&$msg['result']!="" ? $msg['result']:""; } $data[]=$value; } $str['item']=$data; 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,"未找到数据"); } $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_id["data"]['nickname']) ? $apply_id["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=[ "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, "updatetime"=>date('Y-m-d H:i:s'), ]; $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data); if($da!=false) { foreach ($dain as $value) { $st = Db::name("good_stock_info")->alias("a") ->leftJoin("good_stock d" ,"d.id=a.stockid") ->leftJoin("good b" ,"d.spuCode=b.spuCode") ->where(['wsm_code' => $wsm_out, 'a.bnCode' => $value['bnCode'], 'd.is_del' => 0]) ->field("d.spuCode,wsm_code,d.usable_stock,d.wait_out_stock,d.wait_in_stock,b.good_name,a.total_num,a.balance_num,a.origin_price") ->find(); if (empty($st)) { Db::rollback(); return error_show(1003, "商品不能为空"); } if(isset($value['id'])&&$value['id']!==""){ $good = Db::name('allot_info')->where(["id"=>$value['id'],"is_del"=>0])->find(); if(empty($good)||$good['allot_code']!=$etid['allot_code']){ Db::rollback(); return error_show(2000,"商品不属于此次调拨"); } } if($value['allot_num']>$st['balance_num']){ Db::rollback(); return error_show(2000,"批次库存数量不足"); } $temp = []; isset($value['id'])&&$value['id']!=="" ? $temp['id'] = $value['id']:''; $temp['good_name'] = $st['good_name']; $temp['good_type_code'] = $st['spuCode']; $temp['bnCode'] =$value['bnCode']; $temp['allot_num'] = $value['allot_num']; $temp['usable_num'] =$st['balance_num']; $temp['origin_price'] = $st['origin_price']; $temp['error_num'] = 0; $temp['error_remark'] = ""; $temp['allot_code'] = $etid['allot_code']; $temp['stock_num'] = 0; $temp['good_num']=$st['balance_num']; $temp['error_code']=""; $temp['is_del']=$value['is_del']; isset($value['id'])&&$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==false) { Db::rollback(); return error_show(1003, "调拨更新失败"); } } $order = ["order_code"=>$etid['allot_code'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$order,"DBD",$etid['status'],$this->post); 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){ $order = ["order_code"=>$str['allot_code'],"status"=>$str['status'],"action_remark"=>'',"action_type"=>"del"]; ActionLog::logAdd($this->post['token'],$order,"DBD",$str['status'],$this->post); $process=["order_code"=>$str['allot_code'],"order_status"=>$str['status'],"order_type"=>'DBD']; ProcessOrder::workdel($process); //将对应的调拨单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表) Db::name('process_wait') ->where([ 'order_type' => 'DBD', 'order_code' => $str['allot_code'], 'order_id' => $id, 'status' => ProcessWait::$status_wait, ])->update(['status' => ProcessWait::$status_interrupt]); return error_show(0,"删除成功"); }else{ return error_show(1002,"删除失败"); } } // 0 待发起流程 1 待入库方同意 2 待出库方发货 3待入库方验货 4待验货审核 5 调拨完成 6 调拨驳回 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{ $sr= $st['status']; $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 || $status==1){ $good_data=[]; $vmp = Db::name('allot_info')->where(['allot_code'=>$st['allot_code'],"is_del"=>0])->select(); foreach ($vmp as $value){ $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_type_code'],"wsm_code"=>$st['wsm_out'],"is_del"=>0])->find(); if($value['allot_num']>$stock['usable_stock']){ Db::rollback(); return error_show(2000,"超出库存数量"); } $stockinfo = Db::name("good_stock_info")->where(["bnCode"=>$value['bnCode'],"stockid"=>$stock['id']])->find(); if($value['allot_num']>$stockinfo['balance_num']){ Db::rollback(); return error_show(2000,"超出bn库存数量"); } if($status==2){ $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,"状态更新失败"); } $stoup =GoodStockInfo::bnStock($stock['id'],$value['bnCode'],$value['allot_num'],1); if($stoup==false){ Db::rollback(); return error_show(1002,"bn库存数修改失败"); } //商品变动日志表,good_log_code字段存储调拨单号 $good_data[] = ['good_log_code' => $st['allot_code'], "stock_id" => $stock['id'], "type" => 1, 'stock' =>$value['allot_num'], "stock_name" => "wait_out_stock"]; $good_data[] = ['good_log_code' => $st['allot_code'], "stock_id" => $stock['id'], "type" => 2, 'stock' => $value['allot_num'], "stock_name" => "usable_stock"]; } } GoodLog::LogAdd($this->post['token'],$good_data,'DBD'); } $order = ["order_code"=>$st['allot_code'],"status"=>$sr,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd($this->post['token'],$order,"DBD",$status,$this->post); $process=["order_code"=>$st['allot_code'],"order_id"=>$st['id'],"order_status"=>$st['status'],"order_type"=>'DBD',"before_status"=>$sr, 'holder_id' => $st['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$process); 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'],'is_del'=>0])->select(); $good_data=[]; if(!empty($vnp)){ foreach ($vnp as $value){ $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_type_code'],"wsm_code"=>$al['wsm_out'],"is_del"=>0])->find(); if($stock['wait_out_stock']<$value['allot_num']){ Db::rollback(); return error_show(2000,"超出库存数量"); } $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,"发货更新失败"); } //商品变动日志表,good_log_code字段存储调拨单号 $good_data[] = ['good_log_code' => $allot_code, "stock_id" => $stock['id'], "type" => 1, 'stock' => $value['allot_num'], "stock_name" => "intra_stock"]; $good_data[] = ['good_log_code' => $allot_code, "stock_id" => $stock['id'], "type" => 2, 'stock' => $value['allot_num'], "stock_name" => "wait_out_stock"]; } GoodLog::LogAdd($this->post['token'],$good_data,'DBD'); } $order = ["order_code"=>$al['allot_code'],"status"=>$al['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$order,"DBD",3,$this->post); $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>3,"order_type"=>'DBD',"before_status"=>$al['status'], 'holder_id' => $al['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$process); 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) { $good_data=[]; foreach ($dain as $value) { // $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode") // ->where(['wsm_code' => $al['wsm_out'], 'a.spuCode' => $value['good_code'], 'a.is_del' => 0]) // ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find(); // if ($st==false) { // Db::rollback(); // return error_show(1003, "未找到商品"); // } $n = Db::name('allot_info')->where(['id'=>$value['id'],'allot_code'=>$al['allot_code'],'is_del'=>0])->find(); if($n==false){ Db::rollback(); return error_show(10032, "未找到盘点信息数据"); } $temp = []; $temp['error_code']=$value['error_code']; $temp['error_num'] = $value['error_num']; $temp['error_remark'] = $value['error_remark']; $temp['stock_num']=$n['allot_num']-$value['error_num']; $temp['updatetime'] = date("Y-m-d H:i:s"); $np = Db::name('allot_info')->where(['id'=>$value['id'],'allot_code'=> $al['allot_code'],'is_del'=>0])->save($temp); if($np==false){ Db::rollback(); return error_show(1001,"数据更新失败"); } $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_out'],"is_del"=>0])->lock(true)->find(); if($stock['intra_stock']<$n['allot_num']){ Db::rollback(); return error_show(2000,"超出库存数量"); } $stock['updatetime']= date('Y-m-d H:i:s'); $stock['intra_stock']-=$n['allot_num']; $dr = Db::name('good_stock')->update($stock); if($dr==false){ Db::rollback(); return error_show(1002,"数据更新失败"); } //商品变动日志表,good_log_code字段存储调拨单号 $good_data[]=['good_log_code'=>$allot_code,"stock_id"=>$stock['id'],"type"=>2,'stock'=>$n['allot_num'],"stock_name"=>"intra_stock"]; $instock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find(); if($instock==false){ $instock =[]; $instock['spuCode']=$value['good_code']; $instock['wsm_code']=$al['wsm_in']; $instock['wait_in_stock']=0; $instock['wait_out_stock']=0; $instock['usable_stock']=0; $instock['intra_stock']=0; $instock['total_stock']=0; $instock['status']=1; $instock['is_del']=0; $instock['warn_stock']=0; $instock['addtime']= date('Y-m-d H:i:s'); } $instock['wait_in_stock']+=$n['allot_num']-$value['error_num']; $instock['updatetime']= date('Y-m-d H:i:s'); $sk = Db::name('good_stock')->save($instock); if ($sk==false) { Db::rollback(); return error_show(1003, "入库验货更新失败"); } //商品变动日志表,good_log_code字段存储调拨单号 $good_data[]=['good_log_code'=>$allot_code,"stock_id"=>isset($instock['id'])?$instock['id']: Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$n['allot_num']-$value['error_num'],"stock_name"=>"wait_in_stock"]; } GoodLog::LogAdd($this->post['token'],$good_data,'DBD'); $order = ["order_code"=>$al['allot_code'],"status"=>$al['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$order,"DBD",4,$this->post); $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>4,"order_type"=>'DBD',"before_status"=>$al['status'], 'holder_id' => $al['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$process); 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 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) { $order = ["order_code"=>$al['allot_code'],"status"=>$al['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$order,"DBD",5,$this->post); foreach ($dain as $value) { // $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode") // ->where(['wsm_code' => $al['wsm_out'], 'a.spuCode' => $value['good_code'], 'a.is_del' => 0]) // ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find(); $p = Db::name('allot_info')->where(['id'=>$value['id'],'allot_code'=>$al['allot_code'],"is_del"=>0])->find(); if($p==false){ Db::rollback(); return error_show(1002,"未找到盘点数据"); } $temp = []; $temp['error_num'] = $value['error_num']+$p['stock_num']-$value['stock_num']; $temp['stock_num'] = $value['stock_num']; $temp['error_remark'] = $value['error_remark']; $temp['updatetime'] = date("Y-m-d H:i:s"); $np = Db::name('allot_info')->where(['id'=>$value['id'],'allot_code'=> $al['allot_code']])->save($temp); if($np==false){ Db::rollback(); return error_show(1001,"数据更新失败"); } $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->lock(true)->find(); if($stock['wait_in_stock']<$p['stock_num']){ Db::rollback(); return error_show(2000,"超出待入库存数量"); } $stock['wait_in_stock']-=$p['stock_num']; $stock['usable_stock']+=$p['stock_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(1004, "验货更新失败"); } $stoup =GoodStockInfo::bnStock($stock['id'],$p['bnCode'],$p['stock_num'],0,$p['origin_price']); if($stoup==false){ Db::rollback(); return error_show(1002,"bn库存数修改失败"); } //商品变动日志表,good_log_code字段存储调拨单号 $good_data[] = ['good_log_code' => $allot_code, "stock_id" => $stock['id'], "type" => 2, 'stock' => $p['stock_num'], "stock_name" => "wait_in_stock"]; $good_data[] = ['good_log_code' => $allot_code, "stock_id" => $stock['id'], "type" => 1, 'stock' => $p['stock_num'], "stock_name" => "usable_stock"]; } GoodLog::LogAdd($this->post['token'],$good_data,'DBD'); $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>5,"order_type"=>'DBD',"before_status"=>$al['status'], 'holder_id' => $al['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$process); 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 goodlist() { $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; $condtion = [['b.is_del', "=", 0], ['c.is_del', "=", 0],["d.balance_num",">=",0]]; $wsmcode = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : ""; if ($wsmcode !== "") { //return error_show(1002,"仓库code不能为空"); $condtion[] = ['c.wsm_code', "=", $wsmcode]; // $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code"); } $goodcode = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : ""; if ($goodcode != "") { // $condtion['a.good_code'] = Db::raw("like '%{$goodcode}%'"); $condtion[] = ['b.spuCode', "like", "%{$goodcode}%"]; } $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : ""; if ($good_name != "") { // $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'"); $condtion[] = ['b.good_name', "like", "%{$good_name}%"]; } $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : ""; if ($supplierNo != "") { // $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find(); // if (empty($supplier)) { // return error_show(1004, "未找到供应商信息"); // } $wsmcode = Db::name("warehouse_info")->where(["is_del" => 0, "supplierNo" => $supplierNo])->column("wsm_code"); $condtion[] = ['c.wsm_code', "in", $wsmcode]; } $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : ""; if ($companyNo !== "") { $wsmcode = Db::name("warehouse_info")->where(['companyNo' => $companyNo, "is_del" => 0])->column("wsm_code"); $condition[] = ["c.wsm_code", "in", $wsmcode]; } $stock_low = isset($this->post['stock_low']) && $this->post['stock_low'] !== "" ? intval($this->post['stock_low']) : ""; if ($stock_low != "") { $condtion[] = ['d.balance_num', ">=", $stock_low]; } $stock_up = isset($this->post['stock_up']) && $this->post['stock_up'] !== "" ? trim($this->post['stock_up']) : ""; if ($stock_up != "") { $condtion[] = ['d.balance_num', "<=", $stock_up]; } $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : ""; if ($cat_id != "") { $at = Db::name('cat')->where(['id' => $cat_id])->find(); if (empty($at)) { return error_show(1004, "未找到分类信息"); } $cat = manger([$at['id']], $at['level']); $condtion[] = ['b.cat_id', "in", $cat]; } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $condtion[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)]; $count = Db::name("good") ->alias("b") ->join("good_stock c", "c.spuCode=b.spuCode", "left") ->join("good_stock_info d", "c.id=d.stockid", "left") ->where($condtion) ->count(); $page >= ceil($count / $size) ? $page = ceil($count / $size) : ""; $list = Db::name("good") ->alias("b") ->leftJoin("good_stock c", "c.spuCode=b.spuCode") ->join("good_stock_info d", "c.id=d.stockid", "left") ->where($condtion) ->field("b.*,c.id as stock_id,c.usable_stock,c.wait_in_stock,c.wait_out_stock,c.wsm_code,0 uid,'待处理wf' nickname,d.bnCode,d.balance_num,d.origin_price") ->page($page, $size) ->select() ->toArray(); $all_createrid = array_column($list,'createrid'); $item = get_company_name_by_uid($all_createrid); $data = []; if ($list) { //品牌信息 $brands = Db::name('brand')->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id'); $units = Db::name('unit')->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id'); // $business = Db::name('business')->whereIn('companyNo', array_column($list, 'companyNo'))->where('is_del', 0)->column('company', 'companyNo'); $userCommon=\app\admin\common\User::getIns(); $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list, 'supplierNo'),array_column($list, 'companyNo'))]); // $business = $names['data']; $supplier = Db::connect('mysql_sys') ->name('supplier') ->where(['code'=>array_column($list,'supplierNo')]) ->column('name,person','code'); foreach ($list as $key => $value) { // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find(); $value['supplier_name'] = $supplier['name'] ?? '';//$names['data'][$value['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : ""; $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find(); $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : ""; $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : ""; $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : ""; $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : []; $value['brand_name'] = isset($brands[$value['brand_id']]) ? $brands[$value['brand_id']] : ''; $value['unit'] = isset($units[$value['good_unit']]) ? $units[$value['good_unit']] : ''; $value['companyName'] = $names['data'][$value['companyNo']]??'';//isset($names['data'][$value['companyNo']]) ? $business[$value['companyNo']] : ''; //规格信息 $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray(); $speclist = []; if (!empty($spec)) { foreach ($spec as $val) { $temp = []; $temp['spec_id'] = $val['spec_id']; $temp['spec_value_id'] = $val['spec_value_id']; $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find(); $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : ""; $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find(); $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : ""; $speclist[] = $temp; } } $value['specinfo'] = $speclist; $value['cgder'] = $supplier['person'] ?? '';//isset($supplier['person']) ? $supplier['person'] : ''; $value['company_name'] = $item[$value['createrid']]??''; $data[] = $value; } } return app_show(0, "获取成功", ["list" => $data, "count" => $count]); } }