123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- class Supplier extends Base
- {
-
- //该控制器,除了comprehensiveList方法之外,其他对供应商维护的接口都没用,对供应商维护的接口在Suppler控制器中
- /*列表*/
- public function list(){
- $param = $this->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']);
- }
- }
|