12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\admin\controller\clientmanage\search;
- use app\common\controller\Backend;
- use think\Controller;
- use think\Request;
- /**
- * 热门搜索词
- *
- * @icon fa fa-circle-o
- */
- class Keyword extends Backend
- {
- /**
- * SearchKeyword模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('ClientSearchKeyword');
- $this->view->assign("sexList", $this->model->getSexList());
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- public function add()
- {
- if ($this->request->isAjax()) {
- $ids = $this->request->get('ids');
- $row = model('Book')->field('id,name,sex')->where('id', 'in', $ids)->select();
- $params = [];
- $i =0;
- foreach ($row as $value) {
- $keywordexists = [];
- $keywordexists = model('ClientSearchKeyword')->get(['keyword' => $value['name']]);
- if(empty($keywordexists)){
- $params[$i]['keyword'] = $value['name'];
- $params[$i]['book_id'] = $value['id'];
- $params[$i]['sex'] = $value['sex'];
- $i = $i+1;
- }
- }
- model('ClientSearchKeyword')->saveAll($params);
- $this->success('添加成功' .json_encode($ids));
- }
- $this->error("非Ajax请求");
- return $this->view->fetch();
- }
- }
|