// +---------------------------------------------------------------------- namespace app\controller\admin; use app\model\SeoRule; use app\model\Rewrite; /** * @title SEO管理 */ class Seo extends Base { /** * @title SEO列表 */ public function index($page = 1, $r = 20) { $map = []; //读取规则列表 $map[] = ['status', '>=', 0]; $list = SeoRule::where($map)->order('sort asc')->paginate($this->request->pageConfig); $this->data = [ 'list' => $list, 'page' => $list->render(), ]; return $this->fetch(); } /** * @title 添加SEO */ public function add() { if ($this->request->isPost()) { $data = $this->request->post(); $result = $this->seo->save($data); if ($result) { return $this->success("添加成功!"); } else { return $this->error("添加失败!"); } } else { $data = array( 'keyList' => $this->seo->keyList, ); $this->assign($data); $this->setMeta("添加规则"); return $this->fetch('public/edit'); } } /** * @title 编辑SEO */ public function edit($id = null) { if ($this->request->isPost()) { $data = $this->request->post(); $result = $this->seo->save($data, array('id' => $data['id'])); if (false !== $result) { return $this->success("修改成功!"); } else { return $this->error("修改失败!"); } } else { $id = input('id', '', 'trim,intval'); $info = $this->seo->where(array('id' => $id))->find(); $data = array( 'info' => $info, 'keyList' => $this->seo->keyList, ); $this->assign($data); $this->setMeta("编辑规则"); return $this->fetch('public/edit'); } } /** * @title 删除SEO */ public function del() { $id = $this->getArrayParam('id'); if (empty($id)) { return $this->error("非法操作!"); } $result = $this->seo->where(array('id' => array('IN', $id)))->delete(); if ($result) { return $this->success("删除成功!"); } else { return $this->error("删除失败!"); } } /** * @title 伪静态列表 */ public function rewrite() { $map = []; $list = Rewrite::where($map)->paginate($this->request->pageConfig); $this->data = [ 'list' => $list, 'page' => $list->render(), ]; return $this->fetch(); } /** * @title 添加静态规则 */ public function addrewrite() { if ($this->request->isPost()) { $result = model('Rewrite')->change(); if (false != $result) { return $this->success("添加成功!", url('admin/seo/rewrite')); } else { return $this->error(model('Rewrite')->getError()); } } else { $data = array( 'keyList' => $this->rewrite->keyList, ); $this->assign($data); $this->setMeta("添加路由规则"); return $this->fetch('public/edit'); } } /** * @title 编辑静态规则 */ public function editrewrite() { if ($this->request->isPost()) { $result = model('Rewrite')->change(); if (false != $result) { return $this->success("更新成功!", url('admin/seo/rewrite')); } else { return $this->error(model('Rewrite')->getError()); } } else { $id = input('id', '', 'trim,intval'); $info = db('Rewrite')->where(array('id' => $id))->find(); $data = array( 'info' => $info, 'keyList' => $this->rewrite->keyList, ); $this->assign($data); $this->setMeta("编辑路由规则"); return $this->fetch('public/edit'); } } /** * @title 删除静态规则 */ public function delrewrite() { $id = $this->getArrayParam('id'); if (empty($id)) { return $this->error("非法操作!"); } $result = db('Rewrite')->where(array('id' => array('IN', $id)))->delete(); if ($result) { return $this->success("删除成功!"); } else { return $this->error("删除失败!"); } } }