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("删除失败"); } } }