Search.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\home\controller;
  14. use think\Db;
  15. class Search extends Base
  16. {
  17. private $searchword_db;
  18. public function _initialize() {
  19. parent::_initialize();
  20. $this->searchword_db = Db::name('search_word');
  21. }
  22. /**
  23. * 搜索主页
  24. */
  25. public function index()
  26. {
  27. return $this->lists();
  28. }
  29. /**
  30. * 搜索列表
  31. */
  32. public function lists()
  33. {
  34. $param = input('param.');
  35. /*记录搜索词*/
  36. $word = $this->request->param('keywords');
  37. $page = $this->request->param('page');
  38. if(!empty($word) && 2 > $page)
  39. {
  40. $nowTime = getTime();
  41. $row = $this->searchword_db->field('id')->where(['word'=>$word, 'lang'=>$this->home_lang])->find();
  42. if(empty($row))
  43. {
  44. $this->searchword_db->insert([
  45. 'word' => $word,
  46. 'sort_order' => 100,
  47. 'lang' => $this->home_lang,
  48. 'add_time' => $nowTime,
  49. 'update_time' => $nowTime,
  50. ]);
  51. }else{
  52. $this->searchword_db->where(['id'=>$row['id']])->update([
  53. 'searchNum' => Db::raw('searchNum+1'),
  54. 'update_time' => $nowTime,
  55. ]);
  56. }
  57. }
  58. /*--end*/
  59. $result = $param;
  60. $eyou = array(
  61. 'field' => $result,
  62. );
  63. $this->eyou = array_merge($this->eyou, $eyou);
  64. $this->assign('eyou', $this->eyou);
  65. /*模板文件*/
  66. $viewfile = 'lists_search';
  67. /*--end*/
  68. /*多语言内置模板文件名*/
  69. if (!empty($this->home_lang)) {
  70. $viewfilepath = TEMPLATE_PATH.$this->theme_style.DS.$viewfile."_{$this->home_lang}.".$this->view_suffix;
  71. if (file_exists($viewfilepath)) {
  72. $viewfile .= "_{$this->home_lang}";
  73. }
  74. }
  75. /*--end*/
  76. return $this->fetch(":{$viewfile}");
  77. }
  78. }