123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace app\modules\admin\controllers;
- use app\common\controllers\BController;
- use app\models\BadWord;
- use app\modules\admin\models\Config;
- use Yii;
- class BadwordController extends BController
- {
- public $layout = 'main';
- public function actionList()
- {
- $query = BadWord::find();
- if (Yii::$app->request->isAjax) {
- $data = [];
- $params = Yii::$app->request->get('BadWord',[]);
- $query = mergeParams($query,$params);
- $countQuery = clone $query;
- //分页
- if(isset($_GET['limit'])){ $query->limit(intval($_GET['limit']));}
- if(isset($_GET['offset'])){ $query->offset(intval($_GET['offset']));}
- //排序
- if(isset($_GET['sort'])&&isset($_GET['sortOrder']))
- {
- $resultList = $query->orderBy([$_GET['sort']=>($_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC)])->all();
- }
- else
- {
- $resultList = $query->orderBy(['id'=>SORT_ASC])->all();
- }
- foreach($resultList as $result)
- {
- $data[] = array('id'=>$result->id,'bad_word'=>$result->bad_word,'type'=>BadWord::typeOptions($result->type),'replace_word'=>$result->replace_word,'list_order'=>$result->list_order,'create_time'=>get_date($result->create_time,'Y-m-d H:i'));
- }
- $result = ["total"=>$countQuery->count(),"totalNotFiltered"=>$countQuery->count(),"rows"=>$data];
- echo_json($result);
- }
- $this->tableTitle = array(
- array('field'=>'id','checkbox'=>false,'formatter'=>'checkboxFormatter','class'=>'col-md-1'),
- array('field'=>'bad_word','title'=>BadWord::getAttributeName('bad_word'),'align'=>'center','class'=>'col-md-2'),
- array('field'=>'type','title'=>BadWord::getAttributeName('type'),'align'=>'center','class'=>'col-md-2'),
- array('field'=>'replace_word','title'=>BadWord::getAttributeName('replace_word'),'align'=>'center','class'=>'col-md-2'),
- array('field'=>'list_order','title'=>BadWord::getAttributeName('list_order'),'align'=>'center','sortable'=>true,'formatter'=>'editFormatter','class'=>'col-md-1'),
- array('field'=>'create_time','title'=>BadWord::getAttributeName('create_time'),'align'=>'center','sortable'=>true,'class'=>'col-md-2'),
- array('field'=>'operate','title'=>BadWord::getAttributeName('operate'),'align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter','class'=>'col-md-2'),
- );
- $this->tableConfig = array('table'=>BadWord::shortTableName(),'url'=>$this->createRealUrl(['admin/badword/list']),'setFieldUrl'=>$this->createRealUrl(['admin/badword/setfield']),'idField'=>BadWord::modelPrimaryKey(),'checkbox'=>1,'dropmenu'=>1,'pagination'=>true,'pagesize'=>20,'refresh'=>true);
- return $this->render('list',array('model'=>new BadWord()));
- }
- //添加
- function actionAdd()
- {
- $model = new BadWord();
- if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){
- $exist = BadWord::find()->where("bad_word='".$model->bad_word."' and type=".$model->type)->exists();
- if($exist)
- {
- $msgdata = ['error' => 1,'msg' => '已存在该敏感词,添加失败'];
- echo_json($msgdata);
- }
- $model->create_time = TIMESTAMP;
- if(!$model->validate())
- {
- $msgdata = ['error' => 1,'msg' => $model->returnFirstError()];
- }
- else
- {
- if($model->save())
- {
- $msgdata = ['error' => 0,'msg' => '操作成功'];
- }
- else
- {
- $msgdata = ['error' => 1,'msg' => '操作失败'];
- }
- }
- echo_json($msgdata);
- }
- return $this->renderAjax('add',array('model'=>$model));
- }
- //批量删除
- public function actionMultidelete()
- {
- $ids = Yii::$app->request->get('ids');
- if(!empty($ids))
- {
- BadWord::deleteAll("id in(".$ids.")");
- $msgdata = ['error' => 0,'msg' => '操作成功'];
- }
- else
- {
- $msgdata = ['error' => 1,'msg' => '请选择操作记录'];
- }
- echo_json($msgdata);
- }
- //删除
- public function actionDel()
- {
- $id = $this->getKeyId();
- $model = BadWord::findOne($id);
- check_record_exists($model);
- if($model->delete())
- {
- $msgdata = ['error' => 0,'msg' => '操作成功!'];
- }
- else
- {
- $msgdata = ['error' => 1,'msg' => '操作失败!'];
- }
- echo_json($msgdata);
- }
- //配置
- function actionConfig()
- {
- $configModel = Config::find()->where("name='badword'")->limit(1)->one();
- check_record_exists($configModel);
- $config = string2array($configModel->value);
- $post = Yii::$app->request->post();
- if(Yii::$app->request->isAjax&&!empty($post)){
- $post['open_pc'] = $post['open_pc']?$post['open_pc']:0;
- $post['open_wap'] = $post['open_wap']?$post['open_wap']:0;
- $post['open_spider'] = $post['open_spider']?$post['open_spider']:0;
- $post['open'] = $post['open']?$post['open']:0;
- $configModel->value = array2string($post);
- if($configModel->save())
- {
- $msgdata = ['error' => 0,'msg' => '操作成功'];
- }
- else
- {
- $msgdata = ['error' => 1,'msg' => '操作失败'];
- }
- echo_json($msgdata);
- }
- return $this->renderAjax('config',array('config'=>$config));
- }
- }
|