TopSearch.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. $where = [];
  49. $data = input();
  50. if(isset($data['module']) && $data['module'] != '0' && $data['module'] != ''){
  51. // var_dump($data['module']);die;
  52. $where['module'] = $data['module'];
  53. $most_num = 30;
  54. }else{
  55. $most_num = 60;
  56. }
  57. // if(isset($data['module'])){
  58. // $most_num = 30;
  59. // }else{
  60. // $most_num = 60;
  61. // }
  62. if(!isset($data['limit'])){
  63. $data['limit'] = 20;
  64. }
  65. if(!isset($data['page'])){
  66. $data['page'] = 1;
  67. }
  68. $total_num = (int)$data['limit'] * (int)$data['page'];
  69. $limit = 0;
  70. //// return $total_num.'-'.$most_num;
  71. // $page_num = $this->page_num;
  72. if($total_num > $most_num){
  73. $t_num = $total_num - $most_num;
  74. $l_num = $data['limit'] - $t_num;
  75. //$this->page_num = $l_num;
  76. $page_num = $l_num;
  77. $limit = $l_num;
  78. //$this->off_set = $l_num;
  79. // return $l_num;
  80. }
  81. $query = $this->_query($this->table)->where('is_deleted',0)->where($where);
  82. $query->like('title');
  83. $query->order('hot_num desc, sort desc,id desc')->page(true,true,$most_num,$limit);
  84. }
  85. /**
  86. * 数据列表处理
  87. * @auth true
  88. * @menu true
  89. * @param array $data
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. */
  94. protected function _index_page_filter(&$data)
  95. {
  96. }
  97. /**
  98. * 添加商品热搜
  99. * @auth true
  100. * @menu true
  101. * @throws \think\Exception
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @throws \think\exception\DbException
  105. * @throws \think\exception\PDOException
  106. */
  107. public function add()
  108. {
  109. $this->title = '添加';
  110. $this->_form($this->table, 'form');
  111. }
  112. /**
  113. * 编辑商品热搜
  114. * @auth true
  115. * @menu true
  116. * @throws \think\Exception
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. * @throws \think\exception\DbException
  120. * @throws \think\exception\PDOException
  121. */
  122. public function edit()
  123. {
  124. $this->title = '编辑';
  125. $this->_form($this->table, 'form');
  126. }
  127. /**
  128. * 表单数据处理
  129. * @auth true
  130. * @menu true
  131. * @param array $data
  132. */
  133. protected function _form_filter(&$data)
  134. {
  135. $data['create_at'] = date('Y-m-d H:i:s');
  136. $data['hot_time'] = date('Y-m-d H:i:s');
  137. $this->type_desc = $this->module;
  138. // var_dump($data);die;
  139. if($this->request->isPost()){
  140. // if(empty($data['module'])){
  141. // $this->error('请选择模块');
  142. // }
  143. }
  144. }
  145. /**
  146. * 启用
  147. * @auth true
  148. * @menu true
  149. * @throws \think\Exception
  150. * @throws \think\exception\PDOException
  151. */
  152. public function enable()
  153. {
  154. $this->_save($this->table, ['status' => 1]);
  155. }
  156. /**
  157. * 禁用
  158. * @auth true
  159. * @menu true
  160. * @throws \think\Exception
  161. * @throws \think\db\exception\DataNotFoundException
  162. * @throws \think\db\exception\ModelNotFoundException
  163. * @throws \think\exception\DbException
  164. * @throws \think\exception\PDOException
  165. */
  166. public function forbidden()
  167. {
  168. $this->_save($this->table, ['status' => '0']);
  169. }
  170. /**
  171. * 删除
  172. * @auth true
  173. * @menu true
  174. * @throws \think\Exception
  175. * @throws \think\exception\PDOException
  176. */
  177. public function del()
  178. {
  179. $this->_save($this->table, ['is_deleted' => 1]);
  180. }
  181. }