request->only([ 'companyNo', 'supplierNo', 'name', 'addr_code' => '', 'addr', 'contactor_id', 'mobile', 'wsm_name' => '', 'wsm_mobile' => '', 'wsm_addr' => '', 'addrs_code' => '', 'position' => '', 'wsmtype', ], 'post', 'trim'); $val = Validate::rule([ 'companyNo|业务公司编码' => 'require', 'supplierNo|供应商编码' => 'require', 'name|仓库名称' => 'require', 'wsmtype|仓库类型' => 'require', 'addr|仓库地址' => 'require', 'contactor_id|仓库管理员' => 'require|number|gt:0', 'mobile|仓库联系方式' => 'require', ]); if ($val->check($post) == false) return json_show(1004, $val->getError()); // $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :''; // if($name==''){ // return error_show(1004,'参数name 不能为空'); // } // $supplier = isset($post['supplierNo'])&& $post['supplierNo']!='' ?trim($post['supplierNo']) :''; // if($supplier==''){ // return error_show(1004,'参数supplierNo 不能为空'); // } // $supplierinfo = Db::name("supplier")->where(["code"=>$supplier])->find(); // if(empty($supplierinfo)){ // return error_show(1004,'未找到供应商数据'); // } // if($name==$supplierinfo['name']){ // return error_show(1004,'仓库名不可以与供应商名称相同'); // } // $wsmtype = isset($post['wsmtype'])&& $post['wsmtype']!='' ?intval($post['wsmtype']) :''; // if($wsmtype==''){ // return error_show(1004,'参数wsmtype 不能为空'); // } $isT = Db::name('warehouse_info') ->field('id') ->where([['name', "=", $post['name']], ["is_del", "=", 0],["companyNo","=",$post['companyNo']]]) ->findOrEmpty(); if (!empty($isT)) return error_show(1004, '仓库名称已存在'); // $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :''; // if($addr==''){ // return error_show(1004,'参数addr 不能为空'); // } // $contactor_id = isset($post['contactor_id'])&& $post['contactor_id']!='' ?trim($post['contactor_id']) :''; // if($contactor_id==''){ // return error_show(1004,'参数 contactor_id 不能为空'); // } // $contactorinfo = GetInfoById($post['token'],['id'=>$contactor_id]); // if(!empty($contactorinfo) && $contactorinfo['code']!=0){ // return error_show($contactorinfo['code'],$contactorinfo['message']); // } // $nickname = $this->uname; // $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :''; // if($mobile==''){ // return error_show(1004,'参数mobile 不能为空'); // } // $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :''; // $companyNo = isset($post['companyNo'])&& $post['companyNo']!='' ?trim($post['companyNo']) :''; // if($companyNo==""){ // return error_show(1004,"参数companyNo不能为空"); // } // $company = Db::name("business")->where(["companyNo"=>$companyNo,"is_del"=>0])->find(); // if($company==false){ // return error_show(1004,"业务企业未找到"); // } $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('getCodeAndName', ['code' => [$post['companyNo'], $post['supplierNo']]]); if (!isset($tmp['data'][$post['companyNo']])) return json_show(1004, '业务企业未找到'); if (!isset($tmp['data'][$post['supplierNo']])) return json_show(1004, '供应商未找到'); if ($tmp['data'][$post['supplierNo']] == $post['name']) return json_show(1004, '仓库名不可以与供应商名称相同'); $user = $userCommon->handle('userinfo', ['id' => $post['contactor_id']]); // $wsm_type = isset($post['wsm_type']) && $post['wsm_type']!=="" ? intval($post['wsm_type']):"1"; // $wsm_name = isset($post['wsm_name']) && $post['wsm_name']!=="" ? trim($post['wsm_name']):""; // $wsm_mobile = isset($post['wsm_mobile']) && $post['wsm_mobile']!=="" ? trim($post['wsm_mobile']):""; // $addr_code = isset($post['addr_code']) && $post['addr_code']!=="" ? $post['addr_code']:""; // $wsm_addr = isset($post['wsm_addr']) && $post['wsm_addr']!=="" ? trim($post['wsm_addr']):""; // $addrs_code = isset($post['addrs_code']) && $post['addrs_code']!=="" ? $post['addrs_code']:""; Db::startTrans(); try { $date = date('Y-m-d H:i:s'); $wsm_code = makeNo("WSM"); $data = [ 'wsm_code' => $wsm_code, 'name' => $post['name'], 'wsm_type' => $post['wsmtype'], 'supplierNo' => $post['supplierNo'], 'supplierName' => $tmp['data'][$post['supplierNo']], 'addr' => $post['addr'], 'companyNo' => $post['companyNo'], 'companyName' => $tmp['data'][$post['companyNo']]??'', 'contactor' => $post['contactor_id'], 'contactor_name' => $user['data']['nickname'], 'mobile' => $post['mobile'], 'position' => $post['position'], "addrs_code" => json_encode($post['addrs_code']), 'status' => 1, 'is_del' => 0, 'createrid' => $this->uid, 'creater' => $this->uname, 'addtime' => $date, 'updaterid' => $this->uid, 'updater' => $this->uname, 'updatetime' => $date ]; $add = Db::name('warehouse_info')->insert($data, true); if ($add > 0) { $st = ["order_code" => $wsm_code, "status" => 1, "action_remark" => '', "action_type" => "create"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $st, "warehouse", 1, $data); $addrinfo = [ "wsm_code" => $wsm_code, "wsm_type" => $post['wsmtype'], "wsm_name" => $post['wsm_name'], "wsm_mobile" => $post['wsm_mobile'], "wsm_addr" => $post['wsm_addr'], "addr_code" => json_encode($post['addr_code']), "status" => 1, "addtime" => $date, "updatetime" => $date, ]; $addri = DB::name("warehouse_addr")->insert($addrinfo); if ($addri) { $sf = ["order_code" => $wsm_code, "status" => 1, "action_remark" => '', "action_type" => "create"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $sf, "warehouse", 1, $addrinfo); Db::commit(); return app_show(0, '仓库创建成功', ["wsm_code" => $wsm_code]); } } Db::rollback(); return error_show(1005, '仓库创建失败'); } catch (\Exception $e) { Db::rollback(); return error_show(1005, $e->getMessage()); } } public function list(){ $post =$this->request->post(); $condition= [['a.is_del',"=",0],["b.is_del","=",0]]; $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :""; if($supplier!=""){ $condition[]=["supplierNo","=",$supplier]; } // $companyNo = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :""; // if($companyNo!=""){ // $condition[]=["companyNo","=",$companyNo]; // } $wsm_code = isset($post['wsm_code'])&&$post['wsm_code']!="" ? trim($post['wsm_code']) :""; if($wsm_code!=""){ $condition[]=["a.wsm_code","like","%{$wsm_code}%"]; } $start = isset($post['start'])&&$post['start']!="" ? $post['start'] :""; if($start!=""){ $condition[]=["a.addtime",">=",$start]; } $end = isset($post['end'])&&$post['end']!="" ? $post['end'] :""; if($end!=""){ $condition[]=["a.addtime","<=",$end]; } $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :""; if($mobile!=""){ $condition[]=["a.mobile","like","%{$mobile}%"]; } $contactor = isset($post['contactor_id'])&&$post['contactor_id']!="" ? trim($post['contactor_id']) :""; if($contactor!=""){ $condition[]=["a.contactor","=",$contactor]; } $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? intval($post['wsm_type']) :""; if($wsm_type!=""){ $condition[]=["a.wsm_type","=",$wsm_type]; } $contactor_name = isset($post['contactor_name'])&&$post['contactor_name']!="" ? trim($post['contactor_name']) :""; if($contactor_name!=""){ $condition[]=["a.contactor_name","like","%{$contactor_name}%"]; } $wsm_name = isset($post['wsm_name'])&&$post['wsm_name']!="" ? trim($post['wsm_name']) :""; if($wsm_name!=""){ $condition[]=["a.name","like","%{$wsm_name}%"]; } $companyNo = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :""; if($companyNo!=""){ $condition[]=["a.companyNo","like","%{$companyNo}%"]; } $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $condition[]=['a.companyNo','=', $relaComNo]; $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? (int)($post['wsm_type']) :0; if($wsm_type){ $condition[]=["a.wsm_type",'=',$wsm_type]; } $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1; $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10; $company_new_name = isset($post['company_new_name']) && $post['company_new_name'] !== "" ? trim($post['company_new_name']) : ""; if ($company_new_name !== "") $condition[] = ["a.contactor", 'in', get_company_item_user_by_name($company_new_name)]; $count = Db::name("warehouse_info") ->alias("a") ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left") ->where($condition) ->count(); $page>=ceil($count/$size) ? $page = ceil($count/$size): ''; $list = Db::name("warehouse_info") ->alias("a") ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left") ->where($condition) ->field("a.id,a.wsm_code,a.name,a.wsm_type,a.supplierNo,a.supplierName,a.addr,a.contactor,a.contactor_name,a.mobile,a.position,a.status,a.addtime,a.companyNo,a.companyName,a.updatetime,a.wsm_type,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code,a.addrs_code,a.creater") ->page($page,$size) ->order("a.addtime desc") ->select() ->toArray(); $all_createrid = array_column($list,'contactor'); $item = get_company_name_by_uid($all_createrid); // $all_companyNo = array_column($list,'companyNo'); // $userCommon = \app\admin\common\User::getIns(); // $tmp = $userCommon->handle('getCodeAndName',['code'=>$all_companyNo]); foreach ($list as $key=>$value){ $value['company_name'] = $value['companyName'];//$tmp['data'][$value['companyNo']]??''; if($value['wsm_type']!=""){ $type = Db::name("warehouse_type")->where(["id"=>$value['wsm_type']])->find(); $value['type_name'] = isset($type['name']) ? $type['name'] :""; }else{ $value['type_name']=""; } $value['addrs_cn'] =isset($value['addrs_code']) ?GetAddr($value['addrs_code']):""; $value['addr_cn'] =isset($value['addr_code']) ? GetAddr($value['addr_code']):""; $value['addr_code'] = json_decode($value['addr_code'], true); $value['addrs_code'] = json_decode($value['addrs_code'], true); $value['company_new_name'] = $item[$value['contactor']]??''; $list[$key]=$value; } return app_show(0,"获取成功",['list'=>$list,"count"=>$count]); } public function info(){ $post =$this->request->post(); $id = isset($post['id']) && $post['id']!==''?intval($post['id']): ""; if($id===""){ return error_show(1004,"参数id不能为空"); } $warse = Db::name("warehouse_info") ->alias("a") ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left") ->where(["a.id"=>$id,"a.is_del"=>0,"a.status"=>1]) ->field("a.*,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code") ->withAttr('addr_code', function ($val) { return json_decode($val, true); //单独处理省市区编码 }) ->findOrEmpty(); if(empty($warse)) return error_show(1004,"未找到数据"); // $userCommon = \app\admin\common\User::getIns(); // $tmp = $userCommon->handle('getCodeAndName',['code'=>[$warse['supplierNo'],$warse['companyNo']]]); // if($warse['supplierNo']!=""){ // $supplierinfo = Db::name("supplier")->where(["code"=>$warse['supplierNo']])->find(); // $warse['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :""; // }else{ // $warse['supplier_name']=""; // } $warse['supplier_name'] = $warse['supplierName'];//$tmp['data'][$warse['supplierNo']]??''; // if($warse['companyNo']!=""){ // $company = Db::name("business")->where(["companyNo"=>$warse['companyNo']])->find(); // $warse['company_name'] = isset($company['company']) ? $company['company'] :""; // }else{ // $warse['company_name']=""; // } $warse['company_name'] = $warse['companyName'];//$tmp['data'][$warse['companyNo']]??''; $warse['addrs_code'] = isset($warse['addrs_code'])&&$warse['addrs_code']!="" ? json_decode($warse['addrs_code'],true):""; if($warse['wsm_type']!=""){ $type = Db::name("warehouse_type")->field('name')->where(["id"=>$warse['wsm_type']])->findOrEmpty(); $warse['type_name'] = isset($type['name']) ? $type['name'] :""; }else{ $warse['type_name']=""; } return app_show(0,"获取成功",$warse); } public function save(){ $post =$this->request->post(); $id = isset($post['id']) && $post['id']!==''?intval($post['id']): ""; if($id===""){ return error_show(1004,"参数id不能为空"); }; $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0,"status"=>1])->find(); if(empty($warse)){ return error_show(1004,"未找到数据"); } $companyNo = isset($post['companyNo'])&& $post['companyNo']!='' ?trim($post['companyNo']) :''; if($companyNo==""){ return error_show(1004,"参数companyNo不能为空"); } $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :''; if($name==''){ return error_show(1004,'参数name 不能为空'); } $isT = Db::name('warehouse_info')->where([['name',"=",$name],["is_del","=",0],["companyNo","=", $companyNo],["id","<>", $id]])->find(); if(!empty($isT)){ return error_show(1004,'仓库名称已存在'); } $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :''; if($addr==''){ return error_show(1004,'参数addr 不能为空'); } // $contactor = isset($post['contactor'])&& $post['contactor']!='' ?trim($post['contactor']) :''; // if($contactor==''){ // return error_show(1004,'参数contactor_id 不能为空'); // } $contactor = isset($post['contactor_id'])&& $post['contactor_id']!='' ?intval($post['contactor_id']) :''; if($contactor==''){ return error_show(1004,'参数contactor 不能为空'); } // $company = Db::name("business")->where(["companyNo"=>$companyNo,"is_del"=>0])->find(); // if($company==false){ // return error_show(1004,"业务企业未找到"); // } $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('getCodeAndName',['code'=>$companyNo]); if(empty($tmp['data'])) return json_show(1004,'业务企业未找到'); $user = $userCommon->handle('userinfo',['id'=>$contactor]); // $contactorinfo = GetInfoById($post['token'],['id'=>$contactor]); // if(!empty($contactorinfo) && $contactorinfo['code']!=0){ // return error_show($contactorinfo['code'],$contactorinfo['message']); // } $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :''; if($mobile==''){ return error_show(1004,'参数mobile 不能为空'); } $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :''; $wsm_type = isset($post['wsm_type']) && $post['wsm_type']!=="" ? intval($post['wsm_type']):"1"; $wsm_name = isset($post['wsm_name']) && $post['wsm_name']!=="" ? trim($post['wsm_name']):""; $wsm_mobile = isset($post['wsm_mobile']) && $post['wsm_mobile']!=="" ? trim($post['wsm_mobile']):""; $addr_code = isset($post['addr_code']) && $post['addr_code']!=="" ? $post['addr_code']:""; $addrs_code = isset($post['addrs_code']) && $post['addrs_code']!=="" ? $post['addrs_code']:""; $wsm_addr = isset($post['wsm_addr']) && $post['wsm_addr']!=="" ? trim($post['wsm_addr']):""; Db::startTrans(); try{ $data =[ 'name'=>$name, 'addr'=>$addr, 'contactor'=>$contactor, 'contactor_name'=>$user['data']['nickname']??'', 'mobile'=>$mobile, 'position'=>$position, 'companyNo' => $companyNo, 'companyName' => $tmp['data'][$companyNo], 'updaterid'=>$this->uid, 'updater'=>$this->uname, "addrs_code"=>json_encode($addrs_code), 'updatetime'=>date("Y-m-d H:i:s") ]; $add = Db::name('warehouse_info')->where($warse)->update($data); if($add){ $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$st,"warehouse_info",0,$data); $addrinfo = [ "wsm_type"=> $wsm_type, "wsm_name"=>$wsm_name, "wsm_mobile"=>$wsm_mobile, "wsm_addr"=>$wsm_addr, "addr_code"=>json_encode($addr_code), "updatetime"=>date("Y-m-d H:i:s"), ]; $addri = Db::name("warehouse_addr")->where(["wsm_code"=>$warse['wsm_code'],"is_del"=>0])->update ($addrinfo); if($addri){ $sf = ["order_code"=>$warse['wsm_code'],"status"=>$warse['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sf,"warehouse",1,$data); Db::commit(); return app_show(0,'仓库更新成功'); } } Db::rollback(); return error_show(1005,'仓库更新失败'); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function delete(){ $post =$this->request->post(); $id = isset($post['id']) && $post['id']!==''?intval($post['id']): ""; if($id===""){ return error_show(1004,"参数id不能为空"); }; $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($warse)){ return error_show(1004,"未找到数据"); } $warse['is_del'] = 1; $warse['updatetime'] = date("Y-m-d H:i:s"); $Del= Db::name("warehouse_info")->save($warse); if($Del){ $sf = ["order_code"=>$warse['wsm_code'],"status"=>$warse['status'],"action_remark"=>'',"action_type"=>"delete"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sf,"warehouse",1,$warse); } return $Del? app_show(0,'仓库删除成功'): error_show(1005,'仓库删除失败'); } public function status(){ $post =$this->request->post(); $id = isset($post['id']) && $post['id']!==''?intval($post['id']): ""; if($id===""){ return error_show(1004,"参数id不能为空"); }; $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($warse)){ return error_show(1004,"未找到数据"); } $status = isset($post['status']) && $post['status']!=="" ? intval($post['status']) : ""; if($status===""){ return error_show(1005,"参数status 不能为空"); } $vmp=$warse['status']; $warse['status'] = $status; $warse['updatetime'] = date("Y-m-d H:i:s"); $Del= Db::name("warehouse_info")->save($warse); if($Del){ $sf = ["order_code"=>$warse['wsm_code'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sf,"warehouse",$status,$warse); } return $Del? app_show(0,'仓库状态修改成功'): error_show(1005,'仓库状态修改失败'); } public function select(){ $post =$this->request->post(); $condition= [['a.is_del',"=",0],['a.status',"=",1],["b.is_del","=",0]]; // $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :""; // if($supplier!=""){ // $condition[]=["supplierNo","=",$supplier]; // } $company = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :""; if($company!=""){ $condition[]=["companyNo","=",$company]; } $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? intval($post['wsm_type']) :"1"; $condition[]=["a.wsm_type","=",$wsm_type]; $list = Db::name("warehouse_info") ->alias("a") ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left") ->where($condition) ->field("a.id,a.wsm_code,a.name,a.wsm_type,a.supplierNo,a.supplierName,a.addr,a.contactor,a.contactor_name,a.mobile,a.position,a.status,a.addtime,a.updatetime,a.wsm_type,a.companyNo,a.companyName,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code,a.addrs_code") ->order("a.addtime desc") ->select() ->toArray(); // $all_companyNo = array_column($list, 'companyNo'); // $userCommon = \app\admin\common\User::getIns(); // $tmp = $userCommon->handle('getCodeAndName', ['code' => $all_companyNo]); $data=[]; foreach ($list as $value){ $temp=[]; $temp['wsm_code'] =$value['wsm_code']; $temp['wsm_type'] =$value['wsm_type']; $temp['name'] =$value['name']; $temp['supplierNo'] =$value['supplierNo']; $temp['contactor_name'] =$value['contactor_name']; $temp['contactor_id'] =$value['contactor']; $temp['mobile'] =$value['mobile']; $temp['wsm_name'] =$value['wsm_name']; $temp['wsm_mobile'] =$value['wsm_mobile']; $temp['wsm_addr'] =$value['wsm_addr']; $temp['addrs_cn'] =GetAddr($value['addrs_code']); $temp['addr'] =$value['addr']; $temp['wsm_addr_cn'] =GetAddr($value['addr_code']); // $supplierinfo = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find(); // $temp['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :""; $temp['companyNo'] = $value['companyNo']; $value['company_name'] = $value['companyName'];//$tmp[$value['companyNo']] ?? ''; // if($value['companyNo']!=""){ // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find(); // $temp['company_name'] = isset($company['company']) ? $company['company'] :""; // }else{ // $temp['company_name']=""; // } $type = Db::name("warehouse_type")->where(["id"=>$value['wsm_type']])->find(); $temp['type_name'] = isset($type['name']) ? $type['name'] :""; $data[]=$temp; } return app_show(0,'获取成功',$data); } }