'/index.php/Admin/Template/addnews', //添加编辑新闻 'newsinfo' => '/index.php/Admin/Template/newsinfo', //查看新闻详情 'delUser' => '/index.php/Admin/Template/delUser', //删除新闻 ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } public function addnews() { $id = I('get.id'); if (!empty($id)) { $newsInfo = M('retail_news') ->where(array('id' => $id)) ->find(); $this->assign('newsinfo', $newsInfo); } $this->display(); } // 删除新闻 public function delUser() { $id = I('post.id'); $list = M("retail_news")->where(array('id' => $id))->delete(); if ($list) { $res['status'] = 1; $res['msg'] = "删除成功"; } else { $res['status'] = 0; $res['msg'] = "删除失败"; } $this->ajaxReturn($res); } /** * 获取表单数据 */ public function getData() { $user = session('admin_userinfo'); $news['pid'] = $user['pid']; $list = M("retail_news") ->where($news) ->page($_POST['page'], $_POST['limit']) ->order('time desc') ->select(); $count = count(M("retail_news")->where($news)->select()); foreach ($list as $k => &$val) { $val['index'] = round(($_POST['page'] - 1) * $_POST['limit'] + $k + 1); } $res['code'] = 0; $res['msg'] = ''; $res['data'] = $list; $res['count'] = $count; $this->ajaxReturn($res); } //查看新闻内容 public function newsinfo() { $id = I('get.id'); $content = M('retail_news')->where(array('id' => $id))->getField('content'); $content = htmlspecialchars_decode($content); $this->assign('content', $content); $this->display(); } public function toAddNews() { $user = session('admin_userinfo'); if (!empty($user)) { $id = I('post.id'); if ($id) { $old = M('retail_news')->where(array('id' => $id))->find(); if (empty($old)) { $res['status'] = 0; $res['msg'] = '访问有误'; $this->ajaxReturn($res); } } $image = I('post.image'); if (!$image) { $res['status'] = 0; $res['msg'] = "请选择图片"; $this->ajaxReturn($res); } $data['image'] = $image; $data['title'] = I('post.title'); $data['docuat'] = I('post.docuat'); $data['content'] = htmlspecialchars_decode(I('post.content')); $data['time'] = time(); $data['pid'] = $user['pid']; if (!empty($id)) { $list = M('retail_news')->where(array('id' => $id))->save($data); } else { $list = M("retail_news")->add($data); } if ($list) { $res['status'] = 1; $res['msg'] = "操作成功"; } else { $res['status'] = 0; $res['msg'] = "操作失败"; } } else { $res['status'] = 0; $res['msg'] = '登录超时'; } $this->ajaxReturn($res); } }