WechatPush.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\bug\controller;
  3. use think\App;use think\facade\Validate;
  4. class WechatPush extends Base{
  5. public function __construct(App $app) {
  6. parent::__construct($app);
  7. $this->model = new \app\bug\model\WechatSetPush();
  8. }
  9. public function create(){
  10. $post = $this->request->param([
  11. "push_name"=>"",
  12. "belong"=>"",
  13. "template_info"=>"",
  14. "push_user_info"=>""
  15. ],"post","trim");
  16. $valid=Validate::rule([
  17. "push_name|推送名称"=>"require|max:255",
  18. "belong|推送对象"=>"require|number|egt:0",
  19. "template_info|模板信息"=>"require|array",
  20. "push_user_info|推送用户"=>"require|array"
  21. ]);
  22. if($valid->check($post)==false) return error($valid->getError());
  23. $data=[
  24. "push_name"=>$post['push_name'],
  25. "belong"=>$post['belong'],
  26. "template_id"=>$post['template_info']['template_id'],
  27. "template_name"=>$post['template_info']['template_name'],
  28. "template_content"=>$post['template_info']['content'],
  29. "push_user_info"=>$post['push_user_info'],
  30. "status"=>0,
  31. ];
  32. $this->model->save($data);
  33. return success('添加成功');
  34. }
  35. public function save(){
  36. $post = $this->request->param([
  37. "id"=>"",
  38. "push_name"=>"",
  39. "belong"=>"",
  40. "template_info"=>"",
  41. "push_user_info"=>""
  42. ],"post","trim");
  43. $valid=Validate::rule([
  44. "id|推送ID"=>"require|number|egt:0",
  45. "push_name|推送名称"=>"require|max:255",
  46. "belong|推送对象"=>"require|number|egt:0",
  47. "template_info|模板信息"=>"require|array",
  48. "push_user_info|推送用户"=>"require|array"]);
  49. if($valid->check($post)==false) return error($valid->getError());
  50. $info=$this->model->findOrEmpty($post['id']);
  51. if($info->isEmpty())return error('推送信息不存在');
  52. $data=[
  53. "push_name"=>$post['push_name'],
  54. "belong"=>$post['belong'],
  55. "template_id"=>$post['template_info']['template_id'],
  56. "template_name"=>$post['template_info']['template_name'],
  57. "template_content"=>$post['template_info']['content'],
  58. "push_user_info"=>$post['push_user_info'],
  59. "status"=>0,
  60. ];
  61. $info->save($data);
  62. return success('修改成功');
  63. }
  64. public function status(){
  65. $post = $this->request->param([
  66. "id"=>"",
  67. "status"=>"",
  68. ],"post","trim");
  69. $valid=Validate::rule([
  70. "id|推送ID"=>"require|number|egt:0",
  71. "status|状态"=>"require|number|egt:0",
  72. ]);
  73. if($valid->check($post)==false) return error($valid->getError());
  74. $info=$this->model->findOrEmpty($post['id']);
  75. if($info->isEmpty())return error('推送信息不存在');
  76. $info->save(['status'=>$post['status']]);
  77. return success('修改成功');
  78. }
  79. public function getList(){
  80. $post = $this->request->param([
  81. "page"=>1,
  82. "size"=>15,
  83. "push_name"=>"",
  84. "belong"=>"",
  85. ],"post","trim");
  86. $where=[];
  87. if($post['push_name']!=""){
  88. $where[]=['push_name','like','%'.$post['push_name'].'%'];
  89. }
  90. if($post['belong']!=""){
  91. $where[]=['belong','=',$post['belong']];
  92. }
  93. $data = $this->model->where($where)->paginate(['list_rows'=>$post['size'],'page'=>$post['page']]);
  94. return success('获取成功',["list"=>$data->items(),"count"=>$data->total()]);
  95. }
  96. }