0) { $condition[] = array('storeclass_id', '=', $cate_id); } $condition[] = array('store_state', '=', 1); $order = trim(input('param.order')); if (!in_array($order, array('desc', 'asc'))) { unset($order); } $order_sort = 'store_sort asc'; $store_model = model('store'); $store_list = $store_model->getStoreList($condition, 10, $order_sort); //获取店铺商品数,推荐商品列表等信息 $store_list = $store_model->getStoreSearchList($store_list); //信用度排序 $key = trim(input('param.key')); if ($key == 'store_credit') { if ($order == 'desc') { $store_list = sortClass::sortArrayDesc($store_list, 'store_credit_average'); } else { $store_list = sortClass::sortArrayAsc($store_list, 'store_credit_average'); } } else if ($key == 'store_sales') {//销量排行 if ($order == 'desc') { $store_list = sortClass::sortArrayDesc($store_list, 'num_sales_jq'); } else { $store_list = sortClass::sortArrayAsc($store_list, 'num_sales_jq'); } } View::assign('store_list', $store_list); View::assign('show_page', $store_model->page_info->render()); // 页面输出 View::assign('index_sign', 'store_list'); //当前位置 if (intval($cate_id) > 0) { $nav_link[1]['link'] = (string) url('Search/index'); $nav_link[1]['title'] = lang('site_search_store'); $nav = $class_list[$cate_id]; //存入当前级 $nav_link[] = array( 'title' => $nav['storeclass_name'] ); } else { $nav_link[1]['link'] = 'index.html'; $nav_link[1]['title'] = lang('homepage'); $nav_link[2]['title'] = lang('site_search_store'); } View::assign('nav_link_list', $nav_link); $purl = input('param.'); unset($purl['page']); View::assign('purl', url('home/' . request()->controller() . '/' . request()->action(), $purl)); //SEO $seo = model('seo')->type('index')->show(); $this->_assign_seo($seo); View::assign('html_title', (input('param.keyword') ? input('param.keyword') . ' - ' : '' ) . config('ds_config.site_name') . lang('ds_common_search')); return View::fetch($this->template_dir . 'store_list'); } //获取店铺列表要显示的信息 public function storelistinfo_bak($storeinfo) { foreach ($storeinfo as $value) { $map['store_id'] = $value['store_id']; $goods_count['count'] = Db::name('goods')->where($map)->count(); $goods_count['info'] = Db::name('goods')->where('goods_commend', '1')->field('goods_id,goods_name,goods_image,goods_marketprice')->select()->toArray(); $v['store_goodscount'] = $goods_count['count']; $v['store_goodscommend'] = $goods_count['info']; $info = array_merge($value, $v); $store_info[$value['store_id']] = $info; } return $store_info; } } class sortClass { //升序 public static function sortArrayAsc($preData, $sortType = 'store_sort') { $sortData = array(); foreach ($preData as $key_i => $value_i) { $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0; $min_key = ''; $sort_total = count($sortData); foreach ($sortData as $key_j => $value_j) { $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0; if ($price_i < $value_j[$sortType]) { $min_key = $key_j + 1; break; } } if (empty($min_key)) { array_push($sortData, $value_i); } else { $sortData1 = array_slice($sortData, 0, $min_key - 1); array_push($sortData1, $value_i); if (($min_key - 1) < $sort_total) { $sortData2 = array_slice($sortData, $min_key - 1); foreach ($sortData2 as $value) { array_push($sortData1, $value); } } $sortData = $sortData1; } } return $sortData; } //降序 public static function sortArrayDesc($preData, $sortType = 'store_sort') { $sortData = array(); foreach ($preData as $key_i => $value_i) { $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0; $min_key = ''; $sort_total = count($sortData); foreach ($sortData as $key_j => $value_j) { $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0; if ($price_i > $value_j[$sortType]) { $min_key = $key_j + 1; break; } } if (empty($min_key)) { array_push($sortData, $value_i); } else { $sortData1 = array_slice($sortData, 0, $min_key - 1); array_push($sortData1, $value_i); if (($min_key - 1) < $sort_total) { $sortData2 = array_slice($sortData, $min_key - 1); foreach ($sortData2 as $value) { array_push($sortData1, $value); } } $sortData = $sortData1; } } return $sortData; } }