12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\exception\HttpResponseException;
- use app\admin\model\auto\Commands;
- use think\Log;
- /**
- * 首页接口
- */
- class Autocmd extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * 首页
- *
- */
- public function index()
- {
- try {
- $params = $this->request->get();
- $queryArr = explode(' ', $params['query'] ?? '');
- $data = [];
- if (empty($queryArr)) {
- $this->success('请求成功', $data);
- }
- $model = Commands::where('status', 1)->field('id,type_id,command,note,cmd_tags,weigh');
- foreach ($queryArr as &$value) {
- $word = addslashes(trim($value));
- // $model->where('CONCAT(type_id, command, note, cmd_tags) LIKE ' . "'%{$word}%'");
- $model->where('full_text', 'like', "%{$word}%");
- }
- // echo $model->buildSql();exit;
- $list = $model->select();
- foreach ($list as $item) {
- $data[] = $item['command'] . ' #' . $item['type_id'] . ':' . $item['note'];
- }
- $this->success('请求成功', $data);
- } catch (HttpResponseException $e) {
- throw $e;
- } catch (\Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|