Storelist.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Storelist extends BaseMall {
  22. public function initialize() {
  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. $class_list = rkcache('storeclass', true, 'file');
  32. $cate_id = intval(input('param.cate_id'));
  33. if (!key_exists($cate_id, $class_list))
  34. $cate_id = 0;
  35. View::assign('class_list', $class_list);
  36. //店铺搜索
  37. $condition = array();
  38. $keyword = trim(input('param.keyword'));
  39. if ($keyword != '') {
  40. $condition[] = array('store_name|store_mainbusiness', 'like', '%' . $keyword . '%');
  41. }
  42. $user_name = trim(input('param.user_name'));
  43. if ($user_name != '') {
  44. $condition[] = array('member_name', '=', $user_name);
  45. }
  46. $area_info = trim(input('param.area_info'));
  47. if (!empty($area_info)) {
  48. //修复店铺按地区搜索
  49. $tabs = preg_split("#\s+#", $area_info, -1, PREG_SPLIT_NO_EMPTY);
  50. $len = count($tabs);
  51. $area_name = $tabs[$len - 1];
  52. if ($area_name) {
  53. $area_name = trim($area_name);
  54. $condition[] = array('area_info', 'like', '%' . $area_name . '%');
  55. }
  56. }
  57. if ($cate_id > 0) {
  58. $condition[] = array('storeclass_id', '=', $cate_id);
  59. }
  60. $condition[] = array('store_state', '=', 1);
  61. $order = trim(input('param.order'));
  62. if (!in_array($order, array('desc', 'asc'))) {
  63. unset($order);
  64. }
  65. $order_sort = 'store_sort asc';
  66. $store_model = model('store');
  67. $store_list = $store_model->getStoreList($condition, 10, $order_sort);
  68. //获取店铺商品数,推荐商品列表等信息
  69. $store_list = $store_model->getStoreSearchList($store_list);
  70. //信用度排序
  71. $key = trim(input('param.key'));
  72. if ($key == 'store_credit') {
  73. if ($order == 'desc') {
  74. $store_list = sortClass::sortArrayDesc($store_list, 'store_credit_average');
  75. } else {
  76. $store_list = sortClass::sortArrayAsc($store_list, 'store_credit_average');
  77. }
  78. } else if ($key == 'store_sales') {//销量排行
  79. if ($order == 'desc') {
  80. $store_list = sortClass::sortArrayDesc($store_list, 'num_sales_jq');
  81. } else {
  82. $store_list = sortClass::sortArrayAsc($store_list, 'num_sales_jq');
  83. }
  84. }
  85. View::assign('store_list', $store_list);
  86. View::assign('show_page', $store_model->page_info->render());
  87. // 页面输出
  88. View::assign('index_sign', 'store_list');
  89. //当前位置
  90. if (intval($cate_id) > 0) {
  91. $nav_link[1]['link'] = (string) url('Search/index');
  92. $nav_link[1]['title'] = lang('site_search_store');
  93. $nav = $class_list[$cate_id];
  94. //存入当前级
  95. $nav_link[] = array(
  96. 'title' => $nav['storeclass_name']
  97. );
  98. } else {
  99. $nav_link[1]['link'] = 'index.html';
  100. $nav_link[1]['title'] = lang('homepage');
  101. $nav_link[2]['title'] = lang('site_search_store');
  102. }
  103. View::assign('nav_link_list', $nav_link);
  104. $purl = input('param.');
  105. unset($purl['page']);
  106. View::assign('purl', url('home/' . request()->controller() . '/' . request()->action(), $purl));
  107. //SEO
  108. $seo = model('seo')->type('index')->show();
  109. $this->_assign_seo($seo);
  110. View::assign('html_title', (input('param.keyword') ? input('param.keyword') . ' - ' : '' ) . config('ds_config.site_name') . lang('ds_common_search'));
  111. return View::fetch($this->template_dir . 'store_list');
  112. }
  113. //获取店铺列表要显示的信息
  114. public function storelistinfo_bak($storeinfo) {
  115. foreach ($storeinfo as $value) {
  116. $map['store_id'] = $value['store_id'];
  117. $goods_count['count'] = Db::name('goods')->where($map)->count();
  118. $goods_count['info'] = Db::name('goods')->where('goods_commend', '1')->field('goods_id,goods_name,goods_image,goods_marketprice')->select()->toArray();
  119. $v['store_goodscount'] = $goods_count['count'];
  120. $v['store_goodscommend'] = $goods_count['info'];
  121. $info = array_merge($value, $v);
  122. $store_info[$value['store_id']] = $info;
  123. }
  124. return $store_info;
  125. }
  126. }
  127. class sortClass {
  128. //升序
  129. public static function sortArrayAsc($preData, $sortType = 'store_sort') {
  130. $sortData = array();
  131. foreach ($preData as $key_i => $value_i) {
  132. $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0;
  133. $min_key = '';
  134. $sort_total = count($sortData);
  135. foreach ($sortData as $key_j => $value_j) {
  136. $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0;
  137. if ($price_i < $value_j[$sortType]) {
  138. $min_key = $key_j + 1;
  139. break;
  140. }
  141. }
  142. if (empty($min_key)) {
  143. array_push($sortData, $value_i);
  144. } else {
  145. $sortData1 = array_slice($sortData, 0, $min_key - 1);
  146. array_push($sortData1, $value_i);
  147. if (($min_key - 1) < $sort_total) {
  148. $sortData2 = array_slice($sortData, $min_key - 1);
  149. foreach ($sortData2 as $value) {
  150. array_push($sortData1, $value);
  151. }
  152. }
  153. $sortData = $sortData1;
  154. }
  155. }
  156. return $sortData;
  157. }
  158. //降序
  159. public static function sortArrayDesc($preData, $sortType = 'store_sort') {
  160. $sortData = array();
  161. foreach ($preData as $key_i => $value_i) {
  162. $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0;
  163. $min_key = '';
  164. $sort_total = count($sortData);
  165. foreach ($sortData as $key_j => $value_j) {
  166. $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0;
  167. if ($price_i > $value_j[$sortType]) {
  168. $min_key = $key_j + 1;
  169. break;
  170. }
  171. }
  172. if (empty($min_key)) {
  173. array_push($sortData, $value_i);
  174. } else {
  175. $sortData1 = array_slice($sortData, 0, $min_key - 1);
  176. array_push($sortData1, $value_i);
  177. if (($min_key - 1) < $sort_total) {
  178. $sortData2 = array_slice($sortData, $min_key - 1);
  179. foreach ($sortData2 as $value) {
  180. array_push($sortData1, $value);
  181. }
  182. }
  183. $sortData = $sortData1;
  184. }
  185. }
  186. return $sortData;
  187. }
  188. }