56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use think\exception\HttpResponseException;
|
|
use app\common\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());
|
|
}
|
|
}
|
|
}
|