commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 生成商品列表 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
define('INIT_NO_USERS', true); |
|
9 |
|
|
10 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
11 |
|
|
12 |
if ((DEBUG_MODE & 2) != 2) |
|
13 |
{ |
|
14 |
$smarty->caching = true; |
|
15 |
} |
|
16 |
|
|
17 |
$charset = empty($_GET['charset']) ? EC_CHARSET : $_GET['charset']; |
|
18 |
$type = empty($_GET['type']) ? '' : 'collection'; |
|
19 |
if (strtolower($charset) == 'gb2312') |
|
20 |
{ |
|
21 |
$charset = 'gbk'; |
|
22 |
} |
|
23 |
header('content-type: application/x-javascript; charset=' . ($charset == 'UTF8' ? 'utf-8' : $charset)); |
|
24 |
|
|
25 |
/*------------------------------------------------------ */ |
|
26 |
//-- 判断是否存在缓存,如果存在则调用缓存,反之读取相应内容 |
|
27 |
/*------------------------------------------------------ */ |
|
28 |
/* 缓存编号 */ |
|
29 |
$cache_id = sprintf('%X', crc32($_SERVER['QUERY_STRING'])); |
|
30 |
|
|
31 |
$tpl = ROOT_PATH . DATA_DIR . '/goods_script.html'; |
|
32 |
if (!$smarty->is_cached($tpl, $cache_id)) |
|
33 |
{ |
|
34 |
$time = gmtime(); |
|
35 |
$sql=''; |
|
36 |
/* 根据参数生成查询语句 */ |
|
37 |
if ($type == '') |
|
38 |
{ |
|
39 |
$sitename = !empty($_GET['sitename']) ? $_GET['sitename'] : ''; |
|
40 |
$_from = (!empty($_GET['charset']) && $_GET['charset'] != 'UTF8')? urlencode(ecs_iconv('UTF-8', 'GBK', $sitename)) : urlencode(@$sitename); |
|
41 |
$goods_url = $ecs->url() . 'affiche.php?ad_id=-1&from=' . $_from . '&goods_id='; |
|
42 |
|
|
43 |
$sql = 'SELECT goods_id, goods_name, market_price, goods_thumb, RAND() AS rnd, ' . |
|
44 |
"IF(is_promote = 1 AND '$time' >= promote_start_date AND ". |
|
45 |
"'$time' <= promote_end_date, promote_price, shop_price) AS goods_price " . |
|
46 |
'FROM ' . $ecs->table('goods') . ' AS g ' . |
|
47 |
"WHERE is_delete = '0' AND is_on_sale = '1' AND is_alone_sale = '1' "; |
|
48 |
if (!empty($_GET['cat_id'])) |
|
49 |
{ |
|
50 |
$sql .= ' AND ' . get_children(intval($_GET['cat_id'])); |
|
51 |
} |
|
52 |
if (!empty($_GET['brand_id'])) |
|
53 |
{ |
|
54 |
$sql .= " AND brand_id = '" . intval($_GET['brand_id']) . "'"; |
|
55 |
} |
|
56 |
if (!empty($_GET['intro_type'])) |
|
57 |
{ |
|
58 |
$_GET['intro_type'] = trim($_GET['intro_type']); |
|
59 |
|
|
60 |
if ($_GET['intro_type'] == 'is_best' || $_GET['intro_type'] == 'is_new' || $_GET['intro_type'] == 'is_hot' || $_GET['intro_type'] == 'is_promote' || $_GET['intro_type'] == 'is_random') |
|
61 |
{ |
|
62 |
if ($_GET['intro_type'] == 'is_random') |
|
63 |
{ |
|
64 |
$sql .= ' ORDER BY rnd'; |
|
65 |
} |
|
66 |
else |
|
67 |
{ |
|
68 |
if ($_GET['intro_type'] == 'is_promote') |
|
69 |
{ |
|
70 |
$sql .= " AND promote_start_date <= '$time' AND promote_end_date >= '$time'"; |
|
71 |
} |
|
72 |
$sql .= " AND " . $_GET['intro_type'] . " = 1 ORDER BY add_time DESC"; |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
elseif ($type == 'collection') |
|
78 |
{ |
|
79 |
$uid = (int)$_GET['u']; |
|
80 |
$goods_url = $ecs->url() . "goods.php?u=$uid&id="; |
|
81 |
$sql = "SELECT g.goods_id, g.goods_name, g.market_price, g.goods_thumb, IF(g.is_promote = 1 AND '$time' >= g.promote_start_date AND ". |
|
82 |
"'$time' <= g.promote_end_date, g.promote_price, g.shop_price) AS goods_price FROM " . $ecs->table('goods') . " g LEFT JOIN " . $ecs->table('collect_goods') . " c ON g.goods_id = c.goods_id " . |
|
83 |
" WHERE c.user_id = '$uid'"; |
|
84 |
} |
|
85 |
$sql .= " LIMIT " . (!empty($_GET['goods_num']) ? intval($_GET['goods_num']) : 10); |
|
86 |
$res = $db->query($sql); |
|
87 |
|
|
88 |
$goods_list = array(); |
|
89 |
while ($goods = $db->fetchRow($res)) |
|
90 |
{ |
|
91 |
// 转换编码 |
|
92 |
$goods['goods_price'] = price_format($goods['goods_price']); |
|
93 |
if ($charset != EC_CHARSET) |
|
94 |
{ |
|
95 |
if (EC_CHARSET == 'gbk') |
|
96 |
{ |
|
97 |
$tmp_goods_name = htmlentities($goods['goods_name'], ENT_QUOTES, 'gb2312'); |
|
98 |
} |
|
99 |
else |
|
100 |
{ |
|
101 |
$tmp_goods_name = htmlentities($goods['goods_name'], ENT_QUOTES, EC_CHARSET); |
|
102 |
} |
|
103 |
$goods['goods_name'] = ecs_iconv(EC_CHARSET, $charset, $tmp_goods_name); |
|
104 |
$goods['goods_price'] = ecs_iconv(EC_CHARSET, $charset, $goods['goods_price']); |
|
105 |
} |
|
106 |
$goods['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($goods['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $goods['goods_name']; |
|
107 |
$goods['goods_thumb'] = get_image_path($goods['goods_id'], $goods['goods_thumb'], true); |
|
108 |
$goods_list[] = $goods; |
|
109 |
} |
|
110 |
|
|
111 |
/* 排列方式 */ |
|
112 |
$arrange = empty($_GET['arrange']) || !in_array($_GET['arrange'], array('h', 'v')) ? 'h' : $_GET['arrange']; |
|
113 |
|
|
114 |
/* 排列显示条目个数 */ |
|
115 |
$goods_num = !empty($_GET['goods_num']) ? intval($_GET['goods_num']) : 10; |
|
116 |
$rows_num = !empty($_GET['rows_num']) ? intval($_GET['rows_num']) : '1'; |
|
117 |
if($arrange == 'h') |
|
118 |
{ |
|
119 |
$goods_items = array_chunk($goods_list,$rows_num); |
|
120 |
} |
|
121 |
else |
|
122 |
{ |
|
123 |
$columns_num = ceil($goods_num / $rows_num); |
|
124 |
$goods_items = array_chunk($goods_list,$columns_num); |
|
125 |
} |
|
126 |
$smarty->assign('goods_list', $goods_items); |
|
127 |
|
|
128 |
|
|
129 |
/* 是否需要图片 */ |
|
130 |
$need_image = empty($_GET['need_image']) || $_GET['need_image'] == 'true' ? 1 : 0; |
|
131 |
$smarty->assign('need_image', $need_image); |
|
132 |
|
|
133 |
/* 图片大小 */ |
|
134 |
$smarty->assign('thumb_width', intval($_CFG['thumb_width'])); |
|
135 |
$smarty->assign('thumb_height', intval($_CFG['thumb_height'])); |
|
136 |
|
|
137 |
/* 网站根目录 */ |
|
138 |
$smarty->assign('url', $ecs->url()); |
|
139 |
|
|
140 |
/* 商品页面连接 */ |
|
141 |
$smarty->assign('goods_url', $goods_url); |
|
142 |
} |
|
143 |
$output = $smarty->fetch($tpl, $cache_id); |
|
144 |
$output = str_replace("\r", '', $output); |
|
145 |
$output = str_replace("\n", '', $output); |
|
146 |
|
|
147 |
echo "document.write('$output');"; |
|
148 |
|
|
149 |
?> |