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