Autocmd.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\exception\HttpResponseException;
  5. use app\admin\model\auto\Commands;
  6. use think\Log;
  7. /**
  8. * 首页接口
  9. */
  10. class Autocmd extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. }
  18. /**
  19. * 首页
  20. *
  21. */
  22. public function index()
  23. {
  24. try {
  25. $params = $this->request->get();
  26. $queryArr = explode(' ', $params['query'] ?? '');
  27. $data = [];
  28. if (empty($queryArr)) {
  29. $this->success('请求成功', $data);
  30. }
  31. $model = Commands::where('status', 1)->field('id,type_id,command,note,cmd_tags,weigh');
  32. foreach ($queryArr as &$value) {
  33. $word = addslashes(trim($value));
  34. // $model->where('CONCAT(type_id, command, note, cmd_tags) LIKE ' . "'%{$word}%'");
  35. $model->where('full_text', 'like', "%{$word}%");
  36. }
  37. // echo $model->buildSql();exit;
  38. $list = $model->select();
  39. foreach ($list as $item) {
  40. $data[] = $item['command'] . ' #' . $item['type_id'] . ':' . $item['note'];
  41. }
  42. $this->success('请求成功', $data);
  43. } catch (HttpResponseException $e) {
  44. throw $e;
  45. } catch (\Exception $e) {
  46. $this->error($e->getMessage());
  47. }
  48. }
  49. }