Pay.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;
  5. use think\Error;use think\Exception;use think\facade\Validate;
  6. use think\Request;
  7. use think\facade\Db;
  8. class Pay extends Base
  9. {
  10. public function __construct(App $app) {
  11. parent::__construct($app);
  12. }
  13. /**
  14. * 显示资源列表
  15. */
  16. public function list()
  17. {
  18. $param =$this->request->param(["status"=>"","pay_name"=>"","page"=>1,"size"=>10],"post","trim");
  19. $where=[];
  20. if($param['pay_name']!='') $where[]=["pay_name","like","%{$param['pay_name']}%"];
  21. if($param['status']!='') $where[]=["status","=",$param['status']];
  22. $count =Db::name("pay")->where($where)->count();
  23. $total =ceil($count/$param['size']);
  24. $page = $total>=$param['page']? intval($param['page']) : intval($total);
  25. $list =Db::name("pay")->where($where)->page($page,intval($param['size']))
  26. ->order("id desc")->select()->toArray();
  27. return app_show(0,"获取成功",["list"=>$list,'count'=>$count]);
  28. }
  29. /**pay_rate 数据
  30. * ['companyNo'=>'GYS','companyName'=>'供应商']
  31. * [] 业务公司+销售平台
  32. * ['companyNo'=>'KH','companyName'=>'客户']
  33. *
  34. * @return \think\Response
  35. */
  36. public function create()
  37. {
  38. $param = $this->request->only(["pay_name"=>"","pay_rate"=>[]],"post");
  39. $valid = Validate::rule([
  40. "pay_name|名称"=>"require|max:255|min:2",
  41. "pay_rate|内容"=>"require|array",
  42. ]);
  43. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  44. $isT =Db::name("pay")->where("pay_name",$param['pay_name'])->findOrEmpty();
  45. if(!empty($isT)) return error_show(1004,"名称已存在");
  46. Db::startTrans();
  47. try{
  48. $data=[
  49. "pay_name"=>$param['pay_name'],
  50. "apply_id"=>$this->uid,
  51. "apply_name"=>$this->uname,
  52. "status"=>1
  53. ];
  54. $payadd =Db::name("pay")->insertGetId($data);
  55. if($payadd==false) throw new Exception('新建失败');
  56. $payinfo=[];
  57. foreach ($param['pay_rate'] as $key=>$item){
  58. $temp=[];
  59. $temp['pay_id'] = $payadd;
  60. $temp['companyNo'] = $item['companyNo'];
  61. $temp['companyName'] = $item['companyName'];
  62. $temp['rate'] = $item['rate']??0;
  63. $temp['is_cgd'] = $item['is_cgd']??0;
  64. $temp['is_qrd'] = $item['is_qrd']??0;
  65. $temp['weight'] = $key;
  66. $temp['status'] = 1;
  67. $payinfo[]=$temp;
  68. }
  69. $payin = Db::name("pay_rate")->insertAll($payinfo);
  70. if($payin==false) throw new Exception('新建失败');
  71. Db::commit();
  72. return app_show(0,"新建成功");
  73. }catch (\Exception $e){
  74. Db::rollback();
  75. return error_show(1005,$e->getMessage());
  76. }
  77. }
  78. /**
  79. * 保存新建的资
  80. */
  81. public function save()
  82. {
  83. $param = $this->request->only(["id"=>"","pay_name"=>"","pay_rate"=>[]],"post");
  84. $valid = Validate::rule([
  85. "pay_name|名称"=>"require|max:255|min:2",
  86. "pay_rate|内容"=>"require|array",
  87. "id|主键ID"=>"require|number",
  88. ]);
  89. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  90. $isT =Db::name("pay")->where("id",$param['id'])->findOrEmpty();
  91. if(empty($isT)) return error_show(1004,"未找到数据");
  92. $isT =Db::name("pay")->where([["id","<>",$param['id']],["pay_name","=",$param['pay_name']]])->findOrEmpty();
  93. if(!empty($isT)) return error_show(1004,"名称已存在");
  94. Db::startTrans();
  95. try{
  96. $data=[
  97. "id"=>$param['id'],
  98. "pay_name"=>$param['pay_name'],
  99. "updatetime"=>date("Y-m-d H:i:s")
  100. ];
  101. $payadd =Db::name("pay")->save($data);
  102. if($payadd==false) throw new Exception('更新失败');
  103. foreach ($param['pay_rate'] as $key=>$item){
  104. $temp=[];
  105. $temp['pay_id'] = $param['id'];
  106. $temp['id'] = $item['id']??null;
  107. $temp['companyNo'] = $item['companyNo'];
  108. $temp['companyName'] = $item['companyName'];
  109. $temp['rate'] = $item['rate']??0;
  110. $temp['is_cgd'] = $item['is_cgd']??0;
  111. $temp['is_qrd'] = $item['is_qrd']??0;
  112. $temp['weight'] = $key;
  113. $temp['status'] = $item['status']??1;
  114. $temp['is_del'] =$item['is_del']??0;
  115. $temp['updatetime'] =date("Y-m-d H:i:s");
  116. $payin = Db::name("pay_rate")->save($temp);
  117. if($payin==false) throw new Exception('更新失败');
  118. }
  119. Db::commit();
  120. return app_show(0,"更新成功");
  121. }catch (\Exception $e){
  122. Db::rollback();
  123. return error_show(1005,$e->getMessage());
  124. }
  125. }
  126. /**
  127. * 显示指定的资源
  128. *
  129. */
  130. public function info()
  131. {
  132. $param =$this->request->only(["id"=>''],"post","trim");
  133. $valid= Validate::rule(["id|主键ID"=>"require|number" ]);
  134. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  135. $isT =Db::name("pay")->where("id",$param['id'])->findOrEmpty();
  136. if(empty($isT)) return error_show(1004,"未找到数据");
  137. $info =Db::name("pay_rate")->where(["pay_id"=>$param['id'],"is_del"=>0])->order("weight asc,id desc")->select()->toArray();
  138. $isT["pay_rate"] = $info;
  139. return app_show(0,"获取成功",$isT);
  140. }
  141. /**
  142. * 显示编辑资源表单页.
  143. *
  144. * @param int $id
  145. * @return \think\Response
  146. */
  147. public function status()
  148. {
  149. $param =$this->request->only(["id"=>'',"status"=>""],"post","trim");
  150. $valid= Validate::rule([
  151. "id|主键ID"=>"require|number",
  152. "status|状态"=>"require|number|in:0,1",
  153. ]);
  154. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  155. $isT =Db::name("pay")->where("id",$param['id'])->findOrEmpty();
  156. if(empty($isT)) return error_show(1004,"未找到数据");
  157. if($isT['status']==$param['status']) return error_show(1004,"状态已更新");
  158. $isT['status'] = $param['status'];
  159. $isT['updatetime'] =date("Y-m-d H:i:s");
  160. $upT =Db::name("pay")->save($isT);
  161. return $upT? app_show(0,"状态更新成功"):error_show(1004,"状态更新失败");
  162. }
  163. public function query(){
  164. $param =$this->request->only(["status"=>""],"post","trim");
  165. $where=[];
  166. if($param['status']!=="") $where[]=["status","=",$param['status']];
  167. $list =Db::name("pay")->where($where)->select()->toArray();
  168. return app_show(0,"获取成功",$list);
  169. }
  170. }