123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use think\App;
- use think\Error;use think\Exception;use think\facade\Validate;
- use think\Request;
- use think\facade\Db;
- class Pay extends Base
- {
- public function __construct(App $app) {
- parent::__construct($app);
- }
- /**
- * 显示资源列表
- */
- public function list()
- {
- $param =$this->request->param(["status"=>"","pay_name"=>"","page"=>1,"size"=>10],"post","trim");
- $where=[];
- if($param['pay_name']!='') $where[]=["pay_name","like","%{$param['pay_name']}%"];
- if($param['status']!='') $where[]=["status","=",$param['status']];
- $count =Db::name("pay")->where($where)->count();
- $total =ceil($count/$param['size']);
- $page = $total>=$param['page']? intval($param['page']) : intval($total);
- $list =Db::name("pay")->where($where)->page($page,intval($param['size']))
- ->order("id desc")->select()->toArray();
- return app_show(0,"获取成功",["list"=>$list,'count'=>$count]);
- }
- /**pay_rate 数据
- * ['companyNo'=>'GYS','companyName'=>'供应商']
- * [] 业务公司+销售平台
- * ['companyNo'=>'KH','companyName'=>'客户']
- *
- * @return \think\Response
- */
- public function create()
- {
- $param = $this->request->only(["pay_name"=>"","pay_rate"=>[]],"post");
- $valid = Validate::rule([
- "pay_name|名称"=>"require|max:255|min:2",
- "pay_rate|内容"=>"require|array",
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $isT =Db::name("pay")->where("pay_name",$param['pay_name'])->findOrEmpty();
- if(!empty($isT)) return error_show(1004,"名称已存在");
- Db::startTrans();
- try{
- $data=[
- "pay_name"=>$param['pay_name'],
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "status"=>1
- ];
- $payadd =Db::name("pay")->insertGetId($data);
- if($payadd==false) throw new Exception('新建失败');
- $payinfo=[];
- foreach ($param['pay_rate'] as $key=>$item){
- $temp=[];
- $temp['pay_id'] = $payadd;
- $temp['companyNo'] = $item['companyNo'];
- $temp['companyName'] = $item['companyName'];
- $temp['rate'] = $item['rate']??0;
- $temp['is_cgd'] = $item['is_cgd']??0;
- $temp['is_qrd'] = $item['is_qrd']??0;
- $temp['weight'] = $key;
- $temp['status'] = 1;
- $payinfo[]=$temp;
- }
- $payin = Db::name("pay_rate")->insertAll($payinfo);
- if($payin==false) throw new Exception('新建失败');
- Db::commit();
- return app_show(0,"新建成功");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- /**
- * 保存新建的资
- */
- public function save()
- {
- $param = $this->request->only(["id"=>"","pay_name"=>"","pay_rate"=>[]],"post");
- $valid = Validate::rule([
- "pay_name|名称"=>"require|max:255|min:2",
- "pay_rate|内容"=>"require|array",
- "id|主键ID"=>"require|number",
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $isT =Db::name("pay")->where("id",$param['id'])->findOrEmpty();
- if(empty($isT)) return error_show(1004,"未找到数据");
- $isT =Db::name("pay")->where([["id","<>",$param['id']],["pay_name","=",$param['pay_name']]])->findOrEmpty();
- if(!empty($isT)) return error_show(1004,"名称已存在");
- Db::startTrans();
- try{
- $data=[
- "id"=>$param['id'],
- "pay_name"=>$param['pay_name'],
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $payadd =Db::name("pay")->save($data);
- if($payadd==false) throw new Exception('更新失败');
- foreach ($param['pay_rate'] as $key=>$item){
- $temp=[];
- $temp['pay_id'] = $param['id'];
- $temp['id'] = $item['id']??null;
- $temp['companyNo'] = $item['companyNo'];
- $temp['companyName'] = $item['companyName'];
- $temp['rate'] = $item['rate']??0;
- $temp['is_cgd'] = $item['is_cgd']??0;
- $temp['is_qrd'] = $item['is_qrd']??0;
- $temp['weight'] = $key;
- $temp['status'] = $item['status']??1;
- $temp['is_del'] =$item['is_del']??0;
- $temp['updatetime'] =date("Y-m-d H:i:s");
- $payin = Db::name("pay_rate")->save($temp);
- if($payin==false) throw new Exception('更新失败');
- }
- Db::commit();
- return app_show(0,"更新成功");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- /**
- * 显示指定的资源
- *
- */
- public function info()
- {
- $param =$this->request->only(["id"=>''],"post","trim");
- $valid= Validate::rule(["id|主键ID"=>"require|number" ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $isT =Db::name("pay")->where("id",$param['id'])->findOrEmpty();
- if(empty($isT)) return error_show(1004,"未找到数据");
- $info =Db::name("pay_rate")->where(["pay_id"=>$param['id'],"is_del"=>0])->order("weight asc,id desc")->select()->toArray();
- $isT["pay_rate"] = $info;
- return app_show(0,"获取成功",$isT);
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function status()
- {
- $param =$this->request->only(["id"=>'',"status"=>""],"post","trim");
- $valid= Validate::rule([
- "id|主键ID"=>"require|number",
- "status|状态"=>"require|number|in:0,1",
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $isT =Db::name("pay")->where("id",$param['id'])->findOrEmpty();
- if(empty($isT)) return error_show(1004,"未找到数据");
- if($isT['status']==$param['status']) return error_show(1004,"状态已更新");
- $isT['status'] = $param['status'];
- $isT['updatetime'] =date("Y-m-d H:i:s");
- $upT =Db::name("pay")->save($isT);
- return $upT? app_show(0,"状态更新成功"):error_show(1004,"状态更新失败");
- }
- public function query(){
- $param =$this->request->only(["status"=>""],"post","trim");
- $where=[];
- if($param['status']!=="") $where[]=["status","=",$param['status']];
- $list =Db::name("pay")->where($where)->select()->toArray();
- return app_show(0,"获取成功",$list);
- }
- }
|