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 |
|
|
11 |
if ((DEBUG_MODE & 2) != 2) |
|
12 |
{ |
|
13 |
$smarty->caching = true; |
|
14 |
} |
|
15 |
|
|
16 |
/*------------------------------------------------------ */ |
|
17 |
//-- act 操作项的初始化 |
|
18 |
/*------------------------------------------------------ */ |
|
19 |
if (empty($_REQUEST['act'])) |
|
20 |
{ |
|
21 |
$_REQUEST['act'] = 'list'; |
|
22 |
} |
|
23 |
|
|
24 |
/*------------------------------------------------------ */ |
|
25 |
//-- PROCESSOR |
|
26 |
/*------------------------------------------------------ */ |
|
27 |
|
|
28 |
/*------------------------------------------------------ */ |
|
29 |
//-- 积分兑换商品列表 |
|
30 |
/*------------------------------------------------------ */ |
|
31 |
if ($_REQUEST['act'] == 'list') |
|
32 |
{ |
|
33 |
/* 初始化分页信息 */ |
|
34 |
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1; |
|
35 |
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10; |
|
36 |
$cat_id = isset($_REQUEST['cat_id']) && intval($_REQUEST['cat_id']) > 0 ? intval($_REQUEST['cat_id']) : 0; |
|
37 |
$integral_max = isset($_REQUEST['integral_max']) && intval($_REQUEST['integral_max']) > 0 ? intval($_REQUEST['integral_max']) : 0; |
|
38 |
$integral_min = isset($_REQUEST['integral_min']) && intval($_REQUEST['integral_min']) > 0 ? intval($_REQUEST['integral_min']) : 0; |
|
39 |
|
|
40 |
/* 排序、显示方式以及类型 */ |
|
41 |
$default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : ($_CFG['show_order_type'] == '1' ? 'grid' : 'text'); |
|
42 |
$default_sort_order_method = $_CFG['sort_order_method'] == '0' ? 'DESC' : 'ASC'; |
|
43 |
$default_sort_order_type = $_CFG['sort_order_type'] == '0' ? 'goods_id' : ($_CFG['sort_order_type'] == '1' ? 'exchange_integral' : 'last_update'); |
|
44 |
|
|
45 |
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'exchange_integral', 'last_update','click_count'))) ? trim($_REQUEST['sort']) : $default_sort_order_type; |
|
46 |
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : $default_sort_order_method; |
|
47 |
$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); |
|
48 |
$display = in_array($display, array('list', 'grid', 'text')) ? $display : 'text'; |
|
49 |
setcookie('ECS[display]', $display, gmtime() + 86400 * 7); |
|
50 |
|
|
51 |
/* 页面的缓存ID */ |
|
52 |
$cache_id = sprintf('%X', crc32($cat_id . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' . |
|
53 |
$_CFG['lang'] . '-' . $integral_max . '-' .$integral_min)); |
|
54 |
|
|
55 |
if (!$smarty->is_cached('exchange_list.dwt', $cache_id)) |
|
56 |
{ |
|
57 |
/* 如果页面没有被缓存则重新获取页面的内容 */ |
|
58 |
|
|
59 |
$children = get_children($cat_id); |
|
60 |
|
|
61 |
$cat = get_cat_info($cat_id); // 获得分类的相关信息 |
|
62 |
|
|
63 |
if (!empty($cat)) |
|
64 |
{ |
|
65 |
$smarty->assign('keywords', htmlspecialchars($cat['keywords'])); |
|
66 |
$smarty->assign('description', htmlspecialchars($cat['cat_desc'])); |
|
67 |
} |
|
68 |
|
|
69 |
assign_template(); |
|
70 |
|
|
71 |
$position = assign_ur_here('exchange'); |
|
72 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
73 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
74 |
|
|
75 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
76 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
77 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
78 |
$smarty->assign('promotion_info', get_promotion_info()); // 促销活动信息 |
|
79 |
|
|
80 |
|
|
81 |
/* 调查 */ |
|
82 |
$vote = get_vote(); |
|
83 |
if (!empty($vote)) |
|
84 |
{ |
|
85 |
$smarty->assign('vote_id', $vote['id']); |
|
86 |
$smarty->assign('vote', $vote['content']); |
|
87 |
} |
|
88 |
|
|
89 |
$ext = ''; //商品查询条件扩展 |
|
90 |
|
|
91 |
//$smarty->assign('best_goods', get_exchange_recommend_goods('best', $children, $integral_min, $integral_max)); |
|
92 |
//$smarty->assign('new_goods', get_exchange_recommend_goods('new', $children, $integral_min, $integral_max)); |
|
93 |
$smarty->assign('hot_goods', get_exchange_recommend_goods('hot', $children, $integral_min, $integral_max)); |
|
94 |
|
|
95 |
|
|
96 |
$count = get_exchange_goods_count($children, $integral_min, $integral_max); |
|
97 |
$max_page = ($count> 0) ? ceil($count / $size) : 1; |
|
98 |
if ($page > $max_page) |
|
99 |
{ |
|
100 |
$page = $max_page; |
|
101 |
} |
|
102 |
$goodslist = exchange_get_goods($children, $integral_min, $integral_max, $ext, $size, $page, $sort, $order); |
|
103 |
if($display == 'grid') |
|
104 |
{ |
|
105 |
if(count($goodslist) % 2 != 0) |
|
106 |
{ |
|
107 |
$goodslist[] = array(); |
|
108 |
} |
|
109 |
} |
|
110 |
$smarty->assign('goods_list', $goodslist); |
|
111 |
$smarty->assign('category', $cat_id); |
|
112 |
$smarty->assign('integral_max', $integral_max); |
|
113 |
$smarty->assign('integral_min', $integral_min); |
|
114 |
|
|
115 |
|
|
116 |
assign_pager('exchange', $cat_id, $count, $size, $sort, $order, $page, '', '', $integral_min, $integral_max, $display); // 分页 |
|
117 |
assign_dynamic('exchange_list'); // 动态内容 |
|
118 |
} |
|
119 |
|
|
120 |
$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-typeexchange.xml" : 'feed.php?type=exchange'); // RSS URL |
|
121 |
$smarty->display('exchange_list.dwt', $cache_id); |
|
122 |
} |
|
123 |
|
|
124 |
/*------------------------------------------------------ */ |
|
125 |
//-- 积分兑换商品详情 |
|
126 |
/*------------------------------------------------------ */ |
|
127 |
elseif ($_REQUEST['act'] == 'view') |
|
128 |
{ |
|
129 |
$goods_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; |
|
130 |
|
|
131 |
$cache_id = $goods_id . '-' . $_SESSION['user_rank'] . '-' . $_CFG['lang'] . '-exchange'; |
|
132 |
$cache_id = sprintf('%X', crc32($cache_id)); |
|
133 |
|
|
134 |
if (!$smarty->is_cached('exchange_goods.dwt', $cache_id)) |
|
135 |
{ |
|
136 |
$smarty->assign('image_width', $_CFG['image_width']); |
|
137 |
$smarty->assign('image_height', $_CFG['image_height']); |
|
138 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
139 |
$smarty->assign('id', $goods_id); |
|
140 |
$smarty->assign('type', 0); |
|
141 |
$smarty->assign('cfg', $_CFG); |
|
142 |
$sql_attr_www_ecshop68_com="SELECT a.attr_id, ga.goods_attr_id FROM ". $GLOBALS['ecs']->table('attribute') . " AS a left join ". $GLOBALS['ecs']->table('goods_attr') . " AS ga on a.attr_id=ga.attr_id WHERE a.is_attr_gallery=1 and ga.goods_id='" . $goods_id. "' order by ga.goods_attr_id "; |
|
143 |
$goods_attr=$GLOBALS['db']->getRow($sql_attr_www_ecshop68_com); |
|
144 |
$goods_attr_id=$goods_attr['goods_attr_id']; |
|
145 |
$smarty->assign('attr_id', $goods_attr['attr_id']); |
|
146 |
|
|
147 |
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'get_gallery_attr') |
|
148 |
{ |
|
149 |
include('includes/cls_json.php'); |
|
150 |
$json = new JSON; |
|
151 |
|
|
152 |
$goods_attr_id=$_REQUEST['goods_attr_id']; |
|
153 |
$gallery_list_www_ecshop68_com=get_goods_gallery_attr_www_ecshop68_com($goods_id, $goods_attr_id); |
|
154 |
$gallery_content=array(); |
|
155 |
$gallery_content['thumblist'] ='<ul>'; |
|
156 |
foreach($gallery_list_www_ecshop68_com as $gkey=>$gval) |
|
157 |
{ |
|
158 |
$gallery_content['thumblist'] .= '<li>'; |
|
159 |
$gallery_content['thumblist'] .= '<a href="'. $gval['img_original'] . '" rel="zoom-id: zoom; zoom-height: 360px;zoom-width:400px;" rev="'.$gval['img_url'].'" name="'.$gval['img_url'].'" rev="'. $gval['img_original'] . '" '; |
|
160 |
|
|
161 |
$gallery_content['thumblist'] .= '><img src="'. ($gval['thumb_url'] ? $gval['thumb_url'] : $gval['img_url']) . '" class="B_blue" '; |
|
162 |
$gallery_content['thumblist'] .= ' /></a></li>'; |
|
163 |
if ($gkey==0) |
|
164 |
{ |
|
165 |
$gallery_content['bigimg'] = $gval['img_original'] ; |
|
166 |
$gallery_content['middimg'] .= $gval['img_url'] ; |
|
167 |
} |
|
168 |
} |
|
169 |
$gallery_content['thumblist'] .='</ul>'; |
|
170 |
|
|
171 |
die ($json->encode($gallery_content)); |
|
172 |
|
|
173 |
} |
|
174 |
|
|
175 |
|
|
176 |
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'get_products_info') |
|
177 |
{ |
|
178 |
include('includes/cls_json.php'); |
|
179 |
|
|
180 |
$json = new JSON; |
|
181 |
// $res = array('err_msg' => '', 'result' => '', 'qty' => 1); |
|
182 |
|
|
183 |
$spce_id = $_GET['id']; |
|
184 |
$goods_id = $_GET['goods_id']; |
|
185 |
$row = get_products_info($goods_id,explode(",",$spce_id)); |
|
186 |
//$res = array('err_msg'=>$goods_id,'id'=>$spce_id); |
|
187 |
die($json->encode($row)); |
|
188 |
|
|
189 |
} |
|
190 |
|
|
191 |
/* 获得商品的信息 */ |
|
192 |
$goods = get_exchange_goods_info($goods_id); |
|
193 |
|
|
194 |
if ($goods === false) |
|
195 |
{ |
|
196 |
/* 如果没有找到任何记录则跳回到首页 */ |
|
197 |
ecs_header("Location: ./\n"); |
|
198 |
exit; |
|
199 |
} |
|
200 |
else |
|
201 |
{ |
|
202 |
if ($goods['brand_id'] > 0) |
|
203 |
{ |
|
204 |
$goods['goods_brand_url'] = build_uri('brand', array('bid'=>$goods['brand_id']), $goods['goods_brand']); |
|
205 |
} |
|
206 |
|
|
207 |
$goods['goods_style_name'] = add_style($goods['goods_name'], $goods['goods_name_style']); |
|
208 |
|
|
209 |
$smarty->assign('goods', $goods); |
|
210 |
$smarty->assign('goods_id', $goods['goods_id']); |
|
211 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
212 |
|
|
213 |
/* meta */ |
|
214 |
$smarty->assign('keywords', htmlspecialchars($goods['keywords'])); |
|
215 |
$smarty->assign('description', htmlspecialchars($goods['goods_brief'])); |
|
216 |
|
|
217 |
$count1 = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('comment') . " where comment_type=0 and id_value ='$goods_id' and status=1"); |
|
218 |
$smarty->assign('review_count', $count1); |
|
219 |
|
|
220 |
//评价晒单 增加 |
|
221 |
$rank_num['rank_a'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('comment')." WHERE id_value = '$goods_id' AND status = 1 AND comment_rank in (5,4)"); |
|
222 |
$rank_num['rank_b'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('comment')." WHERE id_value = '$goods_id' AND status = 1 AND comment_rank in (3,2)"); |
|
223 |
$rank_num['rank_c'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('comment')." WHERE id_value = '$goods_id' AND status = 1 AND comment_rank = 1"); |
|
224 |
$rank_num['rank_total'] = $rank_num['rank_a'] + $rank_num['rank_b'] + $rank_num['rank_c']; |
|
225 |
$rank_num['rank_pa'] = ($rank_num['rank_a'] > 0) ? round(($rank_num['rank_a'] / $rank_num['rank_total']) * 100,1) : 0; |
|
226 |
$rank_num['rank_pb'] = ($rank_num['rank_b'] > 0) ? round(($rank_num['rank_b'] / $rank_num['rank_total']) * 100,1) : 0; |
|
227 |
$rank_num['rank_pc'] = ($rank_num['rank_c'] > 0) ? round(($rank_num['rank_c'] / $rank_num['rank_total']) * 100,1) : 0; |
|
228 |
$rank_num['shaidan_num'] = $db->getOne("SELECT COUNT(*) AS num FROM ".$ecs->table('shaidan')." WHERE goods_id = '$goods_id' AND status = 1"); |
|
229 |
$smarty->assign('rank_num',$rank_num); |
|
230 |
|
|
231 |
assign_template(); |
|
232 |
|
|
233 |
/* 上一个商品下一个商品 */ |
|
234 |
$sql = "SELECT eg.goods_id FROM " .$ecs->table('exchange_goods'). " AS eg," . $GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND eg.goods_id > " . $goods['goods_id'] . " AND eg.is_exchange = 1 AND g.is_delete = 0 LIMIT 1"; |
|
235 |
$prev_gid = $db->getOne($sql); |
|
236 |
if (!empty($prev_gid)) |
|
237 |
{ |
|
238 |
$prev_good['url'] = build_uri('exchange_goods', array('gid' => $prev_gid), $goods['goods_name']); |
|
239 |
$smarty->assign('prev_good', $prev_good);//上一个商品 |
|
240 |
} |
|
241 |
|
|
242 |
$sql = "SELECT max(eg.goods_id) FROM " . $ecs->table('exchange_goods') . " AS eg," . $GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND eg.goods_id < ".$goods['goods_id'] . " AND eg.is_exchange = 1 AND g.is_delete = 0"; |
|
243 |
$next_gid = $db->getOne($sql); |
|
244 |
if (!empty($next_gid)) |
|
245 |
{ |
|
246 |
$next_good['url'] = build_uri('exchange_goods', array('gid' => $next_gid), $goods['goods_name']); |
|
247 |
$smarty->assign('next_good', $next_good);//下一个商品 |
|
248 |
} |
|
249 |
|
|
250 |
/* current position */ |
|
251 |
$position = assign_ur_here('exchange', $goods['goods_name']); |
|
252 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
253 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
254 |
|
|
255 |
$properties = get_goods_properties($goods_id); // 获得商品的规格和属性 |
|
256 |
$smarty->assign('properties', $properties['pro']); // 商品属性 |
|
257 |
$goodstype = "select goods_type from ".$ecs->table('goods')." where goods_id='". $goods_id ."'"; |
|
258 |
$goodstype_one = $db->getOne($goodstype); |
|
259 |
|
|
260 |
/* 代码增加_start */ |
|
261 |
$sql_zhyh_qq2211707 = "select attr_id from ".$ecs->table('attribute')." where cat_id='". $goodstype_one ."' and is_attr_gallery='1' "; |
|
262 |
$attr_id_gallery = $db->getOne($sql_zhyh_qq2211707); |
|
263 |
|
|
264 |
$sql = "SELECT goods_attr_id, attr_value FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id = '$goods_id'"; |
|
265 |
$results_www_ecshop68_com = $GLOBALS['db']->getAll($sql); |
|
266 |
$return_arr = array(); |
|
267 |
foreach ($results_www_ecshop68_com as $value_ecshop68) |
|
268 |
{ |
|
269 |
$return_arr[$value_ecshop68['goods_attr_id']] = $value_ecshop68['attr_value']; |
|
270 |
} |
|
271 |
$prod_options_arr=array(); |
|
272 |
|
|
273 |
$prod_exist_arr = array(); |
|
274 |
$sql_prod = "select goods_attr from ". $GLOBALS['ecs']->table('products') ." where product_number>0 and goods_id='$goods_id' order by goods_attr"; |
|
275 |
$res_prod = $db->query($sql_prod); |
|
276 |
while ($row_prod = $GLOBALS['db']->fetchRow($res_prod)) |
|
277 |
{ |
|
278 |
$prod_exist_arr[] = "|". $row_prod['goods_attr'] ."|"; |
|
279 |
} |
|
280 |
$GLOBALS['smarty']->assign('prod_exist_arr', $prod_exist_arr); |
|
281 |
|
|
282 |
$selected_first = array(); |
|
283 |
|
|
284 |
foreach ($properties['spe'] AS $skey_ecshop68=>$sval_ecshop68) |
|
285 |
{ |
|
286 |
$hahaha_zhyh = 0; |
|
287 |
$sskey_www_ecshop68_com = '-1'; |
|
288 |
foreach ($sval_ecshop68['values'] AS $sskey_ecshop68=>$ssval_ecshop68) |
|
289 |
{ |
|
290 |
if ( is_exist_prod($selected_first, $ssval_ecshop68['id'], $prod_exist_arr)) |
|
291 |
{ |
|
292 |
$hahaha_zhyh = $hahaha_zhyh ? $hahaha_zhyh : $ssval_ecshop68['id']; |
|
293 |
$sskey_www_ecshop68_com = ($sskey_www_ecshop68_com != '-1') ? $sskey_www_ecshop68_com : $sskey_ecshop68; |
|
294 |
} |
|
295 |
else |
|
296 |
{ |
|
297 |
$properties['spe'][$skey_ecshop68]['values'][$sskey_ecshop68]['disabled'] = "disabled"; |
|
298 |
} |
|
299 |
|
|
300 |
if ($skey_ecshop68==$attr_id_gallery) |
|
301 |
{ |
|
302 |
$goods_attr_id_qq2211707 = $ssval_ecshop68['id'] ; |
|
303 |
$sql_qq2211707_qq87139667 = "select thumb_url from ". $ecs->table('goods_gallery'). " where goods_id='$goods_id' and goods_attr_id='$goods_attr_id_qq2211707' and is_attr_image='1' "; |
|
304 |
$properties['spe'][$skey_ecshop68]['values'][$sskey_ecshop68]['goods_attr_thumb'] = $db->getOne($sql_qq2211707_qq87139667); |
|
305 |
} |
|
306 |
} |
|
307 |
if ($hahaha_zhyh) |
|
308 |
{ |
|
309 |
$selected_first[$skey_ecshop68] = $hahaha_zhyh; |
|
310 |
} |
|
311 |
if ($sskey_www_ecshop68_com!='-1') |
|
312 |
{ |
|
313 |
$properties['spe'][$skey_ecshop68]['values'][$sskey_www_ecshop68_com]['selected_key_ecshop68'] = "1"; |
|
314 |
} |
|
315 |
} |
|
316 |
$smarty->assign('is_goods_page', 1); |
|
317 |
//echo '<pre>'; |
|
318 |
//print_r($properties['spe']); |
|
319 |
//echo '</pre>'; |
|
320 |
/* 代码增加_end */ |
|
321 |
$smarty->assign('specification', $properties['spe']); // 商品规格 |
|
322 |
|
|
323 |
$smarty->assign('pictures', get_goods_gallery_attr_www_ecshop68_com($goods_id, $goods_attr_id)); // 商品相册_修改 |
|
324 |
$smarty->assign('new_goods', get_recommend_goods('new')); // 最新商品 改 By |
|
325 |
$smarty->assign('url', $_SERVER["REQUEST_URI"]); |
|
326 |
assign_dynamic('exchange_goods'); |
|
327 |
} |
|
328 |
} |
|
329 |
|
|
330 |
$smarty->display('exchange_goods.dwt', $cache_id); |
|
331 |
} |
|
332 |
|
|
333 |
/*------------------------------------------------------ */ |
|
334 |
//-- 兑换 |
|
335 |
/*------------------------------------------------------ */ |
|
336 |
|
|
337 |
elseif ($_REQUEST['act'] == 'buy') |
|
338 |
{ |
|
339 |
/* 查询:判断是否登录 */ |
|
340 |
if (!isset($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) |
|
341 |
{ |
|
342 |
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'exchange') ? $GLOBALS['_SERVER']['HTTP_REFERER'] : './index.php'; |
|
343 |
} |
|
344 |
|
|
345 |
/* 查询:判断是否登录 */ |
|
346 |
if ($_SESSION['user_id'] <= 0) |
|
347 |
{ |
|
348 |
show_message($_LANG['eg_error_login'], array($_LANG['back_up_page']), array($back_act), 'error'); |
|
349 |
} |
|
350 |
|
|
351 |
/* 查询:取得参数:商品id */ |
|
352 |
$goods_id = isset($_POST['goods_id']) ? intval($_POST['goods_id']) : 0; |
|
353 |
if ($goods_id <= 0) |
|
354 |
{ |
|
355 |
ecs_header("Location: ./\n"); |
|
356 |
exit; |
|
357 |
} |
|
358 |
|
|
359 |
/* 查询:取得兑换商品信息 */ |
|
360 |
$goods = get_exchange_goods_info($goods_id); |
|
361 |
if (empty($goods)) |
|
362 |
{ |
|
363 |
ecs_header("Location: ./\n"); |
|
364 |
exit; |
|
365 |
} |
|
366 |
/* 查询:检查兑换商品是否有库存 */ |
|
367 |
if($goods['goods_number'] == 0 && $_CFG['use_storage'] == 1) |
|
368 |
{ |
|
369 |
show_message($_LANG['eg_error_number'], array($_LANG['back_up_page']), array($back_act), 'error'); |
|
370 |
} |
|
371 |
/* 查询:检查兑换商品是否是取消 */ |
|
372 |
if ($goods['is_exchange'] == 0) |
|
373 |
{ |
|
374 |
show_message($_LANG['eg_error_status'], array($_LANG['back_up_page']), array($back_act), 'error'); |
|
375 |
} |
|
376 |
|
|
377 |
$user_info = get_user_info($_SESSION['user_id']); |
|
378 |
$user_points = $user_info['pay_points']; // 用户的积分总数 |
|
379 |
if ($goods['exchange_integral'] > $user_points) |
|
380 |
{ |
|
381 |
show_message($_LANG['eg_error_integral'], array($_LANG['back_up_page']), array($back_act), 'error'); |
|
382 |
} |
|
383 |
|
|
384 |
/* 查询:取得规格 */ |
|
385 |
$specs = ''; |
|
386 |
foreach ($_POST as $key => $value) |
|
387 |
{ |
|
388 |
if (strpos($key, 'value_spec_') !== false) |
|
389 |
{ |
|
390 |
$specs .= ',' . intval($value); |
|
391 |
} |
|
392 |
} |
|
393 |
$specs = trim($specs, ','); |
|
394 |
/* 查询:如果商品有规格则取规格商品信息 配件除外 */ |
|
395 |
if (!empty($specs)) |
|
396 |
{ |
|
397 |
$_specs = explode(',', $specs); |
|
398 |
|
|
399 |
$product_info = get_products_info($goods_id, $_specs); |
|
400 |
} |
|
401 |
if (empty($product_info)) |
|
402 |
{ |
|
403 |
$product_info = array('product_number' => '', 'product_id' => 0); |
|
404 |
} |
|
405 |
|
|
406 |
//查询:商品存在规格 是货品 检查该货品库存 |
|
407 |
if((!empty($specs)) && ($product_info['product_number'] == 0) && ($_CFG['use_storage'] == 1)) |
|
408 |
{ |
|
409 |
show_message($_LANG['eg_error_number'], array($_LANG['back_up_page']), array($back_act), 'error'); |
|
410 |
} |
|
411 |
|
|
412 |
/* 查询:查询规格名称和值,不考虑价格 */ |
|
413 |
$attr_list = array(); |
|
414 |
$sql = "SELECT a.attr_name, g.attr_value " . |
|
415 |
"FROM " . $ecs->table('goods_attr') . " AS g, " . |
|
416 |
$ecs->table('attribute') . " AS a " . |
|
417 |
"WHERE g.attr_id = a.attr_id " . |
|
418 |
"AND g.goods_attr_id " . db_create_in($specs); |
|
419 |
$res = $db->query($sql); |
|
420 |
while ($row = $db->fetchRow($res)) |
|
421 |
{ |
|
422 |
$attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; |
|
423 |
} |
|
424 |
$goods_attr = join(chr(13) . chr(10), $attr_list); |
|
425 |
|
|
426 |
/* 更新:清空购物车中所有团购商品 */ |
|
427 |
include_once(ROOT_PATH . 'includes/lib_order.php'); |
|
428 |
clear_cart(CART_EXCHANGE_GOODS); |
|
429 |
|
|
430 |
/* 更新:加入购物车 */ |
|
431 |
$number = 1; |
|
432 |
$cart = array( |
|
433 |
'user_id' => $_SESSION['user_id'], |
|
434 |
'session_id' => SESS_ID, |
|
435 |
'goods_id' => $goods['goods_id'], |
|
436 |
'product_id' => $product_info['product_id'], |
|
437 |
'goods_sn' => addslashes($goods['goods_sn']), |
|
438 |
'goods_name' => addslashes($goods['goods_name']), |
|
439 |
'market_price' => $goods['market_price'], |
|
440 |
'goods_price' => 0,//$goods['exchange_integral'] |
|
441 |
'goods_number' => $number, |
|
442 |
'goods_attr' => addslashes($goods_attr), |
|
443 |
'goods_attr_id' => $specs, |
|
444 |
'is_real' => $goods['is_real'], |
|
445 |
'extension_code' => addslashes($goods['extension_code']), |
|
446 |
'parent_id' => 0, |
|
447 |
'rec_type' => CART_EXCHANGE_GOODS, |
|
448 |
'is_gift' => 0 |
|
449 |
); |
|
450 |
$db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); |
|
451 |
$_SESSION['sel_cartgoods'] = $db->insert_id(); |
|
452 |
/* 记录购物流程类型:团购 */ |
|
453 |
$_SESSION['flow_type'] = CART_EXCHANGE_GOODS; |
|
454 |
$_SESSION['extension_code'] = 'exchange_goods'; |
|
455 |
$_SESSION['extension_id'] = $goods_id; |
|
456 |
|
|
457 |
|
|
458 |
/* 进入收货人页面 */ |
|
459 |
ecs_header("Location: ./flow.php?step=checkout\n"); |
|
460 |
exit; |
|
461 |
} |
|
462 |
|
|
463 |
/*------------------------------------------------------ */ |
|
464 |
//-- PRIVATE FUNCTION |
|
465 |
/*------------------------------------------------------ */ |
|
466 |
|
|
467 |
/** |
|
468 |
* 获得分类的信息 |
|
469 |
* |
|
470 |
* @param integer $cat_id |
|
471 |
* |
|
472 |
* @return void |
|
473 |
*/ |
|
474 |
function get_cat_info($cat_id) |
|
475 |
{ |
|
476 |
return $GLOBALS['db']->getRow('SELECT keywords, cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') . |
|
477 |
" WHERE cat_id = '$cat_id'"); |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* 获得分类下的商品 |
|
482 |
* |
|
483 |
* @access public |
|
484 |
* @param string $children |
|
485 |
* @return array |
|
486 |
*/ |
|
487 |
function exchange_get_goods($children, $min, $max, $ext, $size, $page, $sort, $order) |
|
488 |
{ |
|
489 |
$display = $GLOBALS['display']; |
|
490 |
$where = "eg.is_exchange = 1 AND g.is_delete = 0 AND ". |
|
491 |
"($children OR " . get_extension_goods($children) . ')'; |
|
492 |
|
|
493 |
if ($min > 0) |
|
494 |
{ |
|
495 |
$where .= " AND eg.exchange_integral >= $min "; |
|
496 |
} |
|
497 |
|
|
498 |
if ($max > 0) |
|
499 |
{ |
|
500 |
$where .= " AND eg.exchange_integral <= $max "; |
|
501 |
} |
|
502 |
|
|
503 |
/* 获得商品列表 */ |
|
504 |
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral, ' . |
|
505 |
'g.goods_type, g.goods_brief, g.goods_thumb , g.goods_img, eg.is_hot ' . |
|
506 |
'FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg, ' .$GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
507 |
"WHERE eg.goods_id = g.goods_id AND $where $ext ORDER BY $sort $order"; |
|
508 |
|
|
509 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); |
|
510 |
|
|
511 |
$arr = array(); |
|
512 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
513 |
{ |
|
514 |
/* 处理商品水印图片 */ |
|
515 |
$watermark_img = ''; |
|
516 |
|
|
517 |
// if ($row['is_new'] != 0) |
|
518 |
// { |
|
519 |
// $watermark_img = "watermark_new_small"; |
|
520 |
// } |
|
521 |
// elseif ($row['is_best'] != 0) |
|
522 |
// { |
|
523 |
// $watermark_img = "watermark_best_small"; |
|
524 |
// } |
|
525 |
// else |
|
526 |
if ($row['is_hot'] != 0) |
|
527 |
{ |
|
528 |
$watermark_img = 'watermark_hot_small'; |
|
529 |
} |
|
530 |
|
|
531 |
if ($watermark_img != '') |
|
532 |
{ |
|
533 |
$arr[$row['goods_id']]['watermark_img'] = $watermark_img; |
|
534 |
} |
|
535 |
|
|
536 |
$arr[$row['goods_id']]['goods_id'] = $row['goods_id']; |
|
537 |
if($display == 'grid') |
|
538 |
{ |
|
539 |
$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']; |
|
540 |
} |
|
541 |
else |
|
542 |
{ |
|
543 |
$arr[$row['goods_id']]['goods_name'] = $row['goods_name']; |
|
544 |
} |
|
545 |
$arr[$row['goods_id']]['name'] = $row['goods_name']; |
|
546 |
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; |
|
547 |
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); |
|
548 |
$arr[$row['goods_id']]['exchange_integral'] = $row['exchange_integral']; |
|
549 |
$arr[$row['goods_id']]['type'] = $row['goods_type']; |
|
550 |
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
551 |
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
552 |
$arr[$row['goods_id']]['url'] = build_uri('exchange_goods', array('gid'=>$row['goods_id']), $row['goods_name']); |
|
553 |
} |
|
554 |
|
|
555 |
return $arr; |
|
556 |
} |
|
557 |
|
|
558 |
/** |
|
559 |
* 获得分类下的商品总数 |
|
560 |
* |
|
561 |
* @access public |
|
562 |
* @param string $cat_id |
|
563 |
* @return integer |
|
564 |
*/ |
|
565 |
function get_exchange_goods_count($children, $min = 0, $max = 0, $ext='') |
|
566 |
{ |
|
567 |
$where = "eg.is_exchange = 1 AND g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')'; |
|
568 |
|
|
569 |
|
|
570 |
if ($min > 0) |
|
571 |
{ |
|
572 |
$where .= " AND eg.exchange_integral >= $min "; |
|
573 |
} |
|
574 |
|
|
575 |
if ($max > 0) |
|
576 |
{ |
|
577 |
$where .= " AND eg.exchange_integral <= $max "; |
|
578 |
} |
|
579 |
|
|
580 |
$sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg, ' . |
|
581 |
$GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND $where $ext"; |
|
582 |
|
|
583 |
/* 返回商品总数 */ |
|
584 |
return $GLOBALS['db']->getOne($sql); |
|
585 |
} |
|
586 |
|
|
587 |
/** |
|
588 |
* 获得指定分类下的推荐商品 |
|
589 |
* |
|
590 |
* @access public |
|
591 |
* @param string $type 推荐类型,可以是 best, new, hot, promote |
|
592 |
* @param string $cats 分类的ID |
|
593 |
* @param integer $min 商品积分下限 |
|
594 |
* @param integer $max 商品积分上限 |
|
595 |
* @param string $ext 商品扩展查询 |
|
596 |
* @return array |
|
597 |
*/ |
|
598 |
function get_exchange_recommend_goods($type = '', $cats = '', $min =0, $max = 0, $ext='') |
|
599 |
{ |
|
600 |
$price_where = ($min > 0) ? " AND g.shop_price >= $min " : ''; |
|
601 |
$price_where .= ($max > 0) ? " AND g.shop_price <= $max " : ''; |
|
602 |
|
|
603 |
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral, ' . |
|
604 |
'g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . |
|
605 |
'FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg ' . |
|
606 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = eg.goods_id ' . |
|
607 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . |
|
608 |
'WHERE eg.is_exchange = 1 AND g.is_delete = 0 ' . $price_where . $ext; |
|
609 |
$num = 0; |
|
610 |
$type2lib = array('best'=>'exchange_best', 'new'=>'exchange_new', 'hot'=>'exchange_hot'); |
|
611 |
$num = get_library_number($type2lib[$type], 'exchange_list'); |
|
612 |
|
|
613 |
switch ($type) |
|
614 |
{ |
|
615 |
case 'best': |
|
616 |
$sql .= ' AND eg.is_best = 1'; |
|
617 |
break; |
|
618 |
case 'new': |
|
619 |
$sql .= ' AND eg.is_new = 1'; |
|
620 |
break; |
|
621 |
case 'hot': |
|
622 |
$sql .= ' AND eg.is_hot = 1'; |
|
623 |
break; |
|
624 |
} |
|
625 |
|
|
626 |
if (!empty($cats)) |
|
627 |
{ |
|
628 |
$sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")"; |
|
629 |
} |
|
630 |
$order_type = $GLOBALS['_CFG']['recommend_order']; |
|
631 |
$sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()'; |
|
632 |
$res = $GLOBALS['db']->selectLimit($sql, $num); |
|
633 |
|
|
634 |
$idx = 0; |
|
635 |
$goods = array(); |
|
636 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
637 |
{ |
|
638 |
$goods[$idx]['id'] = $row['goods_id']; |
|
639 |
$goods[$idx]['name'] = $row['goods_name']; |
|
640 |
$goods[$idx]['brief'] = $row['goods_brief']; |
|
641 |
$goods[$idx]['brand_name'] = $row['brand_name']; |
|
642 |
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? |
|
643 |
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; |
|
644 |
$goods[$idx]['exchange_integral'] = $row['exchange_integral']; |
|
645 |
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
646 |
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
647 |
$goods[$idx]['url'] = build_uri('exchange_goods', array('gid' => $row['goods_id']), $row['goods_name']); |
|
648 |
|
|
649 |
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); |
|
650 |
$idx++; |
|
651 |
} |
|
652 |
|
|
653 |
return $goods; |
|
654 |
} |
|
655 |
|
|
656 |
/** |
|
657 |
* 获得积分兑换商品的详细信息 |
|
658 |
* |
|
659 |
* @access public |
|
660 |
* @param integer $goods_id |
|
661 |
* @return void |
|
662 |
*/ |
|
663 |
function get_exchange_goods_info($goods_id) |
|
664 |
{ |
|
665 |
$time = gmtime(); |
|
666 |
$sql = 'SELECT g.*, c.measure_unit, b.brand_id, b.brand_name AS goods_brand, eg.exchange_integral, eg.is_exchange ' . |
|
667 |
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
668 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg ON g.goods_id = eg.goods_id ' . |
|
669 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' . |
|
670 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON g.brand_id = b.brand_id ' . |
|
671 |
"WHERE g.goods_id = '$goods_id' AND g.is_delete = 0 " . |
|
672 |
'GROUP BY g.goods_id'; |
|
673 |
|
|
674 |
$row = $GLOBALS['db']->getRow($sql); |
|
675 |
|
|
676 |
if ($row !== false) |
|
677 |
{ |
|
678 |
/* 处理商品水印图片 */ |
|
679 |
$watermark_img = ''; |
|
680 |
|
|
681 |
if ($row['is_new'] != 0) |
|
682 |
{ |
|
683 |
$watermark_img = "watermark_new"; |
|
684 |
} |
|
685 |
elseif ($row['is_best'] != 0) |
|
686 |
{ |
|
687 |
$watermark_img = "watermark_best"; |
|
688 |
} |
|
689 |
elseif ($row['is_hot'] != 0) |
|
690 |
{ |
|
691 |
$watermark_img = 'watermark_hot'; |
|
692 |
} |
|
693 |
|
|
694 |
if ($watermark_img != '') |
|
695 |
{ |
|
696 |
$row['watermark_img'] = $watermark_img; |
|
697 |
} |
|
698 |
|
|
699 |
/* 修正重量显示 */ |
|
700 |
$row['goods_weight'] = (intval($row['goods_weight']) > 0) ? |
|
701 |
$row['goods_weight'] . $GLOBALS['_LANG']['kilogram'] : |
|
702 |
($row['goods_weight'] * 1000) . $GLOBALS['_LANG']['gram']; |
|
703 |
|
|
704 |
/* 修正上架时间显示 */ |
|
705 |
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); |
|
706 |
|
|
707 |
/* 修正商品图片 */ |
|
708 |
$row['goods_img'] = get_image_path($goods_id, $row['goods_img']); |
|
709 |
$row['goods_thumb'] = get_image_path($goods_id, $row['goods_thumb'], true); |
|
710 |
|
|
711 |
return $row; |
|
712 |
} |
|
713 |
else |
|
714 |
{ |
|
715 |
return false; |
|
716 |
} |
|
717 |
} |
|
718 |
|
|
719 |
/* 代码增加_start */ |
|
720 |
/** |
|
721 |
* 获得指定商品的相册 |
|
722 |
* |
|
723 |
* @access public |
|
724 |
* @param integer $goods_id |
|
725 |
* @return array |
|
726 |
*/ |
|
727 |
function get_goods_gallery_attr_www_ecshop68_com($goods_id, $goods_attr_id) |
|
728 |
{ |
|
729 |
|
|
730 |
$sql = 'SELECT img_id, img_original, img_url, thumb_url, img_desc' . |
|
731 |
' FROM ' . $GLOBALS['ecs']->table('goods_gallery') . |
|
732 |
" WHERE goods_id = '$goods_id' and goods_attr_id='$goods_attr_id' LIMIT " . $GLOBALS['_CFG']['goods_gallery_number']; |
|
733 |
$row = $GLOBALS['db']->getAll($sql); |
|
734 |
if (count($row)==0) |
|
735 |
{ |
|
736 |
$sql = 'SELECT img_id, img_original, img_url, thumb_url, img_desc' . |
|
737 |
' FROM ' . $GLOBALS['ecs']->table('goods_gallery') . |
|
738 |
" WHERE goods_id = '$goods_id' and goods_attr_id='0' LIMIT " . $GLOBALS['_CFG']['goods_gallery_number']; |
|
739 |
$row = $GLOBALS['db']->getAll($sql); |
|
740 |
} |
|
741 |
/* 格式化相册图片路径 */ |
|
742 |
foreach($row as $key => $gallery_img) |
|
743 |
{ |
|
744 |
$row[$key]['img_url'] = get_image_path($goods_id, $gallery_img['img_url'], false, 'gallery'); |
|
745 |
$row[$key]['thumb_url'] = get_image_path($goods_id, $gallery_img['thumb_url'], true, 'gallery'); |
|
746 |
$row[$key]['img_original'] = get_image_path($goods_id, $gallery_img['img_original'], true, 'gallery'); |
|
747 |
} |
|
748 |
return $row; |
|
749 |
} |
|
750 |
|
|
751 |
/* 代码增加_end */ |
|
752 |
?> |