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 |
elseif (isset($_REQUEST['category'])) |
|
14 |
{ |
|
15 |
$cat_id = intval($_REQUEST['category']); |
|
16 |
} |
|
17 |
else |
|
18 |
{ |
|
19 |
/* 如果分类ID为0,则返回首页 */ |
|
20 |
ecs_header("Location: ./\n"); |
|
21 |
|
|
22 |
exit; |
|
23 |
} |
|
24 |
|
|
25 |
|
|
26 |
/* 初始化分页信息 */ |
|
27 |
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1; |
|
28 |
$brand = isset($_REQUEST['brand']) && intval($_REQUEST['brand']) > 0 ? intval($_REQUEST['brand']) : 0; |
|
29 |
$price_max = isset($_REQUEST['price_max']) && intval($_REQUEST['price_max']) > 0 ? intval($_REQUEST['price_max']) : 0; |
|
30 |
$price_min = isset($_REQUEST['price_min']) && intval($_REQUEST['price_min']) > 0 ? intval($_REQUEST['price_min']) : 0; |
|
31 |
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10; |
|
32 |
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'shop_price', 'last_update'))) ? 'g.'.trim($_REQUEST['sort']) : 'g.goods_id'; |
|
33 |
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : 'DESC'; |
|
34 |
/*------------------------------------------------------ */ |
|
35 |
//-- PROCESSOR |
|
36 |
/*------------------------------------------------------ */ |
|
37 |
|
|
38 |
/* 页面的缓存ID */ |
|
39 |
$cache_id = sprintf('%X', crc32($cat_id . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' . |
|
40 |
$_CFG['lang'] .'-'. $brand. '-' . $price_max . '-' .$price_min . '-' . $filter_attr_str.'-'.$_GET['suppId'])); |
|
41 |
|
|
42 |
if (!$smarty->is_cached('category.dwt', $cache_id)) |
|
43 |
{ |
|
44 |
assign_template(); |
|
45 |
assign_template_supplier(); |
|
46 |
$position = assign_ur_here(); |
|
47 |
|
|
48 |
//$hereinfo = get_categories_tree($cat_id); |
|
49 |
|
|
50 |
//$ur_here = "<a href='supplier.php?suppId=".$_GET['suppId']."'>店铺首页</a> <code>></code> <a href='".$hereinfo[$cat_id]['url']."'>".$hereinfo[$cat_id]['name']."</a>"; |
|
51 |
|
|
52 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
53 |
//$smarty->assign('ur_here', $ur_here); // 当前位置 |
|
54 |
|
|
55 |
|
|
56 |
$smarty->assign('categories', get_categories_tree_supplier()); // 分类树 |
|
57 |
|
|
58 |
|
|
59 |
$children = get_children_supplier($cat_id); |
|
60 |
|
|
61 |
$cat = get_cat_info_supplier($cat_id); // 获得分类的相关信息 |
|
62 |
|
|
63 |
if (!empty($cat)) |
|
64 |
{ |
|
65 |
$smarty->assign('keywords', htmlspecialchars($cat['keywords'])); |
|
66 |
$smarty->assign('description', htmlspecialchars($cat['cat_desc'])); |
|
67 |
$smarty->assign('cat_style', htmlspecialchars($cat['style'])); |
|
68 |
} |
|
69 |
else |
|
70 |
{ |
|
71 |
/* 如果分类不存在则返回首页 */ |
|
72 |
ecs_header("Location: index.php"); |
|
73 |
|
|
74 |
exit; |
|
75 |
} |
|
76 |
|
|
77 |
if($cat['is_show'] >0 && $cat['is_show_cat_pic'] >0){ |
|
78 |
$smarty->assign('cat_pic', $cat['cat_pic']); |
|
79 |
$smarty->assign('cat_pic_url', $cat['cat_pic_url']); |
|
80 |
}else{ |
|
81 |
$smarty->assign('cat_pic', ''); |
|
82 |
$smarty->assign('cat_pic_url', ''); |
|
83 |
} |
|
84 |
|
|
85 |
/* 获取价格分级 */ |
|
86 |
if ($cat['grade'] == 0 && $cat['parent_id'] != 0) |
|
87 |
{ |
|
88 |
$cat['grade'] = get_parent_grade($cat_id); //如果当前分类级别为空,取最近的上级分类 |
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
if ($cat['grade'] > 1) |
|
93 |
{ |
|
94 |
//echo "<pre>"; |
|
95 |
//print_r($cat); |
|
96 |
/* 需要价格分级 */ |
|
97 |
|
|
98 |
/* |
|
99 |
算法思路: |
|
100 |
1、当分级大于1时,进行价格分级 |
|
101 |
2、取出该类下商品价格的最大值、最小值 |
|
102 |
3、根据商品价格的最大值来计算商品价格的分级数量级: |
|
103 |
价格范围(不含最大值) 分级数量级 |
|
104 |
0-0.1 0.001 |
|
105 |
0.1-1 0.01 |
|
106 |
1-10 0.1 |
|
107 |
10-100 1 |
|
108 |
100-1000 10 |
|
109 |
1000-10000 100 |
|
110 |
4、计算价格跨度: |
|
111 |
取整((最大值-最小值) / (价格分级数) / 数量级) * 数量级 |
|
112 |
5、根据价格跨度计算价格范围区间 |
|
113 |
6、查询数据库 |
|
114 |
|
|
115 |
可能存在问题: |
|
116 |
1、 |
|
117 |
由于价格跨度是由最大值、最小值计算出来的 |
|
118 |
然后再通过价格跨度来确定显示时的价格范围区间 |
|
119 |
所以可能会存在价格分级数量不正确的问题 |
|
120 |
该问题没有证明 |
|
121 |
2、 |
|
122 |
当价格=最大值时,分级会多出来,已被证明存在 |
|
123 |
*/ |
|
124 |
|
|
125 |
$sql = "SELECT min(sgc.shop_price) AS min, max(sgc.shop_price) as max ". |
|
126 |
" FROM " . $ecs->table('goods'). " AS sgc ". |
|
127 |
" WHERE ($children OR " . get_extension_goods_supplier($children) . ') AND sgc.is_delete = 0 AND sgc.is_on_sale = 1 AND sgc.is_alone_sale = 1 '; |
|
128 |
//获得当前分类下商品价格的最大值、最小值 |
|
129 |
|
|
130 |
$row = $db->getRow($sql); |
|
131 |
|
|
132 |
// 取得价格分级最小单位级数,比如,千元商品最小以100为级数 |
|
133 |
$price_grade = 0.0001; |
|
134 |
for($i=-2; $i<= log10($row['max']); $i++) |
|
135 |
{ |
|
136 |
$price_grade *= 10; |
|
137 |
} |
|
138 |
|
|
139 |
//跨度 |
|
140 |
$dx = ceil(($row['max'] - $row['min']) / ($cat['grade']) / $price_grade) * $price_grade; |
|
141 |
if($dx == 0) |
|
142 |
{ |
|
143 |
$dx = $price_grade; |
|
144 |
} |
|
145 |
|
|
146 |
for($i = 1; $row['min'] > $dx * $i; $i ++); |
|
147 |
|
|
148 |
for($j = 1; $row['min'] > $dx * ($i-1) + $price_grade * $j; $j++); |
|
149 |
$row['min'] = $dx * ($i-1) + $price_grade * ($j - 1); |
|
150 |
|
|
151 |
for(; $row['max'] >= $dx * $i; $i ++); |
|
152 |
$row['max'] = $dx * ($i) + $price_grade * ($j - 1); |
|
153 |
|
|
154 |
$sql = "SELECT (FLOOR((sgc.shop_price - $row[min]) / $dx)) AS sn, COUNT(*) AS goods_num ". |
|
155 |
" FROM " . $ecs->table('goods') . " AS sgc ". |
|
156 |
" WHERE ($children OR " . get_extension_goods_supplier($children) . ') AND sgc.is_delete = 0 AND sgc.is_on_sale = 1 AND sgc.is_alone_sale = 1 '. |
|
157 |
" GROUP BY sn "; |
|
158 |
|
|
159 |
$price_grade = $db->getAll($sql); |
|
160 |
|
|
161 |
foreach ($price_grade as $key=>$val) |
|
162 |
{ |
|
163 |
$temp_key = $key + 1; |
|
164 |
$price_grade[$temp_key]['goods_num'] = $val['goods_num']; |
|
165 |
$price_grade[$temp_key]['start'] = $row['min'] + round($dx * $val['sn']); |
|
166 |
$price_grade[$temp_key]['end'] = $row['min'] + round($dx * ($val['sn'] + 1)); |
|
167 |
$price_grade[$temp_key]['price_range'] = $price_grade[$temp_key]['start'] . ' - ' . $price_grade[$temp_key]['end']; |
|
168 |
$price_grade[$temp_key]['formated_start'] = price_format($price_grade[$temp_key]['start']); |
|
169 |
$price_grade[$temp_key]['formated_end'] = price_format($price_grade[$temp_key]['end']); |
|
170 |
$price_grade[$temp_key]['url'] = build_uri('supplier', array('go'=>'category','suppid'=>$_GET['suppId'],'cid'=>$cat_id, 'bid'=>$brand, 'price_min'=>$price_grade[$temp_key]['start'], 'price_max'=> $price_grade[$temp_key]['end'], 'filter_attr'=>$filter_attr_str), $cat['cat_name']); |
|
171 |
|
|
172 |
/* 判断价格区间是否被选中 */ |
|
173 |
if (isset($_REQUEST['price_min']) && $price_grade[$temp_key]['start'] == $price_min && $price_grade[$temp_key]['end'] == $price_max) |
|
174 |
{ |
|
175 |
$price_grade[$temp_key]['selected'] = 1; |
|
176 |
} |
|
177 |
else |
|
178 |
{ |
|
179 |
$price_grade[$temp_key]['selected'] = 0; |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
$price_grade[0]['start'] = 0; |
|
184 |
$price_grade[0]['end'] = 0; |
|
185 |
$price_grade[0]['price_range'] = $_LANG['all_attribute']; |
|
186 |
$price_grade[0]['url'] = build_uri('supplier', array('go'=>'category','suppid'=>$_GET['suppId'],'cid'=>$cat_id, 'bid'=>$brand, 'price_min'=>0, 'price_max'=> 0, 'filter_attr'=>$filter_attr_str), $cat['cat_name']); |
|
187 |
$price_grade[0]['selected'] = empty($price_max) ? 1 : 0; |
|
188 |
|
|
189 |
$smarty->assign('price_grade', $price_grade); |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
/* 品牌筛选 */ |
|
194 |
|
|
195 |
$sql = "SELECT b.brand_id, b.brand_name, COUNT(*) AS goods_num ". |
|
196 |
"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ". |
|
197 |
$GLOBALS['ecs']->table('goods') . " AS sgc LEFT JOIN ". $GLOBALS['ecs']->table('goods_cat') . " AS gc ON sgc.goods_id = gc.goods_id " . |
|
198 |
"WHERE sgc.brand_id = b.brand_id AND ($children OR " . 'gc.cat_id ' . db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list_supplier($cat_id, 0, false))))) . ") AND b.is_show = 1 " . |
|
199 |
" AND sgc.is_on_sale = 1 AND sgc.is_alone_sale = 1 AND sgc.is_delete = 0 ". |
|
200 |
"GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY b.sort_order, b.brand_id ASC"; |
|
201 |
|
|
202 |
$brands = $GLOBALS['db']->getAll($sql); |
|
203 |
|
|
204 |
foreach ($brands AS $key => $val) |
|
205 |
{ |
|
206 |
$temp_key = $key + 1; |
|
207 |
$brands[$temp_key]['brand_name'] = $val['brand_name']; |
|
208 |
$brands[$temp_key]['url'] = build_uri('supplier', array('go'=>'category','suppid'=>$_GET['suppId'],'cid' => $cat_id, 'bid' => $val['brand_id'], 'price_min'=>$price_min, 'price_max'=> $price_max, 'filter_attr'=>$filter_attr_str), $cat['cat_name']); |
|
209 |
|
|
210 |
/* 判断品牌是否被选中 */ |
|
211 |
if ($brand == $brands[$key]['brand_id']) |
|
212 |
{ |
|
213 |
$brands[$temp_key]['selected'] = 1; |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
$brands[$temp_key]['selected'] = 0; |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
$brands[0]['brand_name'] = $_LANG['all_attribute']; |
|
222 |
$brands[0]['url'] = build_uri('supplier', array('go'=>'category','suppid'=>$_GET['suppId'],'cid' => $cat_id, 'bid' => 0, 'price_min'=>$price_min, 'price_max'=> $price_max, 'filter_attr'=>$filter_attr_str), $cat['cat_name']); |
|
223 |
$brands[0]['selected'] = empty($brand) ? 1 : 0; |
|
224 |
|
|
225 |
$smarty->assign('brands', $brands); |
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
$count = get_cagtegory_goods_count($children, $brand, $price_min, $price_max); |
|
231 |
//$count = get_cagtegory_goods_count($children, $brand, $price_min, $price_max, $ext); |
|
232 |
$max_page = ($count> 0) ? ceil($count / $size) : 1; |
|
233 |
if ($page > $max_page) |
|
234 |
{ |
|
235 |
$page = $max_page; |
|
236 |
} |
|
237 |
$goodslist = category_get_goods($children, $brand, $price_min, $price_max, $size, $page, $sort, $order); |
|
238 |
//$goodslist = category_get_goods($children, $brand, $price_min, $price_max, $ext, $size, $page, $sort, $order); |
|
239 |
if($display == 'grid') |
|
240 |
{ |
|
241 |
if(count($goodslist) % 2 != 0) |
|
242 |
{ |
|
243 |
$goodslist[] = array(); |
|
244 |
} |
|
245 |
} |
|
246 |
assign_pager('supplier', $cat_id, $count, $size, $sort, $order, $page, '', $brands, $price_min, $price_max, $display, ''); // 分页 |
|
247 |
$smarty->assign('goods_list', $goodslist); |
|
248 |
assign_dynamic('category'); |
|
249 |
} |
|
250 |
|
|
251 |
$smarty->display('category.dwt', $cache_id); |
|
252 |
|
|
253 |
/*------------------------------------------------------ */ |
|
254 |
//-- PRIVATE FUNCTION |
|
255 |
/*------------------------------------------------------ */ |
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
/** |
|
260 |
* 获得分类的信息 |
|
261 |
* |
|
262 |
* @param integer $cat_id |
|
263 |
* |
|
264 |
* @return void |
|
265 |
*/ |
|
266 |
function get_cat_info_supplier($cat_id) |
|
267 |
{ |
|
268 |
return $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id,is_show,is_show_cat_pic,cat_pic,cat_pic_url FROM ' . $GLOBALS['ecs']->table('supplier_category') . |
|
269 |
" WHERE cat_id = '$cat_id'"); |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* 获得分类下的商品 |
|
274 |
* |
|
275 |
* @access public |
|
276 |
* @param string $children |
|
277 |
* @return array |
|
278 |
*/ |
|
279 |
function category_get_goods($children, $brand, $min, $max, $size, $page, $sort, $order) |
|
280 |
{ |
|
281 |
$display = $GLOBALS['display']; |
|
282 |
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ". |
|
283 |
"g.is_delete = 0 AND ($children)"; |
|
284 |
|
|
285 |
if ($brand > 0) |
|
286 |
{ |
|
287 |
$where .= "AND g.brand_id=$brand "; |
|
288 |
} |
|
289 |
|
|
290 |
if ($min > 0) |
|
291 |
{ |
|
292 |
$where .= " AND g.shop_price >= $min "; |
|
293 |
} |
|
294 |
|
|
295 |
if ($max > 0) |
|
296 |
{ |
|
297 |
$where .= " AND g.shop_price <= $max "; |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
/* 获得商品列表 */ |
|
302 |
$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, ' . |
|
303 |
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " . |
|
304 |
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb ,g.original_img, g.goods_img ' . |
|
305 |
'FROM ' . $GLOBALS['ecs']->table('supplier_goods_cat') . ' AS sgc ' . |
|
306 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
307 |
"ON sgc.goods_id = g.goods_id " . |
|
308 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . |
|
309 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " . |
|
310 |
"WHERE $where ORDER BY $sort $order"; |
|
311 |
|
|
312 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); |
|
313 |
$arr = array(); |
|
314 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
315 |
{ |
|
316 |
if ($row['promote_price'] > 0) |
|
317 |
{ |
|
318 |
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); |
|
319 |
} |
|
320 |
else |
|
321 |
{ |
|
322 |
$promote_price = 0; |
|
323 |
} |
|
324 |
|
|
325 |
/* 处理商品水印图片 */ |
|
326 |
$watermark_img = ''; |
|
327 |
|
|
328 |
if ($promote_price != 0) |
|
329 |
{ |
|
330 |
$watermark_img = "watermark_promote_small"; |
|
331 |
} |
|
332 |
elseif ($row['is_new'] != 0) |
|
333 |
{ |
|
334 |
$watermark_img = "watermark_new_small"; |
|
335 |
} |
|
336 |
elseif ($row['is_best'] != 0) |
|
337 |
{ |
|
338 |
$watermark_img = "watermark_best_small"; |
|
339 |
} |
|
340 |
elseif ($row['is_hot'] != 0) |
|
341 |
{ |
|
342 |
$watermark_img = 'watermark_hot_small'; |
|
343 |
} |
|
344 |
|
|
345 |
if ($watermark_img != '') |
|
346 |
{ |
|
347 |
$arr[$row['goods_id']]['watermark_img'] = $watermark_img; |
|
348 |
} |
|
349 |
|
|
350 |
$arr[$row['goods_id']]['goods_id'] = $row['goods_id']; |
|
351 |
if($display == 'grid') |
|
352 |
{ |
|
353 |
$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']; |
|
354 |
} |
|
355 |
else |
|
356 |
{ |
|
357 |
$arr[$row['goods_id']]['goods_name'] = $row['goods_name']; |
|
358 |
} |
|
359 |
$arr[$row['goods_id']]['name'] = $row['goods_name']; |
|
360 |
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; |
|
361 |
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); |
|
362 |
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); |
|
363 |
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); |
|
364 |
$arr[$row['goods_id']]['type'] = $row['goods_type']; |
|
365 |
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ''; |
|
366 |
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
367 |
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
368 |
$arr[$row['goods_id']]['original_img'] = get_image_path($row['goods_id'], $row['original_img']); |
|
369 |
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); |
|
370 |
} |
|
371 |
return $arr; |
|
372 |
} |
|
373 |
|
|
374 |
/** |
|
375 |
* 获得分类下的商品总数 |
|
376 |
* |
|
377 |
* @access public |
|
378 |
* @param string $cat_id |
|
379 |
* @return integer |
|
380 |
*/ |
|
381 |
function get_cagtegory_goods_count($children, $brand, $min, $max) |
|
382 |
{ |
|
383 |
$where = " g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ". |
|
384 |
"g.is_delete = 0 AND ($children)"; |
|
385 |
|
|
386 |
if ($brand > 0) |
|
387 |
{ |
|
388 |
$where .= "AND g.brand_id=$brand "; |
|
389 |
} |
|
390 |
|
|
391 |
if ($min > 0) |
|
392 |
{ |
|
393 |
$where .= " AND g.shop_price >= $min "; |
|
394 |
} |
|
395 |
|
|
396 |
if ($max > 0) |
|
397 |
{ |
|
398 |
$where .= " AND g.shop_price <= $max "; |
|
399 |
} |
|
400 |
|
|
401 |
|
|
402 |
/* 返回商品总数 */ |
|
403 |
$sql = 'SELECT count(distinct g.goods_id) FROM ' . $GLOBALS['ecs']->table('supplier_goods_cat') . ' AS sgc LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
404 |
'ON sgc.goods_id = g.goods_id WHERE '.$where; |
|
405 |
return $GLOBALS['db']->getOne($sql); |
|
406 |
} |
|
407 |
|
|
408 |
/** |
|
409 |
* 取得最近的上级分类的grade值 |
|
410 |
* |
|
411 |
* @access public |
|
412 |
* @param int $cat_id //当前的cat_id |
|
413 |
* |
|
414 |
* @return int |
|
415 |
*/ |
|
416 |
function get_parent_grade($cat_id) |
|
417 |
{ |
|
418 |
static $res = NULL; |
|
419 |
|
|
420 |
if ($res === NULL) |
|
421 |
{ |
|
422 |
$data = read_static_cache('cat_parent_grade_supplier'.$_GET['suppId']); |
|
423 |
if ($data === false) |
|
424 |
{ |
|
425 |
$sql = "SELECT parent_id, cat_id, grade ". |
|
426 |
" FROM " . $GLOBALS['ecs']->table('supplier_category') . "WHERE supplier_id=".$_GET['suppId']; |
|
427 |
$res = $GLOBALS['db']->getAll($sql); |
|
428 |
write_static_cache('cat_parent_grade_supplier'.$_GET['suppId'], $res); |
|
429 |
} |
|
430 |
else |
|
431 |
{ |
|
432 |
$res = $data; |
|
433 |
} |
|
434 |
} |
|
435 |
|
|
436 |
if (!$res) |
|
437 |
{ |
|
438 |
return 0; |
|
439 |
} |
|
440 |
|
|
441 |
$parent_arr = array(); |
|
442 |
$grade_arr = array(); |
|
443 |
|
|
444 |
foreach ($res as $val) |
|
445 |
{ |
|
446 |
$parent_arr[$val['cat_id']] = $val['parent_id']; |
|
447 |
$grade_arr[$val['cat_id']] = $val['grade']; |
|
448 |
} |
|
449 |
|
|
450 |
while ($parent_arr[$cat_id] >0 && $grade_arr[$cat_id] == 0) |
|
451 |
{ |
|
452 |
$cat_id = $parent_arr[$cat_id]; |
|
453 |
} |
|
454 |
|
|
455 |
return $grade_arr[$cat_id]; |
|
456 |
|
|
457 |
} |
|
458 |
|
|
459 |
|
|
460 |
?> |