-
Notifications
You must be signed in to change notification settings - Fork 27
/
brand.php
420 lines (359 loc) · 17.1 KB
/
brand.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?php
/**
* 鸿宇多用户商城 品牌列表
* ============================================================================
* 版权所有 2015-2016 鸿宇多用户商城科技有限公司,并保留所有权利。
* 网站地址: http://bbs.hongyuvip.com;
* ----------------------------------------------------------------------------
* 仅供学习交流使用,如需商用请购买正版版权。鸿宇不承担任何法律责任。
* 踏踏实实做事,堂堂正正做人。
* ============================================================================
* $Author: Shadow & 鸿宇
* $Id: brand.php 17217 2016-01-19 06:29:08Z Shadow & 鸿宇
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
/* 获得请求的分类 ID */
// safety_20150629 change_start
if (!empty($_REQUEST['id']) && preg_match('/^-?[1-9]\d*$/', $_REQUEST['id']))
{
$brand_id = intval($_REQUEST['id']);
}
if (!empty($_REQUEST['brand']) && preg_match('/^-?[1-9]\d*$/', $_REQUEST['brand']))
{
$brand_id = intval($_REQUEST['brand']);
}
// safety_20150629 change_end
if (empty($brand_id))
{
/* 缓存编号 */
$cache_id = sprintf('%X', crc32($_CFG['lang']));
if (!$smarty->is_cached('brand_list.dwt', $cache_id))
{
assign_template();
$position = assign_ur_here('', $_LANG['all_brand']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('brand_list', get_brands());
}
$smarty->display('brand_list.dwt', $cache_id);
exit();
}
/* 初始化分页信息 */
$page = !empty($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$size = !empty($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
$cate = !empty($_REQUEST['cat']) && intval($_REQUEST['cat']) > 0 ? intval($_REQUEST['cat']) : 0;
$suppId = !empty($_REQUEST['suppId']) && intval($_REQUEST['suppId']) > 0 ? intval($_REQUEST['suppId']) : 0;
/* 排序、显示方式以及类型 */
$default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : ($_CFG['show_order_type'] == '1' ? 'grid' : 'text');
$default_sort_order_method = $_CFG['sort_order_method'] == '0' ? 'DESC' : 'ASC';
$default_sort_order_type = $_CFG['sort_order_type'] == '0' ? 'goods_id' : ($_CFG['sort_order_type'] == '1' ? 'shop_price' : 'last_update');
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'shop_price', 'last_update','click_count', 'salenum'))) ? trim($_REQUEST['sort']) : $default_sort_order_type;
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : $default_sort_order_method;
$display = (isset($_REQUEST['display']) && in_array(trim(strtolower($_REQUEST['display'])), array('list', 'grid', 'text'))) ? trim($_REQUEST['display']) : (isset($_COOKIE['ECS']['display']) ? $_COOKIE['ECS']['display'] : $default_display_type);
$display = in_array($display, array('list', 'grid', 'text')) ? $display : 'text';
setcookie('ECS[display]', $display, gmtime() + 86400 * 7);
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
/* 页面的缓存ID */
$cache_id = sprintf('%X', crc32($brand_id . '-' . $display . '-' . $sort . '-' . $order . '-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' . $_CFG['lang'] . '-' . $cate . '-' . $suppId));
if (!$smarty->is_cached('brand.dwt', $cache_id))
{
$brand_info = get_brand_info($brand_id);
if (empty($brand_info))
{
ecs_header("Location: ./\n");
exit;
}
$smarty->assign('data_dir', DATA_DIR);
$smarty->assign('keywords', htmlspecialchars($brand_info['brand_desc']));
$smarty->assign('description', htmlspecialchars($brand_info['brand_desc']));
/* 赋值固定内容 */
assign_template();
$position = assign_ur_here($cate, $brand_info['brand_name']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('brand_id', $brand_id);
$smarty->assign('category', $cate);
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
$smarty->assign('brand_cat_list', brand_related_cat($brand_id)); // 相关分类
$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-b$brand_id.xml" : 'feed.php?brand=' . $brand_id);
/* 调查 */
$vote = get_vote();
if (!empty($vote))
{
$smarty->assign('vote_id', $vote['id']);
$smarty->assign('vote', $vote['content']);
}
$smarty->assign('best_goods', brand_recommend_goods('best', $brand_id, $cate));
$smarty->assign('promotion_goods', brand_recommend_goods('promote', $brand_id, $cate));
$smarty->assign('brand', $brand_info);
$smarty->assign('promotion_info', get_promotion_info());
$count = goods_count_by_brand($brand_id, $cate);
$goodslist = brand_get_goods($brand_id, $cate, $size, $page, $sort, $order);
if($display == 'grid')
{
if(count($goodslist) % 2 != 0)
{
$goodslist[] = array();
}
}
$smarty->assign('goods_list', $goodslist);
$smarty->assign('script_name', 'brand');
if($suppId>0){
$brand_id = $brand_id.'&suppId='.$suppId;
}
assign_pager('brand', $cate, $count, $size, $sort, $order, $page, '', $brand_id, 0, 0, $display); // 分页
assign_dynamic('brand'); // 动态内容
}
$smarty->assign('actname','brand.php');
$smarty->display('brand.dwt', $cache_id);
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 获得指定品牌的详细信息
*
* @access private
* @param integer $id
* @return void
*/
function get_brand_info($id)
{
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('brand') . " WHERE brand_id = '$id'";
return $GLOBALS['db']->getRow($sql);
}
/**
* 获得指定品牌下的推荐和促销商品
*
* @access private
* @param string $type
* @param integer $brand
* @return array
*/
function brand_recommend_goods($type, $brand, $cat = 0)
{
static $result = NULL;
$time = gmtime();
if ($result === NULL)
{
if ($cat > 0)
{
$cat_where = "AND " . get_children($cat);
}
else
{
$cat_where = '';
}
$sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, ' .
'b.brand_name, g.is_best, g.is_new, g.is_hot, g.is_promote ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
'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 AND g.brand_id = '$brand' AND " .
"(g.is_best = 1 OR (g.is_promote = 1 AND promote_start_date <= '$time' AND ".
"promote_end_date >= '$time')) $cat_where" .
'ORDER BY g.sort_order, g.last_update DESC';
$result = $GLOBALS['db']->getAll($sql);
}
/* 取得每一项的数量限制 */
$num = 0;
$type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion');
$num = get_library_number($type2lib[$type]);
$idx = 0;
$goods = array();
foreach ($result AS $row)
{
if ($idx >= $num)
{
break;
}
if (($type == 'best' && $row['is_best'] == 1) ||
($type == 'promote' && $row['is_promote'] == 1 &&
$row['promote_start_date'] <= $time && $row['promote_end_date'] >= $time))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['short_style_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
/* 检查是否已经存在于用户的收藏夹 */
$sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('collect_goods') .
" WHERE user_id='$_SESSION[user_id]' AND goods_id = " . $goods[$idx]['id'];
if ($GLOBALS['db']->GetOne($sql) > 0)
{
$goods[$idx]['is_collet'] = 1;
}
else
{
$goods[$idx]['is_collet'] = 0;
}
$idx++;
}
}
return $goods;
}
/**
* 获得指定的品牌下的商品总数
*
* @access private
* @param integer $brand_id
* @param integer $cate
* @return integer
*/
function goods_count_by_brand($brand_id, $cate = 0)
{
global $suppId;
$sql = 'SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('goods'). ' AS g '.
"WHERE brand_id = '$brand_id' AND supplier_id = '$suppId' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0";
if ($cate > 0)
{
$sql .= " AND " . get_children($cate);
}
return $GLOBALS['db']->getOne($sql);
}
/**
* 获得品牌下的商品
*
* @access private
* @param integer $brand_id
* @return array
*/
function brand_get_goods($brand_id, $cate, $size, $page, $sort, $order)
{
global $suppId;
$cate_where = ($cate > 0) ? 'AND ' . get_children($cate) : '';
/* 获得商品列表 */
/*$sql = 'SELECT g.goods_id, g.goods_name, g.click_count, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['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 AND g.supplier_id = '$suppId' AND g.brand_id = '$brand_id' $cate_where".
"ORDER BY $sort $order";*/
$sql = 'SELECT g.goods_id, g.goods_name, g.click_count, g.goods_number, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['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 AND g.brand_id = '$brand_id' $cate_where".
"ORDER BY $sort $order";
/* 代码增加_start By bbs.hongyuvip.com */
if ($sort=='salenum')
{
$sql = 'SELECT SUM(o.goods_number) as salenum, g.goods_id, g.goods_name, g.click_count, g.goods_number, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['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]' " . "LEFT JOIN " . $GLOBALS['ecs']->table('order_goods') . " as o ON o.goods_id = g.goods_id " . " where g.brand_id = '$brand_id' $ext group by g.goods_id ORDER BY $sort $order";
}
/* 代码增加_end By bbs.hongyuvip.com */
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
$arr = array();
while ($row = $GLOBALS['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;
}
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($GLOBALS['display'] == 'grid')
{
$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'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
$arr[$row['goods_id']]['comment_count'] = get_comment_count($row['goods_id']);
$arr[$row['goods_id']]['count'] = selled_count($row['goods_id']);
$arr[$row['goods_id']]['click_count'] = $row['click_count'];
$arr[$row['goods_id']]['goods_number'] = $row['goods_number'];
/* 检查是否已经存在于用户的收藏夹 */
$sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('collect_goods') .
" WHERE user_id='$_SESSION[user_id]' AND goods_id = " . $row['goods_id'];
if ($GLOBALS['db']->GetOne($sql) > 0)
{
$arr[$row['goods_id']]['is_collet'] = 1;
}
else
{
$arr[$row['goods_id']]['is_collet'] = 0;
}
}
return $arr;
}
/**
* 获得与指定品牌相关的分类
*
* @access public
* @param integer $brand
* @return array
*/
function brand_related_cat($brand)
{
$arr[] = array('cat_id' => 0,
'cat_name' => $GLOBALS['_LANG']['all_category'],
'url' => build_uri('brand', array('bid' => $brand), $GLOBALS['_LANG']['all_category']));
$sql = "SELECT c.cat_id, c.cat_name, COUNT(g.goods_id) AS goods_count FROM ".
$GLOBALS['ecs']->table('category'). " AS c, ".
$GLOBALS['ecs']->table('goods') . " AS g " .
"WHERE g.brand_id = '$brand' AND c.cat_id = g.cat_id ".
"GROUP BY g.cat_id";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
$row['url'] = build_uri('brand', array('cid' => $row['cat_id'], 'bid' => $brand), $row['cat_name']);
$arr[] = $row;
}
return $arr;
}
?>