TopSearch.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\nutrition\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 商品热搜管理
  7. * Class TopSearch
  8. * @package app\mall\controller
  9. */
  10. class TopSearch extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'TopSearch';
  17. protected $module;
  18. function initialize()
  19. {
  20. $this->module = array(
  21. 0 => '请选择',
  22. 'video'=>'视频',
  23. 'article'=>'图文',
  24. 'datum'=>'资料',
  25. 'press'=>'新闻',
  26. 'demand'=>'需求',
  27. 'forum'=>'问答',
  28. 'goods'=>'商品',
  29. 'activity'=>'活动',
  30. 'recruit'=>'招聘',
  31. 'supplier_goods'=>'供应商产品',
  32. );
  33. }
  34. /**
  35. * 商品热搜列表
  36. * @auth true
  37. * @menu true
  38. * @throws \think\Exception
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. * @throws \think\exception\PDOException
  43. */
  44. public function index()
  45. {
  46. $this->title = '热搜列表';
  47. $this->type_desc = $this->module;
  48. $query = $this->_query($this->table)->where('is_deleted',0);
  49. $query->like('title');
  50. $query->order('hot_num desc, sort desc,id desc')->page();
  51. }
  52. /**
  53. * 数据列表处理
  54. * @auth true
  55. * @menu true
  56. * @param array $data
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @throws \think\exception\DbException
  60. */
  61. protected function _index_page_filter(&$data)
  62. {
  63. }
  64. /**
  65. * 添加商品热搜
  66. * @auth true
  67. * @menu true
  68. * @throws \think\Exception
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. * @throws \think\exception\DbException
  72. * @throws \think\exception\PDOException
  73. */
  74. public function add()
  75. {
  76. $this->title = '添加';
  77. $this->_form($this->table, 'form');
  78. }
  79. /**
  80. * 编辑商品热搜
  81. * @auth true
  82. * @menu true
  83. * @throws \think\Exception
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * @throws \think\exception\DbException
  87. * @throws \think\exception\PDOException
  88. */
  89. public function edit()
  90. {
  91. $this->title = '编辑';
  92. $this->_form($this->table, 'form');
  93. }
  94. /**
  95. * 表单数据处理
  96. * @auth true
  97. * @menu true
  98. * @param array $data
  99. */
  100. protected function _form_filter(&$data)
  101. {
  102. $data['create_at'] = date('Y-m-d H:i:s');
  103. $this->type_desc = $this->module;
  104. if($this->request->isPost()){
  105. if(empty($data['module'])){
  106. $this->error('请选择模块');
  107. }
  108. }
  109. }
  110. /**
  111. * 启用
  112. * @auth true
  113. * @menu true
  114. * @throws \think\Exception
  115. * @throws \think\exception\PDOException
  116. */
  117. public function enable()
  118. {
  119. $this->_save($this->table, ['status' => 1]);
  120. }
  121. /**
  122. * 禁用
  123. * @auth true
  124. * @menu true
  125. * @throws \think\Exception
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. * @throws \think\exception\PDOException
  130. */
  131. public function forbidden()
  132. {
  133. $this->_save($this->table, ['status' => '0']);
  134. }
  135. /**
  136. * 删除
  137. * @auth true
  138. * @menu true
  139. * @throws \think\Exception
  140. * @throws \think\exception\PDOException
  141. */
  142. public function del()
  143. {
  144. $this->_save($this->table, ['is_deleted' => 1]);
  145. }
  146. }