function index() { // 查询参数 $param = $this->_get_query_param(); if (empty($param)) { header('Location: index.php?app=category'); exit; } /* 筛选条件 */ $this->assign('filters', $this->_get_filter($param)); /* 按分类、品牌、地区、价格区间统计商品数量 */ $stats = $this->_get_group_by_info($param, ENABLE_SEARCH_CACHE); $this->assign('categories', $stats['by_category']); $this->assign('category_count', count($stats['by_category'])); $this->assign('brands', $stats['by_brand']); $this->assign('brand_count', count($stats['by_brand'])); $this->assign('price_intervals', $stats['by_price']); $this->assign('regions', $stats['by_region']); $this->assign('region_count', count($stats['by_region'])); /* 排序 */ $orders = $this->_get_orders(); $this->assign('orders', $orders); /* 分页信息 */ $page = $this->_get_page(NUM_PER_PAGE); $page['item_count'] = $stats['total_count']; $this->_format_page($page); $this->assign('page_info', $page); /* 商品列表 */ $sgrade_mod =& m('sgrade'); $sgrades = $sgrade_mod->get_options(); $conditions = $this->_get_goods_conditions($param); $goods_mod =& m('goods'); $goods_list = $goods_mod->get_list(array('conditions' => $conditions, 'order' => isset($_GET['order']) && isset($orders[$_GET['order']]) ? $_GET['order'] : '', 'limit' => $page['limit'])); foreach ($goods_list as $key => $goods) { $step = intval(Conf::get('upgrade_required')); $step < 1 && ($step = 5); $store_mod =& m('store'); $goods_list[$key]['credit_image'] = $this->_view->res_base . '/images/' . $store_mod->compute_credit($goods['credit_value'], $step); empty($goods['default_image']) && ($goods_list[$key]['default_image'] = Conf::get('default_goods_image')); $goods_list[$key]['grade_name'] = $sgrades[$goods['sgrade']]; } $this->assign('goods_list', $goods_list); /* 商品展示方式 */ $display_mode = ecm_getcookie('goodsDisplayMode'); if (empty($display_mode) || !in_array($display_mode, array('list', 'squares'))) { $display_mode = 'squares'; // 默认格子方式 } $this->assign('display_mode', $display_mode); /* 取得导航 */ $this->assign('navs', $this->_get_navs()); /* 当前位置 */ $cate_id = isset($param['cate_id']) ? $param['cate_id'] : 0; $this->_curlocal($this->_get_goods_curlocal($cate_id)); /*列表页热卖推荐商品 By psmb*/ $this->assign('hot_sales_list', $this->_get_hot_sales_list($cate_id)); /*end*/ $this->assign('page_title', Conf::get('site_title')); $this->display('search.goods.html'); }
function _get_goods_history($id, $num = 9) { $goods_list = array(); $goods_ids = ecm_getcookie('goodsBrowseHistory'); $goods_ids = $goods_ids ? explode(',', $goods_ids) : array(); if ($goods_ids) { $rows = $this->_goods_mod->find(array('conditions' => $goods_ids, 'fields' => 'goods_name,default_image')); foreach ($goods_ids as $goods_id) { if (isset($rows[$goods_id])) { empty($rows[$goods_id]['default_image']) && ($rows[$goods_id]['default_image'] = Conf::get('default_goods_image')); $goods_list[] = $rows[$goods_id]; } } } $goods_ids[] = $id; if (count($goods_ids) > $num) { unset($goods_ids[0]); } ecm_setcookie('goodsBrowseHistory', join(',', array_unique($goods_ids))); return $goods_list; }
function index() { /* 取得导航 */ $this->assign('navs', $this->_get_navs()); /* 取得满足条件的商品 */ $conditions = "g.if_show = 1 AND g.closed = 0 AND s.state = 1"; // 上架且没有被禁售,店铺是开启状态 $filters = array(); // 筛选条件 // 分类 $cate_id = empty($_GET['cate_id']) ? 0 : intval($_GET['cate_id']); if ($cate_id > 0) { $gcategory_mod =& m('gcategory'); $cate_ids = $gcategory_mod->get_descendant($cate_id); $conditions .= " AND cate_id" . db_create_in($cate_ids); } // 关键字 $keyword = trim($_GET['keyword']); if (!empty($keyword)) { //LLL 主搜索中 也搜索货号 //$conditions .= " AND goods_name OR sku LIKE '%{$keyword}%' "; $conditions .= " AND goods_name OR sku LIKE '%{$keyword}%' "; $filters['keyword'] = array('key' => 'keyword', 'name' => LANG::get('keyword'), 'value' => $keyword); } // 品牌 if (!empty($_GET['brand'])) { $conditions .= " AND brand = '{$_GET['brand']}' "; $filters['brand'] = array('key' => 'brand', 'name' => LANG::get('brand'), 'value' => $_GET['brand']); } // 地区 if (!empty($_GET['region_id'])) { $conditions .= " AND region_id = '{$_GET['region_id']}' "; $region_mod =& m('region'); $region = $region_mod->get_info($_GET['region_id']); $filters['region_id'] = array('key' => 'region_id', 'name' => LANG::get('region'), 'value' => $region['region_name']); } // 价格区间 if (!empty($_GET['price'])) { $arr = explode('-', $_GET['price']); $min = floatval($arr[0]); $max = floatval($arr[1]); if ($min != 0 || $max != 0) { if ($min != 0 && $max != 0) { if ($min > $max) { list($min, $max) = array($max, $min); } $conditions .= " AND price >= '{$min}' AND price <= '{$max}' "; $filters['price'] = array('key' => 'price', 'name' => LANG::get('price'), 'value' => price_format($min) . ' - ' . price_format($max)); } else { if ($min != 0) { $conditions .= " AND price >= '{$min}' "; $filters['price'] = array('key' => 'price', 'name' => LANG::get('price'), 'value' => LANG::get('ge') . ' ' . price_format($min)); } else { $conditions .= " AND price <= '{$max}' "; $filters['price'] = array('key' => 'price', 'name' => LANG::get('price'), 'value' => LANG::get('le') . ' ' . price_format($max)); } } } else { unset($_GET['price']); } } $page = $this->_get_page(12); $goods_mod =& m('goods'); $store_mod =& m('store'); $sgrade_mod =& m('sgrade'); $sgrades = $sgrade_mod->find(array('fields' => 'grade_name')); $goods_list = $goods_mod->get_list(array('conditions' => $conditions, 'count' => true, 'order' => empty($_GET['order']) || !in_array($_GET['order'], array('sales desc', 'price asc', 'price desc', 'credit_value_desc', 'views desc', 'add_time desc')) ? 'sales desc' : $_GET['order'], 'limit' => $page['limit'])); //LLL search 页面中商品列表中商品名多语言 $goods_list = chg_array2_string($goods_list, 'goods_name', get_lang2()); foreach ($goods_list as $key => $goods) { //等级图片 $step = intval(Conf::get('upgrade_required')); $step < 1 && ($step = 5); $goods_list[$key]['credit_image'] = $this->_view->res_base . '/images/' . $store_mod->compute_credit($goods['credit_value'], $step); empty($goods['default_image']) && ($goods_list[$key]['default_image'] = Conf::get('default_goods_image')); $goods_list[$key]['grade_name'] = $sgrades[$goods['sgrade']]['grade_name']; } $this->assign('goods_list', $goods_list); $page['item_count'] = $goods_mod->getCount(); $this->_format_page($page); $this->assign('page_info', $page); /* 商品展示方式 */ $display_mode = ecm_getcookie('goodsDisplayMode'); if (empty($display_mode) || !in_array($display_mode, array('list', 'squares'))) { $display_mode = 'squares'; // 默认格子方式 } $this->assign('display_mode', $display_mode); /* 统计品牌 */ $brands = $goods_mod->count_brand(); $this->assign('brands', $brands); $this->assign('brand_count', count($brands)); /* 统计价格 */ $this->assign('price_intervals', $goods_mod->count_price()); /* 统计地区 */ $regions = $goods_mod->count_region(); $this->assign('regions', $regions); $this->assign('region_count', count($regions)); /* 筛选条件 */ $this->assign('filters', $filters); /* 排序方式 */ $this->assign('orders', array('sales desc' => LANG::get('sales_desc'), 'credit_value desc' => LANG::get('credit_value_desc'), 'price asc' => LANG::get('price_asc'), 'price desc' => LANG::get('price_desc'), 'views desc' => LANG::get('views_desc'), 'add_time desc' => LANG::get('add_time_desc'))); /* 取得下级分类 */ $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $categories = $gcategory_mod->get_list($cate_id, true); //LLL categories里面的cate_name部分仅保留对应语言的字符 search page中左categories内容 $categories = chg_array2_string($categories, 'cate_name', get_lang2()); $this->assign('categories', $categories); $this->assign('category_count', count($categories)); /* 当前位置 */ $this->_curlocal($this->_get_goods_curlocal($cate_id)); $this->assign('page_title', Conf::get('site_title')); $this->display('search.goods.html'); }
function index() { // 查询参数 $param = $this->_get_query_param(); // 验证当前请求地址,是否需要跳转到频道页 psmb /**/ $check_param_for_channel = true; if (isset($param['cate_id']) && $param['cate_id'] > 0) { foreach ($param as $k => $v) { if (!empty($v) && ($k != 'cate_id' && $k != 'layer')) { $check_param_for_channel = false; } } // 如果当前请求的地址,只要一个 cate_id 参数,则检验当前 cate_id 是否有对应的频道页 if ($check_param_for_channel === true) { $channel_mod =& af('channels'); $channel_list = $channel_mod->getAll(); if ($channel_list) { foreach ($channel_list as $k => $v) { if ($v['cate_id'] == $param['cate_id'] && $v['status'] == 1) { header('Location:' . SITE_URL . '/index.php?app=channel&id=' . $k); break; } } } } } // end psmb if (isset($param['cate_id']) && $param['layer'] === false) { $this->show_warning('no_such_category'); return; } /* 筛选条件 */ $this->assign('filters', $this->_get_filter($param)); /* 按分类、品牌、地区、价格区间统计商品数量 */ $stats = $this->_get_group_by_info($param, ENABLE_SEARCH_CACHE); $this->assign('categories', $stats['by_category']); $this->assign('category_count', count($stats['by_category'])); if ($stats['by_brand']) { foreach ($stats['by_brand'] as $key => $val) { if ($this->filter_select_brand($val['brand'])) { $stats['by_brand'][$key]['brand_logo'] = $this->filter_select_brand($val['brand']); } } } $this->assign('brands', $stats['by_brand']); $this->assign('brand_count', count($stats['by_brand'])); $this->assign('price_intervals', $stats['by_price']); $this->assign('cate_id', $param['cate_id'] ? $param['cate_id'] : 0); $this->assign('regions', $stats['by_region']); $this->assign('region_count', count($stats['by_region'])); // sku psmb $this->assign('props', $stats['by_props']); $this->assign('props_selected', isset($param['props']) ? $param['props'] . ';' : ''); $this->assign('props_count', count($stats['by_props'])); /* 排序 */ $orders = $this->_get_orders(); $this->assign('orders', $orders); /* 分页信息 */ $page = $this->_get_page(NUM_PER_PAGE); $page['item_count'] = $stats['total_count']; $this->_format_page($page); $this->assign('page_info', $page); /* 商品列表 */ $sgrade_mod =& m('sgrade'); $sgrades = $sgrade_mod->get_options(); $conditions = $this->_get_goods_conditions($param); $goods_mod =& m('goods'); $goods_list = $goods_mod->get_list(array('conditions' => $conditions, 'order' => isset($_GET['order']) && isset($orders[$_GET['order']]) ? $_GET['order'] : '', 'limit' => $page['limit'])); $goodsimage_mod =& m('goodsimage'); foreach ($goods_list as $key => $goods) { $step = intval(Conf::get('upgrade_required')); $step < 1 && ($step = 5); $store_mod =& m('store'); $goods_list[$key]['credit_image'] = $this->_view->res_base . '/images/' . $store_mod->compute_credit($goods['credit_value'], $step); empty($goods['default_image']) && ($goods_list[$key]['default_image'] = Conf::get('default_goods_image')); if ($param['cate_id'] == 21 || $param['cate_id'] == 272) { if ($goods['default_image']) { $goods_list[$key]['default_image'] = str_replace("small_", "", $goods['default_image']); } } $spec_image = $goodsimage_mod->find('goods_id=' . $goods['goods_id']); if (count($spec_image) > 1) { $current_pic = current($spec_image); if ($current_pic['image_url'] !== $goods_list[$key]['default_image']) { $image = $current_pic['image_url']; } else { $next_pic = next($spec_image); $image = $next_pic['image_url']; } $goods_list[$key]['another_image'] = $image; } else { $goods_list[$key]['another_image'] = $goods_list[$key]['default_image']; } $goods_list[$key]['grade_name'] = $sgrades[$goods['sgrade']]; } $this->assign('goods_list', $goods_list); /* 商品展示方式 */ $display_mode = ecm_getcookie('goodsDisplayMode'); if (empty($display_mode) || !in_array($display_mode, array('list', 'squares'))) { $display_mode = 'squares'; // 默认格子方式 } $this->assign('display_mode', $display_mode); /* 取得导航 */ $this->assign('navs', $this->_get_navs()); /* 当前位置 */ $cate_id = isset($param['cate_id']) ? $param['cate_id'] : 0; $this->_curlocal($this->_get_goods_curlocal($cate_id)); /* 配置seo信息 */ $this->_config_seo($this->_get_seo_info('goods', $cate_id)); $this->display('search.goods.html'); }
function _set_goods_history($id, $num = 5) { $goods_ids = ecm_getcookie('goodsBrowseHistory'); $goods_ids = $goods_ids ? explode(',', $goods_ids) : array(); $goods_ids[] = $id; if (count($goods_ids) > $num) { unset($goods_ids[0]); } ecm_setcookie('goodsBrowseHistory', join(',', array_unique($goods_ids))); return true; }
function _get_history() { $goods_list = array(); $goods_ids = ecm_getcookie('goodsBrowseHistory'); $goods_ids = $goods_ids ? explode(',', $goods_ids) : array(); $goods =& m('goods'); if ($goods_ids) { $rows = $goods->find(array('conditions' => $goods_ids, 'fields' => 'goods_name,default_image,price', 'limit' => 5)); foreach ($goods_ids as $goods_id) { if (isset($rows[$goods_id])) { empty($rows[$goods_id]['default_image']) && ($rows[$goods_id]['default_image'] = Conf::get('default_goods_image')); $goods_list[] = $rows[$goods_id]; } } } ecm_setcookie('goodsBrowseHistory', join(',', array_unique($goods_ids))); return $goods_list; }