added 新增规则组的支持,完善SQL文件

This commit is contained in:
zhaoxiang 2016-12-02 01:59:34 +08:00
parent d2dd21aa82
commit 0d67858183
3 changed files with 345 additions and 0 deletions

View File

@ -8,8 +8,324 @@
namespace app\admin\controller;
use app\admin\model\Filter;
class FilterManager extends Base {
public function index(){
$data = Filter::all();
$table = [
'tempType' => 'table',
'header' => [
[
'field' => 'name',
'info' => '规则组名称'
],
[
'field' => 'month',
'info' => '次/月'
],
[
'field' => 'day',
'info' => '次/日'
],
[
'field' => 'hour',
'info' => '次/时'
],
[
'field' => 'minute',
'info' => '次/分'
],
[
'field' => 'second',
'info' => '次/秒'
],
[
'field' => 'status',
'info' => '状态'
]
],
'topButton' => [
[
'href' => 'FilterManager/add',
'class'=> 'btn-success',
'info'=> '新增',
'icon' => 'fa fa-plus',
'confirm' => 0,
]
],
'rightButton' => [
[
'info' => '启用',
'href' => 'FilterManager/open',
'class'=> 'btn-success ajax-put-url',
'param'=> [$this->primaryKey],
'icon' => 'fa fa-check',
'confirm' => 1,
'show' => ['status', 0]
],
[
'info' => '禁用',
'href' => 'FilterManager/close',
'class'=> 'btn-warning ajax-put-url',
'param'=> [$this->primaryKey],
'icon' => 'fa fa-close',
'confirm' => 1,
'show' => ['status', 1]
],
[
'info' => '编辑',
'href' => 'FilterManager/edit',
'class'=> 'btn-primary',
'param'=> [$this->primaryKey],
'icon' => 'fa fa-pencil',
'confirm' => 0,
'show' => ''
],
[
'info' => '删除',
'href' => 'FilterManager/del',
'class'=> 'btn-danger ajax-delete',
'param'=> [$this->primaryKey],
'icon' => 'fa fa-trash',
'confirm' => 1,
]
],
'typeRule' => [
'status' => [
'module' => 'label',
'rule' => [
[
'info' => '禁用',
'class' => 'label label-danger'
],
[
'info' => '启用',
'class' => 'label label-success'
]
]
]
],
'data' => $data
];
$table = $this->_prepareTemplate($table);
$this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS);
}
public function add(){
if( $this->request->isPost() ){
$userModel = new Filter();
$result = $userModel->allowField(true)->save($this->request->post());
if(false === $result){
$this->error($userModel->getError());
}else{
$this->success('操作成功!', url('FilterManager/index'));
}
}else{
$form = [
'formTitle' => $this->menuInfo['name'].'【请注意规则的合理性】',
'tempType' => 'add',
'formAttr' => [
'target' => url('FilterManager/add'),
'formId' => 'add-FilterManager-form',
'backUrl' => url('FilterManager/index'),
],
'formList' => [
[
'module' => 'text',
'description' => '',
'info' => '规则组名称',
'attr' => [
'name' => 'name',
'value' => '',
'placeholder' => ''
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每月请求频率:',
'attr' => [
'name' => 'month',
'value' => '-1',
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每日请求频率:',
'attr' => [
'name' => 'day',
'value' => '-1',
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每小时请求频率:',
'attr' => [
'name' => 'hour',
'value' => '-1',
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每分钟请求频率:',
'attr' => [
'name' => 'minute',
'value' => '-1',
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每秒请求频率:',
'attr' => [
'name' => 'second',
'value' => '-1',
'placeholder' => '-1'
]
]
]
];
$this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS);
}
}
public function del(){
if( $this->request->isDelete() ){
$key = $this->request->delete($this->primaryKey);
$delNum = Filter::destroy($key);
if( $delNum ){
$this->success('操作成功!', url('FilterManager/index'));
}
}
$this->error('操作失败!');
}
public function edit(){
if( $this->request->isPut() ){
$data = $this->request->put();
$keysModel = new Filter();
$keysModel->allowField(true)->update($data);
$this->success('操作成功!', url('FilterManager/index'));
}else{
$detail = Filter::get($this->request->get($this->primaryKey))->toArray();
$form = [
'formTitle' => $this->menuInfo['name'],
'tempType' => 'edit',
'formAttr' => [
'target' => url('FilterManager/edit'),
'formId' => 'edit-FilterManager-form',
'backUrl' => url('FilterManager/index'),
],
'formList' => [
[
'module' => 'hidden',
'description' => '',
'info' => '',
'attr' => [
'name' => $this->primaryKey,
'value' => $detail[$this->primaryKey],
'placeholder' => ''
]
],
[
'module' => 'text',
'description' => '',
'info' => '规则组名称',
'attr' => [
'name' => 'name',
'value' => $detail['name'],
'placeholder' => ''
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每月请求频率:',
'attr' => [
'name' => 'month',
'value' => $detail['month'],
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每日请求频率:',
'attr' => [
'name' => 'day',
'value' => $detail['day'],
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每小时请求频率:',
'attr' => [
'name' => 'hour',
'value' => $detail['hour'],
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每分钟请求频率:',
'attr' => [
'name' => 'minute',
'value' => $detail['minute'],
'placeholder' => '-1'
]
],
[
'module' => 'text',
'description' => '请填写整数,-1表示不限制',
'info' => '每秒请求频率:',
'attr' => [
'name' => 'second',
'value' => $detail['second'],
'placeholder' => '-1'
]
]
]
];
$this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS);
}
}
public function open(){
if( $this->request->isPut() ){
$id = $this->request->put($this->primaryKey);
$keysObj = Filter::get([$this->primaryKey => $id]);
if( is_null($keysObj) ){
$this->error('当前规则组不存在','');
}else{
$keysObj->status = 1;
$keysObj->save();
$this->success('操作成功', url('FilterManager/index'));
}
}
}
public function close(){
if( $this->request->isPut() ){
$id = $this->request->put($this->primaryKey);
$keysObj = Filter::get([$this->primaryKey => $id]);
if( is_null($keysObj) ){
$this->error('当前规则组不存在','');
}else{
$keysObj->status = 0;
$keysObj->save();
$this->success('操作成功', url('FilterManager/index'));
}
}
}
}

View File

@ -0,0 +1,12 @@
<?php
/**
* @since 2016-12-01
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace app\admin\model;
class Filter extends Base {
}

View File

@ -203,6 +203,23 @@ CREATE TABLE `app_member` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用管理员表';
# Dump of table filter
# ------------------------------------------------------------
DROP TABLE IF EXISTS `filter`;
CREATE TABLE `filter` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`total` int(11) NOT NULL DEFAULT '0' COMMENT '请求总数',
`month` int(11) NOT NULL DEFAULT '0' COMMENT '每月请求频率',
`day` int(11) NOT NULL DEFAULT '0' COMMENT '每天请求频率',
`hour` int(11) NOT NULL DEFAULT '0' COMMENT '每小时请求频率',
`minute` int(11) NOT NULL DEFAULT '0' COMMENT '每分钟请求频率',
`second` int(11) NOT NULL DEFAULT '0' COMMENT '没秒钟请求频率',
`name` varchar(50) NOT NULL DEFAULT '' COMMENT '过滤组名称',
`status` tinyint(2) NOT NULL DEFAULT '1' COMMENT '过滤组状态',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Api过滤组配置';
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;