commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 商品比较程序 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
|
|
9 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
10 |
if (!empty($_REQUEST['goods']) && is_array($_REQUEST['goods']) && count($_REQUEST['goods']) > 1) |
|
11 |
{ |
|
12 |
$where = db_create_in($_REQUEST['goods'], 'id_value'); |
|
13 |
$sql = "SELECT id_value , AVG(comment_rank) AS cmt_rank, COUNT(*) AS cmt_count" . |
|
14 |
" FROM " .$ecs->table('comment') . |
|
15 |
" WHERE $where AND comment_type = 0". |
|
16 |
' GROUP BY id_value '; |
|
17 |
$query = $db->query($sql); |
|
18 |
$cmt = array(); |
|
19 |
while ($row = $db->fetch_array($query)) |
|
20 |
{ |
|
21 |
$cmt[$row['id_value']] = $row; |
|
22 |
} |
|
23 |
|
|
24 |
$where = db_create_in($_REQUEST['goods'], 'g.goods_id'); |
|
25 |
$sql = "SELECT g.goods_id, g.goods_type, g.goods_name, g.shop_price, g.goods_weight, g.goods_thumb, g.goods_brief, ". |
|
26 |
"a.attr_name, v.attr_value, a.attr_id, b.brand_name, ". |
|
27 |
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price " . |
|
28 |
"FROM " .$ecs->table('goods'). " AS g ". |
|
29 |
"LEFT JOIN " . $ecs->table('goods_attr'). " AS v ON v.goods_id = g.goods_id ". |
|
30 |
"LEFT JOIN " . $ecs->table('attribute') . " AS a ON a.attr_id = v.attr_id " . |
|
31 |
"LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " . |
|
32 |
"LEFT JOIN " . $ecs->table('member_price') . " AS mp ". |
|
33 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". |
|
34 |
"WHERE g.is_delete = 0 AND $where ". |
|
35 |
"ORDER BY a.attr_id"; |
|
36 |
$res = $db->query($sql); |
|
37 |
$arr = array(); |
|
38 |
$ids = $_REQUEST['goods']; |
|
39 |
$attr_name = array(); |
|
40 |
$type_id = 0; |
|
41 |
while ($row = $db->fetchRow($res)) |
|
42 |
{ |
|
43 |
$goods_id = $row['goods_id']; |
|
44 |
$type_id = $row['goods_type']; |
|
45 |
$arr[$goods_id]['goods_id'] = $goods_id; |
|
46 |
$arr[$goods_id]['url'] = build_uri('goods', array('gid' => $goods_id), $row['goods_name']); |
|
47 |
$arr[$goods_id]['goods_name'] = $row['goods_name']; |
|
48 |
$arr[$goods_id]['shop_price'] = price_format($row['shop_price']); |
|
49 |
$arr[$goods_id]['rank_price'] = price_format($row['rank_price']); |
|
50 |
$arr[$goods_id]['goods_weight'] = (intval($row['goods_weight']) > 0) ? |
|
51 |
ceil($row['goods_weight']) . $_LANG['kilogram'] : ceil($row['goods_weight'] * 1000) . $_LANG['gram']; |
|
52 |
$arr[$goods_id]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
53 |
$arr[$goods_id]['goods_brief'] = $row['goods_brief']; |
|
54 |
$arr[$goods_id]['brand_name'] = $row['brand_name']; |
|
55 |
$properties = get_goods_properties($goods_id); |
|
56 |
$arr[$goods_id]['spe'] = $properties['spe']; |
|
57 |
$arr[$goods_id]['properties'][$row['attr_id']]['name'] = $row['attr_name']; |
|
58 |
if (!empty($arr[$goods_id]['properties'][$row['attr_id']]['value'])) |
|
59 |
{ |
|
60 |
$arr[$goods_id]['properties'][$row['attr_id']]['value'] .= ',' . $row['attr_value']; |
|
61 |
} |
|
62 |
else |
|
63 |
{ |
|
64 |
$arr[$goods_id]['properties'][$row['attr_id']]['value'] = $row['attr_value']; |
|
65 |
} |
|
66 |
|
|
67 |
if (!isset($arr[$goods_id]['comment_rank'])) |
|
68 |
{ |
|
69 |
$arr[$goods_id]['comment_rank'] = isset($cmt[$goods_id]) ? ceil($cmt[$goods_id]['cmt_rank']) : 0; |
|
70 |
$arr[$goods_id]['comment_number'] = isset($cmt[$goods_id]) ? $cmt[$goods_id]['cmt_count'] : 0; |
|
71 |
$arr[$goods_id]['comment_number'] = sprintf($_LANG['comment_num'], $arr[$goods_id]['comment_number']); |
|
72 |
} |
|
73 |
|
|
74 |
$tmp = $ids; |
|
75 |
$key = array_search($goods_id, $tmp); |
|
76 |
|
|
77 |
if ($key !== null && $key !== false) |
|
78 |
{ |
|
79 |
unset($tmp[$key]); |
|
80 |
} |
|
81 |
|
|
82 |
$arr[$goods_id]['ids'] = !empty($tmp) ? "goods[]=" . implode('&goods[]=', $tmp) : ''; |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
/* 代码修改_start */ |
|
87 |
$smarty->assign('back_url', empty($_GET['back_url']) ? $_SERVER['HTTP_REFERER'] : $_GET['back_url']); |
|
88 |
$sql = "SELECT attr_id,attr_name,attr_group FROM " . $ecs->table('attribute') . " WHERE cat_id='$type_id' ORDER BY attr_id"; |
|
89 |
|
|
90 |
$attribute = array(); |
|
91 |
|
|
92 |
$attribute = $db->getAll($sql); |
|
93 |
$sql = 'select attr_group from ' . $ecs->table('goods_type') . ' where cat_id=' . $type_id; |
|
94 |
$attr_group = $db->getOne($sql); |
|
95 |
$group_list = explode("\n", str_replace("\r", '', $attr_group)); |
|
96 |
|
|
97 |
$attr_list = array(); |
|
98 |
foreach($group_list as $key => $group) |
|
99 |
{ |
|
100 |
$attr_list[$key]['group'] = $key; |
|
101 |
$attr_list[$key]['group_name'] = $group; |
|
102 |
} |
|
103 |
foreach($attribute as $attr) |
|
104 |
{ |
|
105 |
if(isset($attr_list[$attr['attr_group']])) |
|
106 |
$attr_list[$attr['attr_group']]['attribute'][] = $attr; |
|
107 |
} |
|
108 |
foreach($arr as $key => $goods) |
|
109 |
{ |
|
110 |
foreach($attribute as $attr) |
|
111 |
{ |
|
112 |
if(!isset($goods['properties'][$attr['attr_id']])) |
|
113 |
$arr[$key]['properties'][$attr['attr_id']] = array('value' => '-'); |
|
114 |
} |
|
115 |
} |
|
116 |
for($i = count($arr); $i<4; $i++) |
|
117 |
$arr[] = array(); |
|
118 |
$smarty->assign('attr_list', $attr_list); |
|
119 |
/* 代码修改_end */ |
|
120 |
$smarty->assign('goods_list', $arr); |
|
121 |
} |
|
122 |
else |
|
123 |
{ |
|
124 |
show_message($_LANG['compare_no_goods']); |
|
125 |
exit; |
|
126 |
} |
|
127 |
|
|
128 |
assign_template(); |
|
129 |
$position = assign_ur_here(0, $_LANG['goods_compare']); |
|
130 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
131 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
132 |
|
|
133 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
134 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
135 |
|
|
136 |
$url = $_SERVER['REQUEST_URI']; |
|
137 |
$smarty->assign('url', $url); |
|
138 |
|
|
139 |
assign_dynamic('compare'); |
|
140 |
//判断 弹框登陆 验证码是否显示 |
|
141 |
$captcha = intval($_CFG['captcha']); |
|
142 |
if(($captcha & CAPTCHA_LOGIN) && (! ($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0) |
|
143 |
{ |
|
144 |
$GLOBALS['smarty']->assign('enabled_captcha', 1); |
|
145 |
$GLOBALS['smarty']->assign('rand', mt_rand()); |
|
146 |
} |
|
147 |
$smarty->display('compare.dwt'); |
|
148 |
|
|
149 |
?> |