1、修复栏目管理中的bug

2、增加路由规则管理
This commit is contained in:
2016-07-23 11:26:09 +08:00
parent 27891c868a
commit 75125bb298
7 changed files with 88 additions and 70 deletions

View File

@@ -48,8 +48,7 @@ class Category extends Admin{
//记录行为 //记录行为
action_log('update_category', 'category', $id, session('user_auth.uid')); action_log('update_category', 'category', $id, session('user_auth.uid'));
return $this->success('编辑成功!', url('index')); return $this->success('编辑成功!', url('index'));
} } else {
else {
$error = $category->getError(); $error = $category->getError();
return $this->error(empty($error) ? '未知错误!' : $error); return $this->error(empty($error) ? '未知错误!' : $error);
} }
@@ -81,8 +80,7 @@ class Category extends Admin{
if (false !== $id) { if (false !== $id) {
action_log('update_category', 'category', $id, session('user_auth.uid')); action_log('update_category', 'category', $id, session('user_auth.uid'));
return $this->success('新增成功!', url('index')); return $this->success('新增成功!', url('index'));
} } else {
else {
$error = $Category->getError(); $error = $Category->getError();
return $this->error(empty($error) ? '未知错误!' : $error); return $this->error(empty($error) ? '未知错误!' : $error);
} }
@@ -126,8 +124,7 @@ class Category extends Admin{
//记录行为 //记录行为
action_log('update_category', 'category', $id, session('user_auth.uid')); action_log('update_category', 'category', $id, session('user_auth.uid'));
return $this->success('删除分类成功!'); return $this->success('删除分类成功!');
} } else {
else {
return $this->error('删除分类失败!'); return $this->error('删除分类失败!');
} }
} }
@@ -137,18 +134,16 @@ class Category extends Admin{
* @param string $type * @param string $type
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
*/ */
public function operate($type = 'move') { public function operate($type = 'move', $from = '') {
//检查操作参数 //检查操作参数
if (strcmp($type, 'move') == 0) { if ($type == 'move') {
$operate = '移动'; $operate = '移动';
} } elseif ($type == 'merge') {
elseif (strcmp($type, 'merge') == 0) {
$operate = '合并'; $operate = '合并';
} } else {
else {
return $this->error('参数错误!'); return $this->error('参数错误!');
} }
$from = intval(input('get.from'));
if (empty($from)) { if (empty($from)) {
return $this->error('参数错误!'); return $this->error('参数错误!');
} }
@@ -156,7 +151,7 @@ class Category extends Admin{
$map = array('status' => 1, 'id' => array('neq', $from)); $map = array('status' => 1, 'id' => array('neq', $from));
$list = db('Category')->where($map)->field('id,pid,title')->select(); $list = db('Category')->where($map)->field('id,pid,title')->select();
//移动分类时增加移至根分类 //移动分类时增加移至根分类
if (strcmp($type, 'move') == 0) { if ($type == 'move') {
//不允许移动至其子孙分类 //不允许移动至其子孙分类
$list = tree_to_list(list_to_tree($list)); $list = tree_to_list(list_to_tree($list));
@@ -181,8 +176,7 @@ class Category extends Admin{
$res = db('Category')->where(array('id' => $from))->setField('pid', $to); $res = db('Category')->where(array('id' => $from))->setField('pid', $to);
if ($res !== false) { if ($res !== false) {
return $this->success('分类移动成功!', url('index')); return $this->success('分类移动成功!', url('index'));
} } else {
else {
return $this->error('分类移动失败!'); return $this->error('分类移动失败!');
} }
} }
@@ -207,7 +201,7 @@ class Category extends Admin{
$to_types = explode(',', $Model->getFieldById($to, 'type')); $to_types = explode(',', $Model->getFieldById($to, 'type'));
foreach ($from_types as $value) { foreach ($from_types as $value) {
if (!in_array($value, $to_types)) { if (!in_array($value, $to_types)) {
$types = config('DOCUMENT_MODEL_TYPE'); $types = config('document_model_type');
return $this->error('请给目标分类绑定文档类型:' . $types[$value]); return $this->error('请给目标分类绑定文档类型:' . $types[$value]);
} }
} }
@@ -218,22 +212,20 @@ class Category extends Admin{
//删除被合并的分类 //删除被合并的分类
$Model->delete($from); $Model->delete($from);
return $this->success('合并分类成功!', url('index')); return $this->success('合并分类成功!', url('index'));
} } else {
else {
return $this->error('合并分类失败!'); return $this->error('合并分类失败!');
} }
} }
public function status() { public function status() {
$id = input('id','','trim,intval'); $id = $this->getArrayParam('id');
$ids = input('post.ids/a',array(),'');
$status = input('status', '0', 'trim,intval'); $status = input('status', '0', 'trim,intval');
array_push($ids, $id);
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$ids); $map['id'] = array('IN', $id);
$result = db('Category')->where($map)->setField('status', $status); $result = db('Category')->where($map)->setField('status', $status);
if ($result) { if ($result) {
return $this->success("设置成功!"); return $this->success("设置成功!");

View File

@@ -104,7 +104,12 @@ class Seo extends Admin{
public function addrewrite(){ public function addrewrite(){
if (IS_POST) { if (IS_POST) {
# code... $result = model('Rewrite')->change();
if (false != $result) {
return $this->success("添加成功!", url('admin/seo/rewrite'));
}else{
return $this->error(model('Rewrite')->getError());
}
}else{ }else{
$data = array( $data = array(
'keyList' => $this->rewrite->keyList 'keyList' => $this->rewrite->keyList
@@ -117,7 +122,12 @@ class Seo extends Admin{
public function editrewrite(){ public function editrewrite(){
if (IS_POST) { if (IS_POST) {
# code... $result = model('Rewrite')->change();
if (false != $result) {
return $this->success("更新成功!", url('admin/seo/rewrite'));
}else{
return $this->error(model('Rewrite')->getError());
}
}else{ }else{
$id = input('id','','trim,intval'); $id = input('id','','trim,intval');
$info = db('Rewrite')->where(array('id'=>$id))->find(); $info = db('Rewrite')->where(array('id'=>$id))->find();

View File

@@ -25,6 +25,10 @@ class Base extends \think\Model{
*/ */
public function change(){ public function change(){
$data = \think\Request::instance()->post(); $data = \think\Request::instance()->post();
if (isset($data['id']) && $data['id']) {
return $this->save($data, array('id'=>$data['id'])); return $this->save($data, array('id'=>$data['id']));
}else{
return $this->save($data);
}
} }
} }

View File

@@ -18,7 +18,7 @@ class Document extends \think\model\Merge{
protected $fk = 'doc_id'; protected $fk = 'doc_id';
// 定义需要自动写入时间戳格式的字段 // 定义需要自动写入时间戳格式的字段
protected $autoTimeField = array('create_time','update_time','deadline'); protected $autoWriteTimestamp = array('create_time','update_time','deadline');
protected $auto = array('doc_id', 'title', 'description', 'update_time','deadline'); protected $auto = array('doc_id', 'title', 'description', 'update_time','deadline');
protected $insert = array('uid', 'attach'=>0, 'view'=>0, 'comment'=>0, 'extend'=>0, 'create_time', 'status'); protected $insert = array('uid', 'attach'=>0, 'view'=>0, 'comment'=>0, 'extend'=>0, 'create_time', 'status');

View File

@@ -14,8 +14,24 @@ namespace app\common\model;
*/ */
class Rewrite extends Base{ class Rewrite extends Base{
protected $autoWriteTimestamp = true;
public $keyList = array( public $keyList = array(
array('name'=>'id','title'=>'标识','type'=>'hidden'), array('name'=>'id','title'=>'标识','type'=>'hidden'),
array('name'=>'title','title'=>'规则名称','type'=>'text','option'=>'','help'=>'规则名称,方便记忆'), array('name'=>'rule','title'=>'规则名称','type'=>'text','option'=>'','help'=>'规则名称,方便记忆'),
array('name'=>'url','title'=>'规则地址','type'=>'text','option'=>'','help'=>'规则地址'),
); );
/**
* 数据修改
* @return [bool] [是否成功]
*/
public function change(){
$data = \think\Request::instance()->post();
if (isset($data['id']) && $data['id']) {
return $this->validate(true)->save($data, array('id'=>$data['id']));
}else{
return $this->validate(true)->save($data);
}
}
} }

View File

@@ -12,21 +12,16 @@ namespace app\common\validate;
/** /**
* 设置模型 * 设置模型
*/ */
class Book extends \think\Validate{ class Rewrite extends Base{
protected $rule = array( protected $rule = array(
'book_name' => 'require', 'rule' => 'require|unique:Rewrite',
'stand_class' => 'require', 'url' => 'require'
); );
protected $message = array( protected $message = array(
'book_name' => '书名称必须!', 'rule.require' => '规则必须!',
'stand_class' => '图书标准类型必须', 'rule.unique' => '规则已存在',
); 'url.require' => '路由地址标题必须!',
protected $scene = array(
'add' => array('book_name', 'stand_class'),
'edit' => array('book_name', 'stand_class')
); );
} }

View File

@@ -1309,6 +1309,7 @@ INSERT INTO `sent_menu` VALUES ('22', '广告管理', 'admin', 'cc', '5', '0', '
INSERT INTO `sent_menu` VALUES ('23', '插件列表', 'admin', 'usb', '6', '0', 'admin/addons/index', '0', '', '插件管理', '0', '0'); INSERT INTO `sent_menu` VALUES ('23', '插件列表', 'admin', 'usb', '6', '0', 'admin/addons/index', '0', '', '插件管理', '0', '0');
INSERT INTO `sent_menu` VALUES ('24', '钩子列表', 'admin', 'code', '6', '0', 'admin/addons/hooks', '0', '', '插件管理', '0', '0'); INSERT INTO `sent_menu` VALUES ('24', '钩子列表', 'admin', 'code', '6', '0', 'admin/addons/hooks', '0', '', '插件管理', '0', '0');
INSERT INTO `sent_menu` VALUES ('25', '自定义表单', 'admin', '', '5', '0', 'admin/form/index', '0', '', '运营管理', '0', '0'); INSERT INTO `sent_menu` VALUES ('25', '自定义表单', 'admin', '', '5', '0', 'admin/form/index', '0', '', '运营管理', '0', '0');
INSERT INTO `sent_menu` VALUES ('26', '伪静态规则', 'admin', '', '2', '0', 'admin/seo/rewrite', '0', '', '优化设置', '0', '0');
-- ----------------------------- -- -----------------------------
-- Table structure for `sent_model` -- Table structure for `sent_model`