| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- /**
- * 极光推送
- */
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\facade\Db;
- use think\db\Query;
- class PushmessageController extends AdminbaseController {
- /*推送发送*/
- public function add(){
- return $this->fetch();
- }
- public function add_post(){
- $rs=array("code"=>0,"msg"=>"","info"=>array());
-
- $data = $this->request->param();
- $title=$data["title"];
- $synopsis=$data["synopsis"];
- $msg_type=$data["msg_type"];
- $content=$data["content"];
- $url=$data["url"];
- if($title==""){
- $rs['code']=1001;
- $rs['msg']="请填写标题";
- echo json_encode($rs);
- return;
- }
- if($synopsis==""){
- $rs['code']=1001;
- $rs['msg']="请填写简介";
- echo json_encode($rs);
- return;
- }
- if($msg_type==2&&$url==""){
- $rs['code']=1002;
- $rs['msg']="请填写链接地址";
- echo json_encode($rs);
- return;
- }
- $id=get_current_admin_id();
- $user=Db::name("user")
- ->where("id='{$id}'")
- ->find();
-
- $info=array("title"=>$title,"synopsis"=>$synopsis,"type"=>$msg_type,"content"=>htmlspecialchars_decode($content),"url"=>$url,"admin"=>$user['user_login'],"addtime"=>time(),"ip"=>$_SERVER['REMOTE_ADDR']);
- $result=Db::name("admin_push")
- ->insert($info);
- if($result!==false){
- $rs['info']['id']=$result;
- $rs['info']['count']=Db::name("user")->where("user_type=2 and user_status=1")->count();
- echo json_encode($rs);
- return;
- }else{
- $rs['code']=1002;
- $rs['msg']="推送失败";
- echo json_encode($rs);
- }
- }
- /*推送记录*/
- public function index(){
- $lists=Db::name("admin_push")
- ->where(function (Query $query) {
- $data = $this->request->param();
- $keyword=isset($data['keyword']) ? $data['keyword']: '';
- if (!empty($keyword)) {
- $query->where('title', 'like', "%$keyword%");
- }
- })
- ->order("addtime desc")
- ->paginate(20);
-
- //获取当前用户总数
- $count=Db::name("user")->where("user_type=2 and user_status=1")->count();
-
- // 获取分页显示
- $page = $lists->render();
- $this->assign('lists', $lists);
- $this->assign('page', $page);
- $this->assign("count", $count);
-
-
- return $this->fetch();
- }
- public function push(){
-
- $res=array("code"=>0,"msg"=>"","info"=>array());
- $data=$this->request->param();
- $id=$data['id'];
- if($id==""){
- $res['code']=1001;
- $res['msg']="数据传入失败";
- echo json_encode($res);
- return;
- }
- //判断id信息是否存在
- $info=Db::name("admin_push")->where("id={$id}")->find();
- if(!$info){
- $res['code']=1001;
- $res['msg']="推送数据不存在";
- echo json_encode($res);
- return;
- }
- txMessageTpns("官方通知",$info['title'],'all',0,[],json_encode(['type'=>3]));
- Db::name("admin_push")->where("id={$id}")->update(['is_push'=>1,'pushtime'=>time()]);
- echo json_encode($res);
-
- }
-
- public function del(){
- $id=$this->request->param("id");
- if($id==""){
- $this->error("数据传入失败");
- return;
- }
- $result=Db::name("admin_push")->where("id={$id}")->delete();
- if($result!==false){
- $this->success("删除成功");
- }else{
- $this->error("删除失败");
- }
- }
-
- }
|