commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 店铺分类文件 |
|
5 |
*/ |
|
6 |
|
|
7 |
|
|
8 |
/* 获得请求的分类 ID */ |
|
9 |
if (isset($_REQUEST['id'])) |
|
10 |
{ |
|
11 |
// $cat_id = intval($_REQUEST['id']); |
|
12 |
} |
|
13 |
else |
|
14 |
{ |
|
15 |
/* 如果分类ID为0,则返回首页 */ |
|
16 |
// ecs_header("Location: ./\n"); |
|
17 |
|
|
18 |
// exit; |
|
19 |
} |
|
20 |
|
|
21 |
|
|
22 |
/* 初始化分页信息 */ |
|
23 |
$cat_id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0 ? intval($_REQUEST['id']) : 0; |
|
24 |
$keywords = isset($_REQUEST['keywords']) && !empty($_REQUEST['keywords']) ? htmlspecialchars($_REQUEST['keywords']) : ''; |
|
25 |
$keywords = ($keywords == '请输入你要查找的商品') ? '' : $keywords; |
|
26 |
$price = isset($_REQUEST['price']) ? intval($_REQUEST['price']) : 0; |
|
27 |
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1; |
|
28 |
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10; |
|
29 |
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'shop_price', 'last_update'))) ? 'g.'.trim($_REQUEST['sort']) : 'g.goods_id'; |
|
30 |
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : 'DESC'; |
|
31 |
/*------------------------------------------------------ */ |
|
32 |
//-- PROCESSOR |
|
33 |
/*------------------------------------------------------ */ |
|
34 |
|
|
35 |
/* 页面的缓存ID */ |
|
36 |
$cache_id = sprintf('%X', crc32($cat_id . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' . |
|
37 |
$_CFG['lang'] .'-'. $brand. '-' . $price_max . '-' .$price_min . '-' . $filter_attr_str.'-'.$_GET['suppId'])); |
|
38 |
|
|
39 |
if (!$smarty->is_cached('search.dwt', $cache_id)) |
|
40 |
{ |
|
41 |
assign_template(); |
|
42 |
assign_template_supplier(); |
|
43 |
$position = assign_ur_here(); |
|
44 |
|
|
45 |
|
|
46 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
47 |
//$smarty->assign('ur_here', $ur_here); // 当前位置 |
|
48 |
|
|
49 |
$smarty->assign('categories', get_categories_tree_supplier()); // 分类树 |
|
50 |
|
|
51 |
$s_value = get_search_price($price); |
|
52 |
|
|
53 |
$children = get_cattype_supplier($cat_id,$keywords); |
|
54 |
if($children === false){ |
|
55 |
ecs_header("Location: supplier.php?suppId=".$_GET['suppId']); |
|
56 |
exit; |
|
57 |
} |
|
58 |
$count = get_cagtegory_goods_count($children,$keywords,$s_value); |
|
59 |
$max_page = ($count> 0) ? ceil($count / $size) : 1; |
|
60 |
if ($page > $max_page) |
|
61 |
{ |
|
62 |
$page = $max_page; |
|
63 |
} |
|
64 |
$goodslist = category_get_goods($children, $size, $page,$keywords,$s_value,$sort, $order); |
|
65 |
if($display == 'grid') |
|
66 |
{ |
|
67 |
if(count($goodslist) % 2 != 0) |
|
68 |
{ |
|
69 |
$goodslist[] = array(); |
|
70 |
} |
|
71 |
} |
|
72 |
assign_pager('supplier', $cat_id, $count, $size, $sort, $order, $page, $keywords."&price=".$price, '', '', '', $display, ''); // 分页 |
|
73 |
$smarty->assign('goods_list', $goodslist); |
|
74 |
assign_dynamic('search'); |
|
75 |
} |
|
76 |
|
|
77 |
$smarty->display('search.dwt', $cache_id); |
|
78 |
|
|
79 |
/*------------------------------------------------------ */ |
|
80 |
//-- PRIVATE FUNCTION |
|
81 |
/*------------------------------------------------------ */ |
|
82 |
|
|
83 |
/** |
|
84 |
* 获得指定商品属性所属的分类的ID |
|
85 |
* |
|
86 |
* @access public |
|
87 |
* @param integer $cat (1=>'精品推荐',2=>'新品上市',3=>'热卖商品') |
|
88 |
* @param string $keywords 关键字 |
|
89 |
* @return string |
|
90 |
*/ |
|
91 |
function get_cattype_supplier($cat = 0,$keywords='') |
|
92 |
{ |
|
93 |
if(empty($keywords)){ |
|
94 |
$where = "supplier_id=".$_GET['suppId']; |
|
95 |
if($cat > 0){ |
|
96 |
$where .= " AND recommend_type=".$cat; |
|
97 |
} |
|
98 |
$sql = "select cat_id from ". $GLOBALS['ecs']->table('supplier_cat_recommend') ." where ".$where; |
|
99 |
$res = $GLOBALS['db']->getAll($sql); |
|
100 |
$arr = array(); |
|
101 |
if(count($res)>0){ |
|
102 |
foreach($res as $k => $v){ |
|
103 |
$arr[$v['cat_id']] = $v['cat_id']; |
|
104 |
} |
|
105 |
} |
|
106 |
if(empty($arr)){ |
|
107 |
return false; |
|
108 |
} |
|
109 |
return 'sgc.cat_id ' . db_create_in(array_keys($arr)); |
|
110 |
}else{ |
|
111 |
return "g.goods_name like '%".$keywords."%'"; |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* 获得分类下的商品 |
|
117 |
* |
|
118 |
* @access public |
|
119 |
* @param string $children |
|
120 |
* @param array $price_search 搜索价格区间中的商品 |
|
121 |
* @return array |
|
122 |
*/ |
|
123 |
function category_get_goods($children, $size, $page,$keywords='',$price_search='',$sort, $order) |
|
124 |
{ |
|
125 |
$display = $GLOBALS['display']; |
|
126 |
|
|
127 |
$price_str = ''; |
|
128 |
if(!empty($price_search)){ |
|
129 |
if($price_search['min'] > 0){ |
|
130 |
$price_str .= " AND g.shop_price > ".$price_search['min']." "; |
|
131 |
} |
|
132 |
if($price_search['max'] > 0){ |
|
133 |
$price_str .= " AND g.shop_price <= ".$price_search['max']." "; |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ". |
|
138 |
"g.is_delete = 0 ".$price_str." AND ($children)"; |
|
139 |
|
|
140 |
|
|
141 |
/* 获得商品列表 */ |
|
142 |
if(empty($keywords)){ |
|
143 |
$where .= " AND sgc.supplier_id=".$_GET['suppId']; |
|
144 |
$sql = 'SELECT DISTINCT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . |
|
145 |
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " . |
|
146 |
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb ,g.original_img , g.goods_img ' . |
|
147 |
'FROM ' . $GLOBALS['ecs']->table('supplier_goods_cat') . ' AS sgc ' . |
|
148 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
149 |
"ON sgc.goods_id = g.goods_id " . |
|
150 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . |
|
151 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " . |
|
152 |
"WHERE $where ORDER BY $sort $order"; |
|
153 |
}else{ |
|
154 |
$where .= " AND g.supplier_id=".$_GET['suppId']; |
|
155 |
$sql = 'SELECT DISTINCT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . |
|
156 |
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " . |
|
157 |
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb ,g.original_img, g.goods_img ' . |
|
158 |
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
159 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . |
|
160 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " . |
|
161 |
"WHERE $where ORDER BY $sort $order"; |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); |
|
166 |
|
|
167 |
$arr = array(); |
|
168 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
169 |
{ |
|
170 |
if ($row['promote_price'] > 0) |
|
171 |
{ |
|
172 |
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); |
|
173 |
} |
|
174 |
else |
|
175 |
{ |
|
176 |
$promote_price = 0; |
|
177 |
} |
|
178 |
|
|
179 |
/* 处理商品水印图片 */ |
|
180 |
$watermark_img = ''; |
|
181 |
|
|
182 |
if ($promote_price != 0) |
|
183 |
{ |
|
184 |
$watermark_img = "watermark_promote_small"; |
|
185 |
} |
|
186 |
elseif ($row['is_new'] != 0) |
|
187 |
{ |
|
188 |
$watermark_img = "watermark_new_small"; |
|
189 |
} |
|
190 |
elseif ($row['is_best'] != 0) |
|
191 |
{ |
|
192 |
$watermark_img = "watermark_best_small"; |
|
193 |
} |
|
194 |
elseif ($row['is_hot'] != 0) |
|
195 |
{ |
|
196 |
$watermark_img = 'watermark_hot_small'; |
|
197 |
} |
|
198 |
|
|
199 |
if ($watermark_img != '') |
|
200 |
{ |
|
201 |
$arr[$row['goods_id']]['watermark_img'] = $watermark_img; |
|
202 |
} |
|
203 |
|
|
204 |
$arr[$row['goods_id']]['goods_id'] = $row['goods_id']; |
|
205 |
if($display == 'grid') |
|
206 |
{ |
|
207 |
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; |
|
208 |
} |
|
209 |
else |
|
210 |
{ |
|
211 |
$arr[$row['goods_id']]['goods_name'] = $row['goods_name']; |
|
212 |
} |
|
213 |
$arr[$row['goods_id']]['name'] = $row['goods_name']; |
|
214 |
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; |
|
215 |
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); |
|
216 |
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); |
|
217 |
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); |
|
218 |
$arr[$row['goods_id']]['type'] = $row['goods_type']; |
|
219 |
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ''; |
|
220 |
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
221 |
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
222 |
$arr[$row['goods_id']]['original_img'] = get_image_path($row['goods_id'], $row['original_img']); |
|
223 |
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); |
|
224 |
} |
|
225 |
|
|
226 |
return $arr; |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* 获得分类下的商品总数 |
|
231 |
* |
|
232 |
* @access public |
|
233 |
* @param string $children |
|
234 |
* @param string $keywords 商品名称查找 |
|
235 |
* @param array $price_search 搜索价格区间中的商品 |
|
236 |
* @return integer |
|
237 |
*/ |
|
238 |
function get_cagtegory_goods_count($children,$keywords='',$price_search='') |
|
239 |
{ |
|
240 |
$price_str = ''; |
|
241 |
if(!empty($price_search)){ |
|
242 |
if($price_search['min'] > 0){ |
|
243 |
$price_str .= " AND g.shop_price > ".$price_search['min']." "; |
|
244 |
} |
|
245 |
if($price_search['max'] > 0){ |
|
246 |
$price_str .= " AND g.shop_price <= ".$price_search['max']." "; |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
/* 返回商品总数 */ |
|
251 |
if(empty($keywords)){ |
|
252 |
$where = "sgc.supplier_id=".$_GET['suppId']." AND $children"; |
|
253 |
$sql = 'SELECT count(DISTINCT g.goods_id) FROM ' . $GLOBALS['ecs']->table('supplier_goods_cat') . ' AS sgc LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
254 |
'ON sgc.goods_id = g.goods_id AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 '.$price_str.' WHERE '.$where; |
|
255 |
}else{ |
|
256 |
$where = "g.supplier_id=".$_GET['suppId']." AND $children"; |
|
257 |
$sql = 'SELECT count(DISTINCT g.goods_id) FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
258 |
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 '. $price_str .' AND '.$where; |
|
259 |
} |
|
260 |
return $GLOBALS['db']->getOne($sql); |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* 获取搜索中用户选择的价格区间 |
|
265 |
* @param int $price 代表价格区间的值 |
|
266 |
*/ |
|
267 |
function get_search_price($price=0){ |
|
268 |
global $index_price; |
|
269 |
$num = count($index_price); |
|
270 |
$info = explode('-',$index_price[$price]); |
|
271 |
$ret = array('min'=>0,'max'=>0); |
|
272 |
if($price < --$num){ |
|
273 |
//搜索中价格第一个条件 |
|
274 |
if(count($info) == 1){ |
|
275 |
$ret['min'] = intval($info[0]); |
|
276 |
$ret['max'] = 0; |
|
277 |
}else{ |
|
278 |
$ret['min'] = intval($info[0]); |
|
279 |
$ret['max'] = intval($info[1]); |
|
280 |
} |
|
281 |
}elseif($price == --$num){ |
|
282 |
//搜索中价格最后一个条件 |
|
283 |
if(count($info) == 1){ |
|
284 |
$ret['min'] = 0; |
|
285 |
$ret['max'] = intval($info[1]); |
|
286 |
}else{ |
|
287 |
$ret['min'] = intval($info[0]); |
|
288 |
$ret['max'] = intval($info[1]); |
|
289 |
} |
|
290 |
}else{ |
|
291 |
//搜索中价格中间条件 |
|
292 |
$ret['min'] = intval($info[0]); |
|
293 |
$ret['max'] = intval($info[1]); |
|
294 |
} |
|
295 |
return $ret; |
|
296 |
} |
|
297 |
|
|
298 |
?> |