request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; // if($token==""){ // return error_show(101,'token不能为空'); // // } // $effetc = VerifyTokens($token); // if(!empty($effetc) && $effetc['code']!=0){ // return error_show($effetc['code'],$effetc['message']); // } } public function add(){ $post =$this->request->post(); $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,'未找到供应商数据'); } $wsmtype = isset($post['wsmtype'])&& $post['wsmtype']!='' ?intval($post['wsmtype']) :''; if($wsmtype==''){ return error_show(1004,'参数wsmtype 不能为空'); } $isT = Db::name('warehouse_info')->where([['name',"=",$name],["is_del","=",0]])->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 不能为空'); } $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']):""; $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']!=="" ? trim($post['addr_code']):""; try{ $data =[ 'wsm_code'=>makeNo("WSM"), 'name'=>$name, 'wsm_type'=>$wsmtype, 'supplierNo'=>$supplier, 'addr'=>$addr, 'contactor'=>$contactor, 'mobile'=>$mobile, 'position'=>$position, 'status'=>1, 'addtime'=>date("Y-m-d H:i:s"), 'updatetime'=>date("Y-m-d H:i:s") ]; $add = Db::name('warehouse_info')->insert($data); if($add){} }catch (\Exception $e){ return error_show(1005,$e->getMessage()); } return $add ? app_show(0,'仓库创建成功'): error_show(1005,'仓库创建失败'); } public function list(){ $post =$this->request->post(); $condition= [['is_del',"=",0]]; $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :""; if($supplier!=""){ $condition[]=["supplierNo","=",$supplier]; } $wsm_code = isset($post['wsm_code'])&&$post['wsm_code']!="" ? trim($post['wsm_code']) :""; if($wsm_code!=""){ $condition[]=["wsm_code","=",$wsm_code]; } $start = isset($post['start'])&&$post['start']!="" ? $post['start'] :""; if($start!=""){ $condition[]=["addtime",">=",$start]; } $end = isset($post['end'])&&$post['end']!="" ? $post['end'] :""; if($end!=""){ $condition[]=["addtime","<=",$end]; } $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :""; if($mobile!=""){ $condition[]=["mobile","like","%{$mobile}%"]; } $contactor = isset($post['contactor'])&&$post['contactor']!="" ? trim($post['contactor']) :""; if($contactor!=""){ $condition[]=["contactor","like","%{$contactor}%"]; } $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1; $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10; $count = Db::name("warehouse_info")->where($condition)->count(); $page>=ceil($count/$size) ? $page = ceil($count/$size): ''; $list = Db::name("warehouse_info")->where($condition)->page($page,$size)->order("addtime desc")->select(); foreach ($list as $key=>$value){ if($value['supplierNo']!=""){ $supplierinfo = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find(); $value['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :""; }else{ $value['supplier_name']=""; } 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']=""; } $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")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($warse)){ return error_show(1004,"未找到数据"); } if($warse['supplierNo']!=""){ $supplierinfo = Db::name("supplier")->where(["code"=>$warse['supplierNo']])->find(); $warse['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :""; }else{ $warse['supplier_name']=""; } if($warse['wsm_type']!=""){ $type = Db::name("warehouse_type")->where(["id"=>$warse['wsm_type']])->find(); $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])->find(); if(empty($warse)){ return error_show(1004,"未找到数据"); } $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],["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 不能为空'); } $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']) :''; $data =[ 'name'=>$name, 'addr'=>$addr, 'contactor'=>$contactor, 'mobile'=>$mobile, 'position'=>$position, 'updatetime'=>date("Y-m-d H:i:s") ]; $add = Db::name('warehouse_info')->where($warse)->update($data); return $add ? app_show(0,'仓库修改成功'): error_show(1005,'仓库修改失败'); } 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); 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 不能为空"); } $warse['status'] = $status; $warse['updatetime'] = date("Y-m-d H:i:s"); $Del= Db::name("warehouse_info")->save($warse); return $Del? app_show(0,'仓库状态修改成功'): error_show(1005,'仓库状态修改失败'); } }