123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\bug\controller;
- use think\App;use think\facade\Validate;
- class WechatPush extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model = new \app\bug\model\WechatSetPush();
- }
- public function create(){
- $post = $this->request->param([
- "push_name"=>"",
- "belong"=>"",
- "template_info"=>"",
- "push_user_info"=>""
- ],"post","trim");
- $valid=Validate::rule([
- "push_name|推送名称"=>"require|max:255",
- "belong|推送对象"=>"require|number|egt:0",
- "template_info|模板信息"=>"require|array",
- "push_user_info|推送用户"=>"require|array"
- ]);
- if($valid->check($post)==false) return error($valid->getError());
- $data=[
- "push_name"=>$post['push_name'],
- "belong"=>$post['belong'],
- "template_id"=>$post['template_info']['template_id'],
- "template_name"=>$post['template_info']['template_name'],
- "template_content"=>$post['template_info']['content'],
- "push_user_info"=>$post['push_user_info'],
- "status"=>0,
- ];
- $this->model->save($data);
- return success('添加成功');
- }
- public function save(){
- $post = $this->request->param([
- "id"=>"",
- "push_name"=>"",
- "belong"=>"",
- "template_info"=>"",
- "push_user_info"=>""
- ],"post","trim");
- $valid=Validate::rule([
- "id|推送ID"=>"require|number|egt:0",
- "push_name|推送名称"=>"require|max:255",
- "belong|推送对象"=>"require|number|egt:0",
- "template_info|模板信息"=>"require|array",
- "push_user_info|推送用户"=>"require|array"]);
- if($valid->check($post)==false) return error($valid->getError());
- $info=$this->model->findOrEmpty($post['id']);
- if($info->isEmpty())return error('推送信息不存在');
- $data=[
- "push_name"=>$post['push_name'],
- "belong"=>$post['belong'],
- "template_id"=>$post['template_info']['template_id'],
- "template_name"=>$post['template_info']['template_name'],
- "template_content"=>$post['template_info']['content'],
- "push_user_info"=>$post['push_user_info'],
- "status"=>0,
- ];
- $info->save($data);
- return success('修改成功');
- }
- public function status(){
- $post = $this->request->param([
- "id"=>"",
- "status"=>"",
- ],"post","trim");
- $valid=Validate::rule([
- "id|推送ID"=>"require|number|egt:0",
- "status|状态"=>"require|number|egt:0",
- ]);
- if($valid->check($post)==false) return error($valid->getError());
- $info=$this->model->findOrEmpty($post['id']);
- if($info->isEmpty())return error('推送信息不存在');
- $info->save(['status'=>$post['status']]);
- return success('修改成功');
- }
- public function getList(){
- $post = $this->request->param([
- "page"=>1,
- "size"=>15,
- "push_name"=>"",
- "belong"=>"",
- ],"post","trim");
- $where=[];
- if($post['push_name']!=""){
- $where[]=['push_name','like','%'.$post['push_name'].'%'];
- }
- if($post['belong']!=""){
- $where[]=['belong','=',$post['belong']];
- }
- $data = $this->model->where($where)->paginate(['list_rows'=>$post['size'],'page'=>$post['page']]);
- return success('获取成功',["list"=>$data->items(),"count"=>$data->total()]);
- }
- }
|