request->filter('trim')->only(['page'=>1,'size'=>10,'name'=>'','code'=>'','is_platform'=>''],'post'); $where = [['is_del',"=",0]]; if ($param['name'] !== "") $where[] = ["name","like", "%{$param['name']}%"]; if ($param['code'] !== "") $where[] = ["code","=", $param['code']]; if ($param['is_platform'] !== "") $where[] = ['is_platform',"=", $param['is_platform']]; $count = Db::name("supplier")->where($where)->count(); $total = ceil($count/$param['size']); $page = $param['page'] >= $total ? $total : $param['page']; $list = Db::name('supplier') ->where($where) ->page($page, $param['size']) ->select() ->toArray(); //这些供应商是否有启用的账号 $has_account = checkHasAccountBySupplierNos(array_column($list, 'code')); foreach ($list as &$value) { $value['has_account'] = (int)isset($has_account[$value['code']]); } return app_show(0,"获取成功",["list"=>$list,'count'=>$count]); } /*新建*/ public function create(){ $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :""; if($name==""){ return error_show(1002,"数据标题不能为空"); } $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find(); if (!empty($rename)) { return error_show(1002, "公司名称已存在"); } $code = rand(0000,9999); $str = sprintf("%04d",$code); $tr="GYS-".date("Ymd")."-".$str; $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :""; if($source==""){ return error_show(1002,"供应商来源不能为空"); } $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :""; if($type==""){ return error_show(1002,"申请类型不能为空"); } $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :""; if($area==""){ return error_show(1002,"大区不能为空"); } $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :""; if($city==""){ return error_show(1002,"城市不能为空"); } $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :""; if($nature==""){ return error_show(1002,"公司类型不能为空"); } $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0"; $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :""; if($ticket_type==""){ return error_show(1002,"回款方式不能为空"); } $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :""; if($legaler==""){ return error_show(1002,"法人不能为空"); } $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :""; if($addr==""){ return error_show(1002,"地址不能为空"); } $data=[ "name"=>$name, "source"=>$source, "code"=>$tr, "type"=>$type, "area"=>$area, "city"=>$city, "nature"=>$nature, "legaler"=>$legaler, "addr"=>$addr, "is_del"=>0, "ticket_type"=>$ticket_type, "addtime"=>date('Y-m-d H:i:s'), "updatetime"=>date("Y-m-d H:i:s"), "is_platform"=>$is_platform ]; $join = Db::name('supplier')->insert($data); $st = ["order_code"=>"GYS","status"=>0,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd($this->post['token'],$st,"role_share",0,$st); return $join? error_show(0,"添加成功") :error_show(1002,"添加失败"); } /*编辑*/ public function edit(){ $id = isset($this->post['id']) && $this->post['id'] !==""? trim($this->post['id']):""; $ion = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find(); if(empty($ion)){ return error_show(1004,"供应商不存在"); } $name = isset($this->post['name']) && $this->post['name']!=="" ? $this->post['name']:""; if($name==""){ return error_show(1002,'数据标题不能为空'); } $rename =Db::name('supplier')->where(['name'=>$name,'is_del'=>0])->where('id','<>',$id)->find(); if(!empty($rename)){ return error_show(1004,"数据标题已存在"); } $source = isset($this->post['source']) && $this->post['source'] !==""? $this->post['source']:""; if($source==""){ return error_show(1002,"供应商来源不能为空"); } $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :""; if($type==""){ return error_show(1002,"申请类型不能为空"); } $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :""; if($area==""){ return error_show(1002,"大区不能为空"); } $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :""; if($city==""){ return error_show(1002,"城市不能为空"); } $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :""; if($nature==""){ return error_show(1002,"公司类型不能为空"); } $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :""; if($legaler==""){ return error_show(1002,"法人不能为空"); } $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0"; $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :""; if($addr==""){ return error_show(1002,"地址不能为空"); } $vmp=[ "id"=>$id, "legaler"=>$legaler, "name"=>$name, "source"=>$source, "type"=>$type, "area"=>$area, "city"=>$city, "nature"=>$nature, "addr"=>$addr, "is_del"=>0, "is_platform"=>$is_platform, "addtime"=>date('Y-m-d H:i:s'), "updatetime"=>date("Y-m-d H:i:s") ]; $ed = Db::name('supplier')->where(['is_del'=>0,'id'=>$id])->save($vmp); $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$st,"GYS",0,$vmp); return $ed ? error_show(0,"编辑成功") : error_show(1002,"编辑失败"); } /*查询*/ public function selec(){ $id= isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :""; if($id==""){ return error_show(1002,"供应商不存在"); } $se = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find(); return app_show(0,"获取成功",$se); } /*删除*/ public function del(){ $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :""; $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find(); if($sup==false){ return error_show(1002,"供应商信息不存在"); } $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]); if($supp){ // $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"del"]; // ActionLog::logAdd($this->post['token'],$st,"GYS",0,$supp); return error_show(0,"供应商信息删除成功"); }else{ return error_show(1002,"供应商信息删除失败"); } } //公司汇总列表(供应商、客户和公司合并) public function comprehensiveList() { $post = $this->request->only(['companyNo' => '', 'name' => '', 'type' => '', 'page' => 1, 'size' => 10], 'post', 'trim'); $userCommon = \app\admin\common\User::getIns(); $rs = $userCommon->handle('hqList', [ 'code' => $post['companyNo'], 'name'=>$post['name'], 'type'=>$post['type'], 'page'=>$post['page'], 'size'=>$post['size'], 'level'=>$this->level, 'account_id'=>$this->uid ]); return json_show($rs['code'], $rs['message'],$rs['data']); } }