commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 搜索程序 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
|
|
9 |
|
|
10 |
if (!function_exists("htmlspecialchars_decode")) |
|
11 |
{ |
|
12 |
function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) |
|
13 |
{ |
|
14 |
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style))); |
|
15 |
} |
|
16 |
} |
|
17 |
|
|
18 |
if (empty($_GET['encode'])) |
|
19 |
{ |
|
20 |
$string = array_merge($_GET, $_POST); |
|
21 |
if (get_magic_quotes_gpc()) |
|
22 |
{ |
|
23 |
require(dirname(__FILE__) . '/includes/lib_base.php'); |
|
24 |
$string = stripslashes_deep($string); |
|
25 |
} |
|
26 |
$string['search_encode_time'] = time(); |
|
27 |
$string = str_replace('+', '%2b', base64_encode(serialize($string))); |
|
28 |
|
|
29 |
header("Location: pro_search.php?encode=$string\n"); |
|
30 |
|
|
31 |
exit; |
|
32 |
} |
|
33 |
else |
|
34 |
{ |
|
35 |
$string = base64_decode(trim($_GET['encode'])); |
|
36 |
if ($string !== false) |
|
37 |
{ |
|
38 |
$string = unserialize($string); |
|
39 |
if ($string !== false) |
|
40 |
{ |
|
41 |
/* 用户在重定向的情况下当作一次访问 */ |
|
42 |
if (!empty($string['search_encode_time'])) |
|
43 |
{ |
|
44 |
if (time() > $string['search_encode_time'] + 2) |
|
45 |
{ |
|
46 |
define('INGORE_VISIT_STATS', true); |
|
47 |
} |
|
48 |
} |
|
49 |
else |
|
50 |
{ |
|
51 |
define('INGORE_VISIT_STATS', true); |
|
52 |
} |
|
53 |
} |
|
54 |
else |
|
55 |
{ |
|
56 |
$string = array(); |
|
57 |
} |
|
58 |
} |
|
59 |
else |
|
60 |
{ |
|
61 |
$string = array(); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
66 |
|
|
67 |
$_REQUEST = array_merge($_REQUEST, addslashes_deep($string)); |
|
68 |
|
|
69 |
$_REQUEST['act'] = !empty($_REQUEST['act']) ? trim($_REQUEST['act']) : ''; |
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
//线上红包 |
|
74 |
$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('bonus_type') . |
|
75 |
" WHERE send_type = '4'"; |
|
76 |
$row = $GLOBALS['db']->GetAll($sql); |
|
77 |
$time=time(); |
|
78 |
date_default_timezone_set('PRC'); |
|
79 |
$smarty->assign('time',$time); |
|
80 |
$smarty->assign('online_bonus',$row); |
|
81 |
|
|
82 |
//判断 弹框登陆 验证码是否显示 |
|
83 |
$captcha = intval($_CFG['captcha']); |
|
84 |
if(($captcha & CAPTCHA_LOGIN) && (! ($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0) |
|
85 |
{ |
|
86 |
$GLOBALS['smarty']->assign('enabled_captcha', 1); |
|
87 |
$GLOBALS['smarty']->assign('rand', mt_rand()); |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
/*------------------------------------------------------ */ |
|
93 |
//-- 高级搜索 |
|
94 |
/*------------------------------------------------------ */ |
|
95 |
if ($_REQUEST['act'] == 'advanced_search') |
|
96 |
{ |
|
97 |
$goods_type = !empty($_REQUEST['goods_type']) ? intval($_REQUEST['goods_type']) : 0; |
|
98 |
$attributes = get_seachable_attributes($goods_type); |
|
99 |
$smarty->assign('goods_type_selected', $goods_type); |
|
100 |
$smarty->assign('goods_type_list', $attributes['cate']); |
|
101 |
$smarty->assign('goods_attributes', $attributes['attr']); |
|
102 |
|
|
103 |
assign_template(); |
|
104 |
assign_dynamic('search'); |
|
105 |
$position = assign_ur_here(0, $_LANG['advanced_search']); |
|
106 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
107 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
108 |
|
|
109 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
110 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
111 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
112 |
$smarty->assign('promotion_info', get_promotion_info()); |
|
113 |
$smarty->assign('cat_list', cat_list(0, 0, true, 2, false)); |
|
114 |
$smarty->assign('brand_list', get_brand_list()); |
|
115 |
$smarty->assign('action', 'form'); |
|
116 |
$smarty->assign('use_storage', $_CFG['use_storage']); |
|
117 |
|
|
118 |
$smarty->display('pro_search.dwt'); |
|
119 |
|
|
120 |
exit; |
|
121 |
} |
|
122 |
/*------------------------------------------------------ */ |
|
123 |
//-- 搜索结果 |
|
124 |
/*------------------------------------------------------ */ |
|
125 |
else |
|
126 |
{ |
|
127 |
$_REQUEST['keywords'] = !empty($_REQUEST['keywords']) ? htmlspecialchars(trim($_REQUEST['keywords'])) : ''; |
|
128 |
$_REQUEST['brand'] = !empty($_REQUEST['brand']) ? intval($_REQUEST['brand']) : 0; |
|
129 |
$_REQUEST['category'] = !empty($_REQUEST['category']) ? intval($_REQUEST['category']) : 0; |
|
130 |
$_REQUEST['min_price'] = !empty($_REQUEST['min_price']) ? intval($_REQUEST['min_price']) : 0; |
|
131 |
$_REQUEST['max_price'] = !empty($_REQUEST['max_price']) ? intval($_REQUEST['max_price']) : 0; |
|
132 |
$_REQUEST['goods_type'] = !empty($_REQUEST['goods_type']) ? intval($_REQUEST['goods_type']) : 0; |
|
133 |
$_REQUEST['sc_ds'] = !empty($_REQUEST['sc_ds']) ? intval($_REQUEST['sc_ds']) : 0; |
|
134 |
$_REQUEST['outstock'] = !empty($_REQUEST['outstock']) ? 1 : 0; |
|
135 |
|
|
136 |
$action = ''; |
|
137 |
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'form') |
|
138 |
{ |
|
139 |
/* 要显示高级搜索栏 */ |
|
140 |
$adv_value['keywords'] = htmlspecialchars(stripcslashes($_REQUEST['keywords'])); |
|
141 |
$adv_value['brand'] = $_REQUEST['brand']; |
|
142 |
$adv_value['min_price'] = $_REQUEST['min_price']; |
|
143 |
$adv_value['max_price'] = $_REQUEST['max_price']; |
|
144 |
$adv_value['category'] = $_REQUEST['category']; |
|
145 |
|
|
146 |
$attributes = get_seachable_attributes($_REQUEST['goods_type']); |
|
147 |
|
|
148 |
/* 将提交数据重新赋值 */ |
|
149 |
foreach ($attributes['attr'] AS $key => $val) |
|
150 |
{ |
|
151 |
if (!empty($_REQUEST['attr'][$val['id']])) |
|
152 |
{ |
|
153 |
if ($val['type'] == 2) |
|
154 |
{ |
|
155 |
$attributes['attr'][$key]['value']['from'] = !empty($_REQUEST['attr'][$val['id']]['from']) ? htmlspecialchars(stripcslashes(trim($_REQUEST['attr'][$val['id']]['from']))) : ''; |
|
156 |
$attributes['attr'][$key]['value']['to'] = !empty($_REQUEST['attr'][$val['id']]['to']) ? htmlspecialchars(stripcslashes(trim($_REQUEST['attr'][$val['id']]['to']))) : ''; |
|
157 |
} |
|
158 |
else |
|
159 |
{ |
|
160 |
$attributes['attr'][$key]['value'] = !empty($_REQUEST['attr'][$val['id']]) ? htmlspecialchars(stripcslashes(trim($_REQUEST['attr'][$val['id']]))) : ''; |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
if ($_REQUEST['sc_ds']) |
|
165 |
{ |
|
166 |
$smarty->assign('scck', 'checked'); |
|
167 |
} |
|
168 |
$smarty->assign('adv_val', $adv_value); |
|
169 |
$smarty->assign('goods_type_list', $attributes['cate']); |
|
170 |
$smarty->assign('goods_attributes', $attributes['attr']); |
|
171 |
$smarty->assign('goods_type_selected', $_REQUEST['goods_type']); |
|
172 |
$smarty->assign('cat_list', cat_list(0, $adv_value['category'], true, 2, false)); |
|
173 |
$smarty->assign('brand_list', get_brand_list()); |
|
174 |
$smarty->assign('action', 'form'); |
|
175 |
$smarty->assign('use_storage', $_CFG['use_storage']); |
|
176 |
$action = 'form'; |
|
177 |
} |
|
178 |
|
|
179 |
/* 初始化搜索条件 */ |
|
180 |
$keywords = ''; |
|
181 |
$tag_where = ''; |
|
182 |
if (!empty($_REQUEST['keywords'])) |
|
183 |
{ |
|
184 |
$arr = array(); |
|
185 |
if (stristr($_REQUEST['keywords'], ' AND ') !== false) |
|
186 |
{ |
|
187 |
/* 检查关键字中是否有AND,如果存在就是并 */ |
|
188 |
$arr = explode('AND', $_REQUEST['keywords']); |
|
189 |
$operator = " AND "; |
|
190 |
} |
|
191 |
elseif (stristr($_REQUEST['keywords'], ' OR ') !== false) |
|
192 |
{ |
|
193 |
/* 检查关键字中是否有OR,如果存在就是或 */ |
|
194 |
$arr = explode('OR', $_REQUEST['keywords']); |
|
195 |
$operator = " OR "; |
|
196 |
} |
|
197 |
elseif (stristr($_REQUEST['keywords'], ' + ') !== false) |
|
198 |
{ |
|
199 |
/* 检查关键字中是否有加号,如果存在就是或 */ |
|
200 |
$arr = explode('+', $_REQUEST['keywords']); |
|
201 |
$operator = " OR "; |
|
202 |
} |
|
203 |
else |
|
204 |
{ |
|
205 |
/* 检查关键字中是否有空格,如果存在就是并 */ |
|
206 |
$arr = explode(' ', $_REQUEST['keywords']); |
|
207 |
$operator = " AND "; |
|
208 |
} |
|
209 |
|
|
210 |
$keywords = 'AND ('; |
|
211 |
$goods_ids = array(); |
|
212 |
foreach ($arr AS $key => $val) |
|
213 |
{ |
|
214 |
if ($key > 0 && $key < count($arr) && count($arr) > 1) |
|
215 |
{ |
|
216 |
$keywords .= $operator; |
|
217 |
} |
|
218 |
$val = mysql_like_quote(trim($val)); |
|
219 |
$sc_dsad = $_REQUEST['sc_ds'] ? " OR goods_desc LIKE '%$val%'" : ''; |
|
220 |
$keywords .= "(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)"; |
|
221 |
|
|
222 |
$sql = 'SELECT DISTINCT goods_id FROM ' . $ecs->table('tag') . " WHERE tag_words LIKE '%$val%' "; |
|
223 |
$res = $db->query($sql); |
|
224 |
while ($row = $db->FetchRow($res)) |
|
225 |
{ |
|
226 |
$goods_ids[] = $row['goods_id']; |
|
227 |
} |
|
228 |
|
|
229 |
$db->autoReplace($ecs->table('keywords'), array('date' => local_date('Y-m-d'), |
|
230 |
'searchengine' => 'ecshop', 'keyword' => addslashes(str_replace('%', '', $val)), 'count' => 1), array('count' => 1)); |
|
231 |
} |
|
232 |
$keywords .= ')'; |
|
233 |
|
|
234 |
$goods_ids = array_unique($goods_ids); |
|
235 |
$tag_where = implode(',', $goods_ids); |
|
236 |
if (!empty($tag_where)) |
|
237 |
{ |
|
238 |
$tag_where = 'OR g.goods_id ' . db_create_in($tag_where); |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
$category = !empty($_REQUEST['category']) ? intval($_REQUEST['category']) : 0; |
|
243 |
$categories = ($category > 0) ? ' AND ' . get_children($category) : ''; |
|
244 |
$brand = $_REQUEST['brand'] ? " AND brand_id = '$_REQUEST[brand]'" : ''; |
|
245 |
$outstock = !empty($_REQUEST['outstock']) ? " AND g.goods_number > 0 " : ''; |
|
246 |
|
|
247 |
$min_price = $_REQUEST['min_price'] != 0 ? " AND g.shop_price >= '$_REQUEST[min_price]'" : ''; |
|
248 |
$max_price = $_REQUEST['max_price'] != 0 || $_REQUEST['min_price'] < 0 ? " AND g.shop_price <= '$_REQUEST[max_price]'" : ''; |
|
249 |
|
|
250 |
/* 排序、显示方式以及类型 */ |
|
251 |
$default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : ($_CFG['show_order_type'] == '1' ? 'grid' : 'text'); |
|
252 |
$default_sort_order_method = $_CFG['sort_order_method'] == '0' ? 'DESC' : 'ASC'; |
|
253 |
$default_sort_order_type = $_CFG['sort_order_type'] == '0' ? 'goods_id' : ($_CFG['sort_order_type'] == '1' ? 'shop_price' : 'last_update'); |
|
254 |
|
|
255 |
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'promote_price', 'salenum', 'zhekou'))) ? trim($_REQUEST['sort']) : $default_sort_order_type; |
|
256 |
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : $default_sort_order_method; |
|
257 |
$display = (isset($_REQUEST['display']) && in_array(trim(strtolower($_REQUEST['display'])), array('list', 'grid', 'text'))) ? trim($_REQUEST['display']) : (isset($_SESSION['display_search']) ? $_SESSION['display_search'] : $default_display_type); |
|
258 |
|
|
259 |
$_SESSION['display_search'] = $display; |
|
260 |
|
|
261 |
$page = !empty($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1; |
|
262 |
$size = !empty($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10; |
|
263 |
|
|
264 |
$intromode = ''; //方式,用于决定搜索结果页标题图片 |
|
265 |
|
|
266 |
if (!empty($_REQUEST['intro'])) |
|
267 |
{ |
|
268 |
switch ($_REQUEST['intro']) |
|
269 |
{ |
|
270 |
case 'best': |
|
271 |
$intro = ' AND g.is_best = 1'; |
|
272 |
$intromode = 'best'; |
|
273 |
$ur_here = $_LANG['best_goods']; |
|
274 |
break; |
|
275 |
case 'new': |
|
276 |
$intro = ' AND g.is_new = 1'; |
|
277 |
$intromode ='new'; |
|
278 |
$ur_here = $_LANG['new_goods']; |
|
279 |
break; |
|
280 |
case 'hot': |
|
281 |
$intro = ' AND g.is_hot = 1'; |
|
282 |
$intromode = 'hot'; |
|
283 |
$ur_here = $_LANG['hot_goods']; |
|
284 |
break; |
|
285 |
case 'promotion': |
|
286 |
$time = gmtime(); |
|
287 |
$intro = " AND g.promote_price > 0 AND g.promote_start_date <= '$time' AND g.promote_end_date >= '$time'"; |
|
288 |
$intromode = 'promotion'; |
|
289 |
$ur_here = $_LANG['group_buy_goods']; |
|
290 |
break; |
|
291 |
default: |
|
292 |
$intro = ''; |
|
293 |
} |
|
294 |
} |
|
295 |
else |
|
296 |
{ |
|
297 |
$intro = ''; |
|
298 |
} |
|
299 |
|
|
300 |
if (empty($ur_here)) |
|
301 |
{ |
|
302 |
$ur_here = $_LANG['search_goods']; |
|
303 |
} |
|
304 |
|
|
305 |
/*------------------------------------------------------ */ |
|
306 |
//-- 属性检索 |
|
307 |
/*------------------------------------------------------ */ |
|
308 |
$attr_in = ''; |
|
309 |
$attr_num = 0; |
|
310 |
$attr_url = ''; |
|
311 |
$attr_arg = array(); |
|
312 |
|
|
313 |
if (!empty($_REQUEST['attr'])) |
|
314 |
{ |
|
315 |
$sql = "SELECT goods_id, COUNT(*) AS num FROM " . $ecs->table("goods_attr") . " WHERE 0 "; |
|
316 |
foreach ($_REQUEST['attr'] AS $key => $val) |
|
317 |
{ |
|
318 |
if (is_not_null($val) && is_numeric($key)) |
|
319 |
{ |
|
320 |
$attr_num++; |
|
321 |
$sql .= " OR (1 "; |
|
322 |
|
|
323 |
if (is_array($val)) |
|
324 |
{ |
|
325 |
$sql .= " AND attr_id = '$key'"; |
|
326 |
|
|
327 |
if (!empty($val['from'])) |
|
328 |
{ |
|
329 |
$sql .= is_numeric($val['from']) ? " AND attr_value >= " . floatval($val['from']) : " AND attr_value >= '$val[from]'"; |
|
330 |
$attr_arg["attr[$key][from]"] = $val['from']; |
|
331 |
$attr_url .= "&attr[$key][from]=$val[from]"; |
|
332 |
} |
|
333 |
|
|
334 |
if (!empty($val['to'])) |
|
335 |
{ |
|
336 |
$sql .= is_numeric($val['to']) ? " AND attr_value <= " . floatval($val['to']) : " AND attr_value <= '$val[to]'"; |
|
337 |
$attr_arg["attr[$key][to]"] = $val['to']; |
|
338 |
$attr_url .= "&attr[$key][to]=$val[to]"; |
|
339 |
} |
|
340 |
} |
|
341 |
else |
|
342 |
{ |
|
343 |
/* 处理选购中心过来的链接 */ |
|
344 |
$sql .= isset($_REQUEST['pickout']) ? " AND attr_id = '$key' AND attr_value = '" . $val . "' " : " AND attr_id = '$key' AND attr_value LIKE '%" . mysql_like_quote($val) . "%' "; |
|
345 |
$attr_url .= "&attr[$key]=$val"; |
|
346 |
$attr_arg["attr[$key]"] = $val; |
|
347 |
} |
|
348 |
|
|
349 |
$sql .= ')'; |
|
350 |
} |
|
351 |
} |
|
352 |
|
|
353 |
/* 如果检索条件都是无效的,就不用检索 */ |
|
354 |
if ($attr_num > 0) |
|
355 |
{ |
|
356 |
$sql .= " GROUP BY goods_id HAVING num = '$attr_num'"; |
|
357 |
|
|
358 |
$row = $db->getCol($sql); |
|
359 |
if (count($row)) |
|
360 |
{ |
|
361 |
$attr_in = " AND " . db_create_in($row, 'g.goods_id'); |
|
362 |
} |
|
363 |
else |
|
364 |
{ |
|
365 |
$attr_in = " AND 0 "; |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
elseif (isset($_REQUEST['pickout'])) |
|
370 |
{ |
|
371 |
/* 从选购中心进入的链接 */ |
|
372 |
$sql = "SELECT DISTINCT(goods_id) FROM " . $ecs->table('goods_attr'); |
|
373 |
$col = $db->getCol($sql); |
|
374 |
//如果商店没有设置商品属性,那么此检索条件是无效的 |
|
375 |
if (!empty($col)) |
|
376 |
{ |
|
377 |
$attr_in = " AND " . db_create_in($col, 'g.goods_id'); |
|
378 |
} |
|
379 |
} |
|
380 |
|
|
381 |
//时区转换 |
|
382 |
|
|
383 |
/* 获得符合条件的商品总数 */ |
|
384 |
$sql = "SELECT COUNT(*) FROM " .$ecs->table('goods'). " AS g ". |
|
385 |
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_promote = 1 AND g.promote_end_date >= ".gmtime()." $attr_in ". |
|
386 |
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock ." ) ".$tag_where." )"; |
|
387 |
$count = $db->getOne($sql); |
|
388 |
|
|
389 |
$max_page = ($count> 0) ? ceil($count / $size) : 1; |
|
390 |
if ($page > $max_page) |
|
391 |
{ |
|
392 |
$page = $max_page; |
|
393 |
} |
|
394 |
|
|
395 |
/* 查询商品 */ |
|
396 |
$sort = ($sort == 'shop_price' ? 'shop_p' : $sort); |
|
397 |
$sql = "SELECT g.goods_id, g.goods_name, g.goods_number, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ". |
|
398 |
" IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, " . |
|
399 |
" IF(g.promote_price != '' " . |
|
400 |
" AND g.promote_start_date <= " . gmtime() . |
|
401 |
" AND g.promote_end_date >= " . gmtime() . ", g.promote_price, shop_price) " . |
|
402 |
" AS shop_p, g.goods_type, " . |
|
403 |
"g.zhekou, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type ". |
|
404 |
"FROM " .$ecs->table('goods'). " AS g ". |
|
405 |
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". |
|
406 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". |
|
407 |
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_promote = 1 AND g.promote_end_date >= ".gmtime()." $attr_in ". |
|
408 |
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " . |
|
409 |
"ORDER BY $sort $order"; |
|
410 |
if ($sort=='salenum') |
|
411 |
{ |
|
412 |
$sql = "SELECT IFNULL(o.num,0) AS salenum, g.goods_id, g.goods_name, g.goods_number, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, " . |
|
413 |
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, " . |
|
414 |
"g.zhekou, g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type " . |
|
415 |
"FROM " .$ecs->table('goods'). " AS g " . |
|
416 |
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . |
|
417 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " . |
|
418 |
" LEFT JOIN " . |
|
419 |
" (SELECT " . |
|
420 |
" SUM(og.`goods_number`) " . |
|
421 |
" AS num,og.goods_id " . |
|
422 |
" FROM " . |
|
423 |
" ecs_order_goods AS og, " . |
|
424 |
" ecs_order_info AS oi " . |
|
425 |
" WHERE oi.pay_status = 2 " . |
|
426 |
" AND oi.order_status >= 1 " . |
|
427 |
" AND oi.order_id = og.order_id " . |
|
428 |
" GROUP BY og.goods_id) " . |
|
429 |
" AS o " . |
|
430 |
"ON o.goods_id = g.goods_id " . |
|
431 |
"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_promote = 1 AND g.promote_end_date >= ".gmtime()." $attr_in " . |
|
432 |
"AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " . |
|
433 |
"ORDER BY $sort $order"; |
|
434 |
} |
|
435 |
$res = $db->SelectLimit($sql, $size, ($page - 1) * $size); |
|
436 |
|
|
437 |
$arr = array(); |
|
438 |
while ($row = $db->FetchRow($res)) |
|
439 |
{ |
|
440 |
if ($row['promote_price'] > 0) |
|
441 |
{ |
|
442 |
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); |
|
443 |
} |
|
444 |
else |
|
445 |
{ |
|
446 |
$promote_price = 0; |
|
447 |
} |
|
448 |
|
|
449 |
/* 处理商品水印图片 */ |
|
450 |
/* 处理商品水印图片 */ |
|
451 |
$watermark_img = ''; |
|
452 |
|
|
453 |
if ($promote_price != 0) |
|
454 |
{ |
|
455 |
$watermark_img = "watermark_promote_small"; |
|
456 |
} |
|
457 |
elseif ($row['is_new'] != 0) |
|
458 |
{ |
|
459 |
$watermark_img = "watermark_new_small"; |
|
460 |
} |
|
461 |
elseif ($row['is_best'] != 0) |
|
462 |
{ |
|
463 |
$watermark_img = "watermark_best_small"; |
|
464 |
} |
|
465 |
elseif ($row['is_hot'] != 0) |
|
466 |
{ |
|
467 |
$watermark_img = 'watermark_hot_small'; |
|
468 |
} |
|
469 |
|
|
470 |
if ($watermark_img != '') |
|
471 |
{ |
|
472 |
$arr[$row['goods_id']]['watermark_img'] = $watermark_img; |
|
473 |
} |
|
474 |
|
|
475 |
$arr[$row['goods_id']]['goods_id'] = $row['goods_id']; |
|
476 |
if($display == 'grid') |
|
477 |
{ |
|
478 |
$arr[$row['goods_id']]['goods_name'] = $row['goods_name']; |
|
479 |
} |
|
480 |
else |
|
481 |
{ |
|
482 |
$arr[$row['goods_id']]['goods_name'] = $row['goods_name']; |
|
483 |
} |
|
484 |
$arr[$row['goods_id']]['goods_id'] = $row['goods_id']; |
|
485 |
$arr[$row['goods_id']]['type'] = $row['goods_type']; |
|
486 |
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); |
|
487 |
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); |
|
488 |
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ''; |
|
489 |
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; |
|
490 |
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
491 |
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
492 |
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); |
|
493 |
|
|
494 |
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; |
|
495 |
$arr[$row['goods_id']]['is_best'] = $row['is_best']; |
|
496 |
$arr[$row['goods_id']]['goods_number'] = $row['goods_number']; |
|
497 |
$arr[$row['goods_id']]['pro_end_time'] = local_date('Y-m-d H:i:s', $row['promote_end_date']); |
|
498 |
|
|
499 |
$time = gmtime(); |
|
500 |
if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date']) |
|
501 |
{ |
|
502 |
$arr[$row['goods_id']]['gmt_end_time'] = local_date('M d, Y H:i:s',$row['promote_end_date']); |
|
503 |
} |
|
504 |
else |
|
505 |
{ |
|
506 |
$arr[$row['goods_id']]['gmt_end_time'] = 0; |
|
507 |
} |
|
508 |
|
|
509 |
|
|
510 |
if($row['shop_price'] != 0) |
|
511 |
{ |
|
512 |
$arr[$row['goods_id']]['zhekou'] = $row['zhekou']; |
|
513 |
} |
|
514 |
|
|
515 |
$arr[$row['goods_id']]['jiesheng'] = $row['shop_price'] - $row['promote_price']; |
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
$arr[$row['goods_id']]['count1'] = selled_count($row['goods_id']); |
|
520 |
|
|
521 |
} |
|
522 |
|
|
523 |
if($display == 'grid') |
|
524 |
{ |
|
525 |
if(count($arr) % 2 != 0) |
|
526 |
{ |
|
527 |
$arr[] = array(); |
|
528 |
} |
|
529 |
} |
|
530 |
$smarty->assign('goods_list', $arr); |
|
531 |
$smarty->assign('category', $category); |
|
532 |
$smarty->assign('keywords', htmlspecialchars(stripslashes($_REQUEST['keywords']))); |
|
533 |
$smarty->assign('search_keywords', stripslashes(htmlspecialchars_decode($_REQUEST['keywords']))); |
|
534 |
$smarty->assign('brand', $_REQUEST['brand']); |
|
535 |
$smarty->assign('min_price', $min_price); |
|
536 |
$smarty->assign('max_price', $max_price); |
|
537 |
$smarty->assign('outstock', $_REQUEST['outstock']); |
|
538 |
|
|
539 |
/* 分页 */ |
|
540 |
$url_format = "search.php?category=$category&keywords=" . urlencode(stripslashes($_REQUEST['keywords'])) . "&brand=" . $_REQUEST['brand']."&action=".$action."&goods_type=" . $_REQUEST['goods_type'] . "&sc_ds=" . $_REQUEST['sc_ds']; |
|
541 |
if (!empty($intromode)) |
|
542 |
{ |
|
543 |
$url_format .= "&intro=" . $intromode; |
|
544 |
} |
|
545 |
if (isset($_REQUEST['pickout'])) |
|
546 |
{ |
|
547 |
$url_format .= '&pickout=1'; |
|
548 |
} |
|
549 |
$url_format .= "&min_price=" . $_REQUEST['min_price'] ."&max_price=" . $_REQUEST['max_price'] . "&sort=$sort"; |
|
550 |
|
|
551 |
$url_format .= "$attr_url&order=$order&page="; |
|
552 |
|
|
553 |
$pager['search'] = array( |
|
554 |
'keywords' => stripslashes(urlencode($_REQUEST['keywords'])), |
|
555 |
'category' => $category, |
|
556 |
'brand' => $_REQUEST['brand'], |
|
557 |
'sort' => $sort, |
|
558 |
'order' => $order, |
|
559 |
'min_price' => $_REQUEST['min_price'], |
|
560 |
'max_price' => $_REQUEST['max_price'], |
|
561 |
'action' => $action, |
|
562 |
'intro' => empty($intromode) ? '' : trim($intromode), |
|
563 |
'goods_type' => $_REQUEST['goods_type'], |
|
564 |
'sc_ds' => $_REQUEST['sc_ds'], |
|
565 |
'outstock' => $_REQUEST['outstock'] |
|
566 |
); |
|
567 |
$pager['search'] = array_merge($pager['search'], $attr_arg); |
|
568 |
|
|
569 |
$pager = get_pager('pro_search.php', $pager['search'], $count, $page, $size); |
|
570 |
$pager['display'] = $display; |
|
571 |
$pager['sort'] = $sort; |
|
572 |
$pager['order'] = $order; |
|
573 |
$pager['category'] = $category; |
|
574 |
$sql_pcat = "SELECT parent_id FROM " . $ecs->table('category') . " WHERE cat_id = " . $category; |
|
575 |
$pcat = $db->getOne($sql_pcat); |
|
576 |
$pcategory = ($pcat == '0' ? $category : $pcat); |
|
577 |
$pager['pcategory'] = $pcategory; |
|
578 |
|
|
579 |
$smarty->assign('url_format', $url_format); |
|
580 |
$smarty->assign('pager', $pager); |
|
581 |
|
|
582 |
assign_template(); |
|
583 |
assign_dynamic('search'); |
|
584 |
$position = assign_ur_here(0, $ur_here . ($_REQUEST['keywords'] ? '_' . $_REQUEST['keywords'] : '')); |
|
585 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
586 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
587 |
$smarty->assign('intromode', $intromode); |
|
588 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
589 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
590 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
591 |
$smarty->assign('promotion_info', get_promotion_info()); |
|
592 |
|
|
593 |
$smarty->assign('categories_pro', get_categories_tree2()); // 分类树 |
|
594 |
$smarty->assign('list_default_sort', $default_sort_order_type); |
|
595 |
|
|
596 |
$smarty->display('pro_search.dwt'); |
|
597 |
} |
|
598 |
|
|
599 |
/*------------------------------------------------------ */ |
|
600 |
//-- PRIVATE FUNCTION |
|
601 |
/*------------------------------------------------------ */ |
|
602 |
/** |
|
603 |
* |
|
604 |
* |
|
605 |
* @access public |
|
606 |
* @param |
|
607 |
* |
|
608 |
* @return void |
|
609 |
*/ |
|
610 |
function is_not_null($value) |
|
611 |
{ |
|
612 |
if (is_array($value)) |
|
613 |
{ |
|
614 |
return (!empty($value['from'])) || (!empty($value['to'])); |
|
615 |
} |
|
616 |
else |
|
617 |
{ |
|
618 |
return !empty($value); |
|
619 |
} |
|
620 |
} |
|
621 |
|
|
622 |
/** |
|
623 |
* 获得可以检索的属性 |
|
624 |
* |
|
625 |
* @access public |
|
626 |
* @params integer $cat_id |
|
627 |
* @return void |
|
628 |
*/ |
|
629 |
function get_seachable_attributes($cat_id = 0) |
|
630 |
{ |
|
631 |
$attributes = array( |
|
632 |
'cate' => array(), |
|
633 |
'attr' => array() |
|
634 |
); |
|
635 |
|
|
636 |
/* 获得可用的商品类型 */ |
|
637 |
$sql = "SELECT t.cat_id, cat_name FROM " .$GLOBALS['ecs']->table('goods_type'). " AS t, ". |
|
638 |
$GLOBALS['ecs']->table('attribute') ." AS a". |
|
639 |
" WHERE t.cat_id = a.cat_id AND t.enabled = 1 AND a.attr_index > 0 "; |
|
640 |
$cat = $GLOBALS['db']->getAll($sql); |
|
641 |
|
|
642 |
/* 获取可以检索的属性 */ |
|
643 |
if (!empty($cat)) |
|
644 |
{ |
|
645 |
foreach ($cat AS $val) |
|
646 |
{ |
|
647 |
$attributes['cate'][$val['cat_id']] = $val['cat_name']; |
|
648 |
} |
|
649 |
$where = $cat_id > 0 ? ' AND a.cat_id = ' . $cat_id : " AND a.cat_id = " . $cat[0]['cat_id']; |
|
650 |
|
|
651 |
$sql = 'SELECT attr_id, attr_name, attr_input_type, attr_type, attr_values, attr_index, sort_order ' . |
|
652 |
' FROM ' . $GLOBALS['ecs']->table('attribute') . ' AS a ' . |
|
653 |
' WHERE a.attr_index > 0 ' .$where. |
|
654 |
' ORDER BY cat_id, sort_order ASC'; |
|
655 |
$res = $GLOBALS['db']->query($sql); |
|
656 |
|
|
657 |
while ($row = $GLOBALS['db']->FetchRow($res)) |
|
658 |
{ |
|
659 |
if ($row['attr_index'] == 1 && $row['attr_input_type'] == 1) |
|
660 |
{ |
|
661 |
$row['attr_values'] = str_replace("\r", '', $row['attr_values']); |
|
662 |
$options = explode("\n", $row['attr_values']); |
|
663 |
|
|
664 |
$attr_value = array(); |
|
665 |
foreach ($options AS $opt) |
|
666 |
{ |
|
667 |
$attr_value[$opt] = $opt; |
|
668 |
} |
|
669 |
$attributes['attr'][] = array( |
|
670 |
'id' => $row['attr_id'], |
|
671 |
'attr' => $row['attr_name'], |
|
672 |
'options' => $attr_value, |
|
673 |
'type' => 3 |
|
674 |
); |
|
675 |
} |
|
676 |
else |
|
677 |
{ |
|
678 |
$attributes['attr'][] = array( |
|
679 |
'id' => $row['attr_id'], |
|
680 |
'attr' => $row['attr_name'], |
|
681 |
'type' => $row['attr_index'] |
|
682 |
); |
|
683 |
} |
|
684 |
} |
|
685 |
} |
|
686 |
|
|
687 |
return $attributes; |
|
688 |
} |
|
689 |
|
|
690 |
/** |
|
691 |
* ============================================================================ |
|
692 |
* 文章自定义数据调用函数 |
|
693 |
* ============================================================================ |
|
694 |
*/ |
|
695 |
//取得文章里面的图片 |
|
696 |
function GetImageSrc($body) { |
|
697 |
if( !isset($body) ) { |
|
698 |
return ''; |
|
699 |
} |
|
700 |
else { |
|
701 |
preg_match_all ("/<(img|IMG)(.*)(src|SRC)=[\"|'|]{0,}([h|\/].*(jpg|JPG|gif|GIF|png|PNG))[\"|'|\s]{0,}/isU",$body,$out); |
|
702 |
return $out[4]; |
|
703 |
} |
|
704 |
} |
|
705 |
|
|
706 |
//提取文里面的URL |
|
707 |
function GetArticleUrl($body) { |
|
708 |
if( !isset($body) ) { |
|
709 |
return ''; |
|
710 |
} |
|
711 |
else { |
|
712 |
preg_match_all("/<(a|A)(.*)(href|HREF)=[\"|'|](.*)[\"|'|\s]{0,}>(.*)<\/(a|A)>/isU",$body,$out); |
|
713 |
return $out; |
|
714 |
} |
|
715 |
} |
|
716 |
|
|
717 |
function get_article_children_new ($cat = 0) |
|
718 |
{ |
|
719 |
return db_create_in(array_unique(array_merge(array($cat), array_keys(article_cat_list($cat, 0, false)))), 'a.cat_id'); |
|
720 |
} |
|
721 |
|
|
722 |
/** |
|
723 |
* 按文章ID号/分类ID/商品ID号/商品分类ID号取得文章 |
|
724 |
* @param array $id 文章ID或文章分类ID |
|
725 |
* @param string $getwhat 以何种方式取文章其中可选参数有: |
|
726 |
[1]art_cat(以文章分类ID获取) [2]art_id(以文章ID获取) |
|
727 |
[3]goods_cat(以商品分类ID获取) [4]goods_id(以商品ID获取) |
|
728 |
其中的[3]和[4]必须有商品关联文章或文章关联商品 |
|
729 |
* @param integer $num 控制显示多少条文章.当参数为0时则全部显示 |
|
730 |
* @param integer $start 从第几条数据开始取 |
|
731 |
* @param boolean $isrand 是否随机显示文章(默认为不显示) |
|
732 |
* @param boolean $showall 是否显示隐藏的文章(黑认为不显示隐藏文章) |
|
733 |
* @return array |
|
734 |
*/ |
|
735 |
function get_article_new( $id = array(0), $getwhat = 'art_id', $num = 0, $isrand = false, $showall = true, $start = 0 ) { |
|
736 |
$sql = ''; |
|
737 |
$findkey = ''; |
|
738 |
$search = ''; |
|
739 |
$wherestr = ''; |
|
740 |
|
|
741 |
for( $i=0; $i<count($id); $i++ ) { |
|
742 |
if( $i<count($id)-1 ) { |
|
743 |
$findkey .= $id[$i] .','; |
|
744 |
} |
|
745 |
else { |
|
746 |
$findkey .= $id[$i]; |
|
747 |
} |
|
748 |
} |
|
749 |
|
|
750 |
if( $getwhat == 'art_cat' ){ |
|
751 |
for( $i=0; $i<count($id); $i++ ) { |
|
752 |
if( $i<count($id)-1 ) { |
|
753 |
$search .= get_article_children_new($id[$i]) . ' OR '; |
|
754 |
} |
|
755 |
else { |
|
756 |
$search .= get_article_children_new($id[$i]); |
|
757 |
} |
|
758 |
} |
|
759 |
} |
|
760 |
elseif($getwhat == 'goods_cat') { |
|
761 |
for( $i=0; $i<count($id); $i++) { |
|
762 |
if( $i<count($id)-1 ) { |
|
763 |
$search .= get_children($id[$i]) . ' OR '; |
|
764 |
} |
|
765 |
else { |
|
766 |
$search .= get_children($id[$i]); |
|
767 |
} |
|
768 |
} |
|
769 |
} |
|
770 |
elseif( $getwhat == 'art_id' ) { |
|
771 |
$search = 'a.article_id IN' . '(' . $findkey . ')'; |
|
772 |
} |
|
773 |
elseif( $getwhat == 'goods_id' ) { |
|
774 |
$search = 'g.goods_id IN' . '(' . $findkey . ')'; |
|
775 |
} |
|
776 |
$wherestr = '(' . $search . ')'; |
|
777 |
|
|
778 |
if( $getwhat == 'art_cat' || $getwhat == 'art_id' ) { |
|
779 |
$sql = 'SELECT a.*,ac.cat_id,ac.cat_name,ac.keywords as cat_keywords,ac.cat_desc |
|
780 |
FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' . |
|
781 |
$GLOBALS['ecs']->table('article_cat') . ' AS ac' . |
|
782 |
' WHERE (a.cat_id = ac.cat_id) AND ' . $wherestr; |
|
783 |
} |
|
784 |
elseif( $getwhat == 'goods_cat' || $getwhat == 'goods_id' ) { |
|
785 |
$sql = 'SELECT DISTINCT a.*,ac.cat_id,ac.cat_name,ac.keywords as cat_keywords,ac.cat_desc FROM ' . |
|
786 |
$GLOBALS['ecs']->table('goods') .' AS g ' . |
|
787 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods_article') . ' AS ga ON g.goods_id=ga.goods_id INNER JOIN ' . |
|
788 |
$GLOBALS['ecs']->table('article') . ' AS a ON ga.article_id = a.article_id, ' . |
|
789 |
$GLOBALS['ecs']->table('article_cat') . 'AS ac ' . |
|
790 |
'WHERE (a.cat_id = ac.cat_id) AND ' . $wherestr; |
|
791 |
} |
|
792 |
|
|
793 |
|
|
794 |
if( ($showall == false) && ( $getwhat == 'art_cat' || $getwhat == 'art_id' ) ) { |
|
795 |
$sql .= ' AND a.is_open=1'; |
|
796 |
} |
|
797 |
elseif( ($showall == false) && ( $getwhat == 'goods_cat' || $getwhat == 'goods_id' ) ) { |
|
798 |
$sql .= ' AND a.is_open=1'; |
|
799 |
} |
|
800 |
|
|
801 |
if( $isrand == true ) { |
|
802 |
$sql .= ' ORDER BY rand()'; |
|
803 |
} |
|
804 |
elseif( ($isrand == false) && ( $getwhat == 'art_cat' || $getwhat == 'art_id' ) ) { |
|
805 |
$sql .= ' ORDER BY a.add_time DESC, a.article_id DESC'; |
|
806 |
} |
|
807 |
elseif( ($isrand == false) && ( $getwhat == 'goods_cat' || $getwhat == 'goods_id' ) ) { |
|
808 |
$sql .= ' ORDER BY a.add_time DESC, a.article_id DESC'; |
|
809 |
} |
|
810 |
|
|
811 |
if( $start == 0 && $num>0 ) { |
|
812 |
$sql .= ' LIMIT ' . $num; |
|
813 |
} |
|
814 |
elseif( $start>0 && $num>0 ) { |
|
815 |
$sql .= ' LIMIT ' . $start . ',' . $num; |
|
816 |
} |
|
817 |
|
|
818 |
//开始查询 |
|
819 |
$arr = $GLOBALS['db']->getAll($sql); |
|
820 |
$articles = array(); |
|
821 |
foreach ($arr AS $id => $row) { |
|
822 |
$articles[$id]['cat_id'] = $row['cat_id']; |
|
823 |
$articles[$id]['cat_name'] = $row['cat_name']; |
|
824 |
$articles[$id]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id'])); |
|
825 |
$articles[$id]['cat_keywords'] = $row['cat_keywords']; |
|
826 |
$articles[$id]['cat_desc'] = $row['cat_desc']; |
|
827 |
$articles[$id]['title'] = $row['title']; |
|
828 |
$articles[$id]['url'] = build_uri('article', array('aid'=>$row['article_id']), $row['title']); |
|
829 |
$articles[$id]['author'] = $row['author']; |
|
830 |
$articles[$id]['content'] = $row['content']; |
|
831 |
$articles[$id]['keywords'] = $row['keywords']; |
|
832 |
$articles[$id]['file_url'] = $row['file_url']; |
|
833 |
$articles[$id]['link'] = $row['link']; |
|
834 |
$articles[$id]['addtime'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); |
|
835 |
$articles[$id]['content'] = $row['content']; |
|
836 |
$imgsrc = GetImageSrc($row['content']); |
|
837 |
$articles[$id]['img'] = $imgsrc; //提取文章中所有的图片 |
|
838 |
$link = GetArticleUrl($row['content']); |
|
839 |
$articles[$id]['link_url'] = $link[4]; //提取文章中所有的链接地址 |
|
840 |
$articles[$id]['link_title'] = $link[5]; //提取文章中所有的链接名称 |
|
841 |
} |
|
842 |
return $articles; |
|
843 |
} |
|
844 |
|
|
845 |
function get_categories_tree2() |
|
846 |
{ |
|
847 |
$now = gmtime(); |
|
848 |
$sql_a = "SELECT DISTINCT(cat_id) FROM " . $GLOBALS['ecs']->table('goods') . " WHERE is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 AND is_promote = 1 AND promote_start_date <= " . $now . " AND promote_end_date >= " . $now; |
|
849 |
$cat_a = $GLOBALS['db']->getCol($sql_a); |
|
850 |
|
|
851 |
$top_id = array(); |
|
852 |
$sec_id = array(); |
|
853 |
$cat = array(); |
|
854 |
foreach($cat_a as $cat_aa) |
|
855 |
{ |
|
856 |
|
|
857 |
$top_id[] = get_pid($cat_aa); |
|
858 |
$sec_id[] = get_2($cat_aa); |
|
859 |
} |
|
860 |
$top_id = array_unique($top_id); |
|
861 |
$sec_id = array_unique($sec_id); |
|
862 |
|
|
863 |
if (count($top_id) > 0) |
|
864 |
{ |
|
865 |
/* 获取当前分类及其子分类 */ |
|
866 |
$where_top_id = count($top_id) == 1 ? " = " . $top_id[0] : " in (" . implode(',', $top_id) . ") "; |
|
867 |
|
|
868 |
$sql = "SELECT cat_id, cat_name, is_show " . |
|
869 |
" FROM " . $GLOBALS['ecs']->table('category') . |
|
870 |
" WHERE cat_id " . $where_top_id . " ORDER BY sort_order ASC, cat_id ASC"; |
|
871 |
|
|
872 |
$res = $GLOBALS['db']->getAll($sql); |
|
873 |
|
|
874 |
foreach ($res AS $row) |
|
875 |
{ |
|
876 |
if ($row['is_show']) |
|
877 |
{ |
|
878 |
$cat_arr[$row['cat_id']]['id'] = $row['cat_id']; |
|
879 |
$cat_arr[$row['cat_id']]['name'] = $row['cat_name']; |
|
880 |
$cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); |
|
881 |
|
|
882 |
if (isset($row['cat_id']) != NULL) |
|
883 |
{ |
|
884 |
$cat_arr[$row['cat_id']]['cat_id'] = get_child_tree2($row['cat_id'], $sec_id); |
|
885 |
} |
|
886 |
} |
|
887 |
} |
|
888 |
} |
|
889 |
|
|
890 |
if(isset($cat_arr)) |
|
891 |
{ |
|
892 |
return $cat_arr; |
|
893 |
} |
|
894 |
} |
|
895 |
|
|
896 |
function get_pid($cid) |
|
897 |
{ |
|
898 |
$pid = $GLOBALS['db']->getOne("SELECT parent_id FROM " . $GLOBALS['ecs']->table('category') . " WHERE cat_id = " . $cid); |
|
899 |
if ($pid > 0) |
|
900 |
{ |
|
901 |
$cid = get_pid($pid); |
|
902 |
} |
|
903 |
return $cid; |
|
904 |
} |
|
905 |
|
|
906 |
function get_2($cid, $bid = 0) |
|
907 |
{ |
|
908 |
$pid = $GLOBALS['db']->getOne("SELECT parent_id FROM " . $GLOBALS['ecs']->table('category') . " WHERE cat_id = " . $cid); |
|
909 |
if ($pid != 0) |
|
910 |
{ |
|
911 |
$bid = get_2($pid, $cid); |
|
912 |
} |
|
913 |
return $bid; |
|
914 |
} |
|
915 |
|
|
916 |
function get_child_tree2($tree_id = 0, $where) |
|
917 |
{ |
|
918 |
$three_arr = array(); |
|
919 |
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 "; |
|
920 |
if ($GLOBALS['db']->getOne($sql) || $tree_id == 0) |
|
921 |
{ |
|
922 |
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' . |
|
923 |
'FROM ' . $GLOBALS['ecs']->table('category') . |
|
924 |
"WHERE parent_id = '$tree_id' AND is_show = 1 AND cat_id in (" . implode(',', $where) . ") ORDER BY sort_order ASC, cat_id ASC"; |
|
925 |
$res = $GLOBALS['db']->getAll($child_sql); |
|
926 |
foreach ($res AS $row) |
|
927 |
{ |
|
928 |
if ($row['is_show']) |
|
929 |
|
|
930 |
$three_arr[$row['cat_id']]['id'] = $row['cat_id']; |
|
931 |
$three_arr[$row['cat_id']]['name'] = $row['cat_name']; |
|
932 |
$three_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); |
|
933 |
|
|
934 |
if (isset($row['cat_id']) != NULL) |
|
935 |
{ |
|
936 |
$three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']); |
|
937 |
|
|
938 |
} |
|
939 |
} |
|
940 |
} |
|
941 |
return $three_arr; |
|
942 |
} |
|
943 |
|
|
944 |
function current_time() |
|
945 |
{ |
|
946 |
$time = gmtime(); |
|
947 |
//时区转换 |
|
948 |
$time = local_date('Y-m-d', $time); |
|
949 |
|
|
950 |
return $time; |
|
951 |
} |
|
952 |
?> |