-
Notifications
You must be signed in to change notification settings - Fork 27
/
pick_out.php
303 lines (253 loc) · 11.4 KB
/
pick_out.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
/**
* 鸿宇多用户商城 选购中心
* ============================================================================
* 版权所有 2015-2016 鸿宇多用户商城科技有限公司,并保留所有权利。
* 网站地址: http://bbs.hongyuvip.com;
* ----------------------------------------------------------------------------
* 仅供学习交流使用,如需商用请购买正版版权。鸿宇不承担任何法律责任。
* 踏踏实实做事,堂堂正正做人。
* ============================================================================
* $Author: Shadow & 鸿宇
* $Id: pick_out.php 17217 2016-01-19 06:29:08Z Shadow & 鸿宇
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
$condition = array();
$picks = array();
$cat_id = !empty($_GET['cat_id']) ? intval($_GET['cat_id']) : 0;
if (!empty($_GET['attr']))
{
foreach($_GET['attr'] as $key => $value)
{
if (!is_numeric($key))
{
unset($_GET['attr'][$key]);
continue;
}
$key = intval($key);
$_GET['attr'][$key] = htmlspecialchars($value);
}
}
if (empty($cat_id))
{
/* 获取所有符合条件的商品类型 */
$sql = "SELECT DISTINCT t.cat_id, t.cat_name " .
"FROM " . $ecs->table('goods_type') . " AS t, " . $ecs->table('attribute') . " AS a, " . $ecs->table('goods_attr') . " AS g " .
"WHERE t.cat_id = a.cat_id AND a.attr_id = g.attr_id AND t.enabled = 1";
$rs = $db->query($sql);
$in_cat = array();
$cat_name = array();
$in_goods = '';
while ($row = $db->fetchRow($rs))
{
$condition[$row['cat_id']]['name'] = $row['cat_name'];
$in_cat[] = $row['cat_id'];
}
$in_cat = "AND a.cat_id ".db_create_in($in_cat);
/* 获取符合条件的属性 */
$sql = "SELECT DISTINCT a.attr_id ".
"FROM ".$ecs->table('goods_attr')." AS g, ".$ecs->table('attribute') ." AS a ".
"WHERE a.attr_id = g.attr_id " . $in_cat;
$in_attr = $db->getCol($sql); //符合条件attr_id;
$in_attr = 'AND g.attr_id '.db_create_in($in_attr);
/* 获取所有属性值 */
$sql = "SELECT DISTINCT g.attr_id, a.attr_name, a.cat_id, g.attr_value".
" FROM ".$ecs->table('goods_attr')." AS g, ".
$ecs->table('attribute') ." AS a".
" WHERE a.attr_id = g.attr_id ".$in_attr." ORDER BY cat_id";
$rs = $db->query($sql);
while ($row = $db->fetchRow($rs))
{
if (empty($condition[$row['cat_id']]['cat'][$row['attr_id']]['cat_name']))
{
$condition[$row['cat_id']]['cat'][$row['attr_id']]['cat_name'] = $row['attr_name'];
}
$condition[$row['cat_id']]['cat'][$row['attr_id']]['list'][] = array('name'=>$row['attr_value'], 'url'=>'pick_out.php?cat_id='.$row['cat_id'].'&attr['.$row['attr_id'].']='.urlencode($row['attr_value']));
}
/* 获取商品总数 */
$goods_count = $db->GetOne("SELECT COUNT(DISTINCT(goods_id)) FROM " . $ecs->table('goods_attr'));
/* 获取符合条件的商品id */
//$sql = "SELECT DISTINCT goods_id FROM " .$ecs->table('goods_attr'). " LIMIT 100";
$sql = "SELECT DISTINCT goods_id FROM " .$ecs->table('goods_attr');
$in_goods = $db->GetCol($sql);
$in_goods = 'AND g.goods_id ' . db_create_in(implode(',', $in_goods));
$url = "search.php?pickout=1";
}
else
{
/* 取得商品类型名称 */
$sql = "SELECT cat_name FROM ".$ecs->table('goods_type')." WHERE cat_id = '$cat_id'";
$cat_name = $db->GetOne($sql);
$condition[0]['name'] = $cat_name;
$picks[] = array('name'=>'<strong>'.$_LANG['goods_type'].':</strong><br />'.$cat_name, 'url'=>'pick_out.php');
$attr_picks = array(); //选择过的attr_id
/* 处理属性,获取满足属性的goods_id */
if (!empty($_GET['attr']))
{
$attr_table = '';
$attr_where = '';
$attr_url = '';
$i = 0;
$goods_result = '';
foreach ($_GET['attr'] AS $key => $value)
{
$attr_url .= '&attr[' . $key . ']=' . $value;
$attr_picks[] = $key;
if ($i > 0)
{
if (empty($goods_result))
{
break;
}
$goods_result = $db->getCol("SELECT goods_id FROM " . $ecs->table("goods_attr") . " WHERE goods_id IN (" . implode(',' , $goods_result) . ") AND attr_id='$key' AND attr_value='$value'");
}
else
{
$goods_result = $db->getCol("SELECT goods_id FROM " . $ecs->table("goods_attr") . " WHERE attr_id='$key' AND attr_value='$value'");
}
$i++;
}
/* 获取指定attr_id的名字 */
$sql = "SELECT attr_id, attr_name FROM ".$ecs->table('attribute')." WHERE attr_id ".db_create_in(implode(',',$attr_picks));
$rs = $db->query($sql);
while ($row = $db->fetchRow($rs))
{
$picks[] = array('name'=>'<strong>'.$row['attr_name'].':</strong><br />'.htmlspecialchars(urldecode($_GET['attr'][$row['attr_id']])), 'url'=>'pick_out.php?cat_id='.$cat_id.search_url($attr_picks, $row['attr_id']));
}
/* 查出数量 */
$goods_count = count($goods_result);
/* 获取符合条件的goods_id */
$in_goods = 'AND g.goods_id '.db_create_in(implode(',', $goods_result));
}
else
{
/* 仅选择了商品类型的情况 */
/* 查出数量 */
$goods_count = $db->GetOne("SELECT COUNT(distinct(g.goods_id)) FROM ".$ecs->table('goods_attr')." AS g, ".$ecs->table('attribute')." AS a WHERE g.attr_id = a.attr_id AND a.cat_id = '$cat_id' ");
/* 防止结果过大,最多只查出前100个goods_id */
$sql = "SELECT DISTINCT g.goods_id FROM ".$ecs->table('goods_attr')." AS g, ".$ecs->table('attribute')." AS a WHERE g.attr_id = a.attr_id AND a.cat_id = '$cat_id' LIMIT 100";
$in_goods = $db->GetCol($sql);
$in_goods = 'AND g.goods_id '.db_create_in(implode(',', $in_goods));
}
/* 获取符合条件的属性 */
$sql = "SELECT DISTINCT a.attr_id FROM ".$ecs->table('goods_attr')." AS g, ".$ecs->table('attribute') ." AS a ".
"WHERE a.attr_id = g.attr_id " . $in_goods;
$in_attr = $db->GetCol($sql); // 符合条件attr_id;
$in_attr = array_diff($in_attr, $attr_picks); // 除去已经选择过的attr_id
$in_attr = 'AND g.attr_id '.db_create_in(implode(',', $in_attr));
/* 获取所有属性值 */
$sql = "SELECT DISTINCT g.attr_id, a.attr_name, g.attr_value FROM ".$ecs->table('goods_attr')." AS g, ".$ecs->table('attribute') ." AS a WHERE a.attr_id = g.attr_id ".$in_attr.$in_goods;
$rs = $db->query($sql);
while ($row = $db->fetchRow($rs))
{
if (empty($condition[0]['cat'][$row['attr_id']]['cat_name']))
{
$condition[0]['cat'][$row['attr_id']]['cat_name'] = $row['attr_name'];
}
$condition[0]['cat'][$row['attr_id']]['list'][] = array('name'=>$row['attr_value'], 'url'=>'pick_out.php?cat_id='.$cat_id.search_url($attr_picks).'&attr['.$row['attr_id'].']='.urlencode($row['attr_value']));
}
/* 生成更多商品的url */
$url = "search.php?pickout=1&cat_id=".$cat_id.search_url($attr_picks);
}
/* 显示商品 */
$goods = array();
$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ".
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
"g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb ".
"FROM " .$ecs->table('goods'). " AS g ".
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".$in_goods.
"ORDER BY g.sort_order, g.last_update DESC";
$res = $db->SelectLimit($sql, 4);
/* 获取品牌 */
$sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, COUNT(g.goods_id) AS goods_num ".
" FROM " . $ecs->table('goods') . " AS g ".
" LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id=b.brand_id ".
" WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND b.brand_id > 0 " . $in_goods .
" GROUP BY g.brand_id ";
$brand_list = $db->getAll($sql);
foreach ($brand_list as $key=>$val)
{
$brand_list[$key]['url'] = $url . '&brand=' . $val['brand_id'];
}
/* 获取分类 */
$sql = "SELECT c.cat_id, c.cat_name, COUNT(g.goods_id) AS goods_num ".
" FROM " . $ecs->table('goods') . " AS g ".
" LEFT JOIN " . $ecs->table('category') . " AS c ON c.cat_id = g.cat_id ".
" WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . $in_goods .
" GROUP BY g.cat_id ";
$cat_list = $db->getAll($sql);
foreach ($cat_list as $key=>$val)
{
$cat_list[$key]['url'] = $url . '&category=' . $val['cat_id'];
}
$idx = 0;
while ($row = $db->fetchRow($res))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
}
else
{
$promote_price = 0;
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['short_name'] = $_CFG['goods_name_length'] > 0 ? sub_str($row['goods_name'], $_CFG['goods_name_length']) : $row['goods_name'];
$goods[$idx]['market_price'] = $row['market_price'];
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
$idx++;
}
$picks[] = array('name'=>$_LANG['remove_all'], 'url'=>'pick_out.php');
assign_template();
$position = assign_ur_here(0, $_LANG['pick_out']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('brand_list', $brand_list); //品牌
$smarty->assign('cat_list', $cat_list); //分类列表
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('data_dir', DATA_DIR); // 数据目录
/* 调查 */
$vote = get_vote();
if (!empty($vote))
{
$smarty->assign('vote_id', $vote['id']);
$smarty->assign('vote', $vote['content']);
}
assign_dynamic('pick_out');
$smarty->assign('url', $url);
$smarty->assign('pickout_goods', $goods);
$smarty->assign('count', $goods_count);
$smarty->assign('picks', $picks);
$smarty->assign('condition', $condition);
$smarty->display('pick_out.dwt');
/**
* 生成搜索的链接地址
*
* @access public
* @param int attr_id 要排除的attr_id
*
* @return string
*/
function search_url(&$attr_picks, $attr_id = 0)
{
$str = '';
foreach ($attr_picks AS $pick_id)
{
if ($pick_id != $attr_id)
{
$str .= '&attr['.$pick_id.']='.urlencode($_GET['attr'][$pick_id]);
}
}
return $str;
}
?>