Storelist.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /*
  3. * 店铺列表控制器
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. *
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Storelist extends BaseMall
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/storelist.lang.php');
  25. }
  26. /**
  27. * 店铺列表
  28. */
  29. public function index()
  30. {
  31. //店铺类目快速搜索
  32. $class_list = rkcache('storeclass', true, 'file');
  33. $cate_id = intval(input('param.cate_id'));
  34. if (!key_exists($cate_id, $class_list))
  35. $cate_id = 0;
  36. View::assign('class_list', $class_list);
  37. //店铺搜索
  38. $condition = array();
  39. $keyword = trim(input('param.keyword'));
  40. if ($keyword != '') {
  41. $condition[] = array('store_name|store_mainbusiness', 'like', '%' . $keyword . '%');
  42. }
  43. $user_name = trim(input('param.user_name'));
  44. if ($user_name != '') {
  45. $condition[] = array('member_name', '=', $user_name);
  46. }
  47. $area_info = trim(input('param.area_info'));
  48. if (!empty($area_info)) {
  49. //修复店铺按地区搜索
  50. $tabs = preg_split("#\s+#", $area_info, -1, PREG_SPLIT_NO_EMPTY);
  51. $len = count($tabs);
  52. $area_name = $tabs[$len - 1];
  53. if ($area_name) {
  54. $area_name = trim($area_name);
  55. $condition[] = array('area_info', 'like', '%' . $area_name . '%');
  56. }
  57. }
  58. if ($cate_id > 0) {
  59. $condition[] = array('storeclass_id', '=', $cate_id);
  60. }
  61. $condition[] = array('store_state', '=', 1);
  62. $order = trim(input('param.order'));
  63. if (!in_array($order, array('desc', 'asc'))) {
  64. unset($order);
  65. }
  66. $order_sort = 'store_sort asc';
  67. $store_model = model('store');
  68. $store_list = $store_model->getStoreList($condition, 10, $order_sort);
  69. //获取店铺商品数,推荐商品列表等信息
  70. $store_list = $store_model->getStoreSearchList($store_list);
  71. //信用度排序
  72. $key = trim(input('param.key'));
  73. if ($key == 'store_credit') {
  74. if ($order == 'desc') {
  75. $store_list = sortClass::sortArrayDesc($store_list, 'store_credit_average');
  76. } else {
  77. $store_list = sortClass::sortArrayAsc($store_list, 'store_credit_average');
  78. }
  79. } else if ($key == 'store_sales') { //销量排行
  80. if ($order == 'desc') {
  81. $store_list = sortClass::sortArrayDesc($store_list, 'num_sales_jq');
  82. } else {
  83. $store_list = sortClass::sortArrayAsc($store_list, 'num_sales_jq');
  84. }
  85. }
  86. View::assign('store_list', $store_list);
  87. View::assign('show_page', $store_model->page_info->render());
  88. // 页面输出
  89. View::assign('index_sign', 'store_list');
  90. //当前位置
  91. if (intval($cate_id) > 0) {
  92. $nav_link[1]['link'] = (string) url('Search/index');
  93. $nav_link[1]['title'] = lang('site_search_store');
  94. $nav = $class_list[$cate_id];
  95. //存入当前级
  96. $nav_link[] = array(
  97. 'title' => $nav['storeclass_name']
  98. );
  99. } else {
  100. $nav_link[1]['link'] = 'index.html';
  101. $nav_link[1]['title'] = lang('homepage');
  102. $nav_link[2]['title'] = lang('site_search_store');
  103. }
  104. View::assign('nav_link_list', $nav_link);
  105. $purl = input('param.');
  106. unset($purl['page']);
  107. View::assign('purl', url('home/' . request()->controller() . '/' . request()->action(), $purl));
  108. //SEO
  109. $seo = model('seo')->type('index')->show();
  110. $this->_assign_seo($seo);
  111. View::assign('html_title', (input('param.keyword') ? input('param.keyword') . ' - ' : '') . config('ds_config.site_name') . lang('ds_common_search'));
  112. return View::fetch($this->template_dir . 'store_list');
  113. }
  114. //获取店铺列表要显示的信息
  115. public function storelistinfo_bak($storeinfo)
  116. {
  117. foreach ($storeinfo as $value) {
  118. $map['store_id'] = $value['store_id'];
  119. $goods_count['count'] = Db::name('goods')->where($map)->count();
  120. $goods_count['info'] = Db::name('goods')->where('goods_commend', '1')->field('goods_id,goods_name,goods_image,goods_marketprice')->select()->toArray();
  121. $v['store_goodscount'] = $goods_count['count'];
  122. $v['store_goodscommend'] = $goods_count['info'];
  123. $info = array_merge($value, $v);
  124. $store_info[$value['store_id']] = $info;
  125. }
  126. return $store_info;
  127. }
  128. }
  129. class sortClass
  130. {
  131. //升序
  132. public static function sortArrayAsc($preData, $sortType = 'store_sort')
  133. {
  134. $sortData = array();
  135. foreach ($preData as $key_i => $value_i) {
  136. $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0;
  137. $min_key = '';
  138. $sort_total = count($sortData);
  139. foreach ($sortData as $key_j => $value_j) {
  140. $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0;
  141. if ($price_i < $value_j[$sortType]) {
  142. $min_key = $key_j + 1;
  143. break;
  144. }
  145. }
  146. if (empty($min_key)) {
  147. array_push($sortData, $value_i);
  148. } else {
  149. $sortData1 = array_slice($sortData, 0, $min_key - 1);
  150. array_push($sortData1, $value_i);
  151. if (($min_key - 1) < $sort_total) {
  152. $sortData2 = array_slice($sortData, $min_key - 1);
  153. foreach ($sortData2 as $value) {
  154. array_push($sortData1, $value);
  155. }
  156. }
  157. $sortData = $sortData1;
  158. }
  159. }
  160. return $sortData;
  161. }
  162. //降序
  163. public static function sortArrayDesc($preData, $sortType = 'store_sort')
  164. {
  165. $sortData = array();
  166. foreach ($preData as $key_i => $value_i) {
  167. $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0;
  168. $min_key = '';
  169. $sort_total = count($sortData);
  170. foreach ($sortData as $key_j => $value_j) {
  171. $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0;
  172. if ($price_i > $value_j[$sortType]) {
  173. $min_key = $key_j + 1;
  174. break;
  175. }
  176. }
  177. if (empty($min_key)) {
  178. array_push($sortData, $value_i);
  179. } else {
  180. $sortData1 = array_slice($sortData, 0, $min_key - 1);
  181. array_push($sortData1, $value_i);
  182. if (($min_key - 1) < $sort_total) {
  183. $sortData2 = array_slice($sortData, $min_key - 1);
  184. foreach ($sortData2 as $value) {
  185. array_push($sortData1, $value);
  186. }
  187. }
  188. $sortData = $sortData1;
  189. }
  190. }
  191. return $sortData;
  192. }
  193. }