commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
/** |
|
3 |
* 预售活动前台文件 |
|
4 |
*/ |
|
5 |
define('IN_ECS', true); |
|
6 |
|
|
7 |
require (dirname(__FILE__) . '/includes/init.php'); |
|
8 |
// require(dirname(__FILE__) . '/includes/lib_goods.php'); |
|
9 |
|
|
10 |
if((DEBUG_MODE & 2) != 2) |
|
11 |
{ |
|
12 |
$smarty->caching = true; |
|
13 |
} |
|
14 |
|
|
15 |
//线上红包 |
|
16 |
$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('bonus_type') . |
|
17 |
" WHERE send_type = '4'"; |
|
18 |
$row = $GLOBALS['db']->GetAll($sql); |
|
19 |
$time=time(); |
|
20 |
date_default_timezone_set('PRC'); |
|
21 |
$smarty->assign('time',$time); |
|
22 |
$smarty->assign('online_bonus',$row); |
|
23 |
|
|
24 |
//判断 弹框登陆 验证码是否显示 |
|
25 |
$captcha = intval($_CFG['captcha']); |
|
26 |
if(($captcha & CAPTCHA_LOGIN) && (! ($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0) |
|
27 |
{ |
|
28 |
$GLOBALS['smarty']->assign('enabled_captcha', 1); |
|
29 |
$GLOBALS['smarty']->assign('rand', mt_rand()); |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
/* ------------------------------------------------------ */ |
|
35 |
// -- act 操作项的初始化 |
|
36 |
/* ------------------------------------------------------ */ |
|
37 |
if(empty($_REQUEST['act'])) |
|
38 |
{ |
|
39 |
// 没有ID则跳转到预售商品详情页 |
|
40 |
if(empty($_REQUEST['id'])) |
|
41 |
{ |
|
42 |
$_REQUEST['act'] = 'list'; |
|
43 |
} |
|
44 |
// 有ID则跳转到预售商品详情页 |
|
45 |
else |
|
46 |
{ |
|
47 |
$_REQUEST['act'] = 'view'; |
|
48 |
} |
|
49 |
}elseif ($_REQUEST['act'] == 'buy'){ |
|
50 |
|
|
51 |
$smarty = $GLOBALS['smarty']; |
|
52 |
$db = $GLOBALS['db']; |
|
53 |
$ecs = $GLOBALS['ecs']; |
|
54 |
|
|
55 |
/* 查询:判断是否登录 */ |
|
56 |
if($_SESSION['user_id'] <= 0) |
|
57 |
{ |
|
58 |
show_message('您还没有登录,请登录', '登录', 'user.php', 'error'); |
|
59 |
} |
|
60 |
|
|
61 |
/* 查询:取得参数:预售活动id */ |
|
62 |
$pre_sale_id = isset($_POST['pre_sale_id']) ? intval($_POST['pre_sale_id']) : 0; |
|
63 |
|
|
64 |
if($pre_sale_id <= 0) |
|
65 |
{ |
|
66 |
ecs_header("Location: pre_sale.php\n"); |
|
67 |
exit(); |
|
68 |
} |
|
69 |
|
|
70 |
/* 查询:取得数量 */ |
|
71 |
$number = isset($_POST['number']) ? intval($_POST['number']) : 1; |
|
72 |
$number = $number < 1 ? 1 : $number; |
|
73 |
|
|
74 |
/* 查询:取得预售活动信息 */ |
|
75 |
$pre_sale = pre_sale_info($pre_sale_id, $number); |
|
76 |
if(empty($pre_sale)) |
|
77 |
{ |
|
78 |
ecs_header("Location: pre_sale.php\n"); |
|
79 |
exit(); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
/* 查询:检查预售活动是否是进行中 */ |
|
86 |
if($pre_sale['status'] != PSS_UNDER_WAY) |
|
87 |
{ |
|
88 |
show_message($_LANG['ps_error_status'], '', '', 'error'); |
|
89 |
} |
|
90 |
|
|
91 |
/* 查询:取得预售商品信息 */ |
|
92 |
$goods = goods_info($pre_sale['goods_id']); |
|
93 |
if(empty($goods)) |
|
94 |
{ |
|
95 |
ecs_header("Location: pre_sale.php\n"); |
|
96 |
exit(); |
|
97 |
} |
|
98 |
|
|
99 |
/* 查询:判断数量是否足够 */ |
|
100 |
if(($pre_sale['restrict_amount'] > 0 && $number > ($pre_sale['restrict_amount'] - $pre_sale['valid_goods'])) || $number > $goods['goods_number']) |
|
101 |
{ |
|
102 |
show_message($_LANG['ps_error_goods_lacking'], '', '', 'error'); |
|
103 |
} |
|
104 |
|
|
105 |
/* 查询:取得规格 */ |
|
106 |
$specs = ''; |
|
107 |
foreach($_POST as $key => $value) |
|
108 |
{ |
|
109 |
if(strpos($key, 'spec_') !== false) |
|
110 |
{ |
|
111 |
$specs .= ',' . intval($value); |
|
112 |
} |
|
113 |
} |
|
114 |
$specs = trim($specs, ','); |
|
115 |
|
|
116 |
/* 查询:如果商品有规格则取规格商品信息 配件除外 */ |
|
117 |
if($specs) |
|
118 |
{ |
|
119 |
$_specs = explode(',', $specs); |
|
120 |
$product_info = get_products_info($goods['goods_id'], $_specs); |
|
121 |
} |
|
122 |
|
|
123 |
empty($product_info) ? $product_info = array( |
|
124 |
'product_number' => 0, 'product_id' => 0 |
|
125 |
) : ''; |
|
126 |
|
|
127 |
/* 查询:判断指定规格的货品数量是否足够 */ |
|
128 |
if($specs && $number > $product_info['product_number'] && false) // 测试 |
|
129 |
{ |
|
130 |
show_message($_LANG['ps_error_goods_lacking'], '', '', 'error'); |
|
131 |
} |
|
132 |
|
|
133 |
/* 查询:查询规格名称和值,不考虑价格 */ |
|
134 |
$attr_list = array(); |
|
135 |
$sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs); |
|
136 |
$res = $db->query($sql); |
|
137 |
while($row = $db->fetchRow($res)) |
|
138 |
{ |
|
139 |
$attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; |
|
140 |
} |
|
141 |
$goods_attr = join(chr(13) . chr(10), $attr_list); |
|
142 |
|
|
143 |
/* 更新:清空购物车中所有预售商品 */ |
|
144 |
include_once (ROOT_PATH . 'includes/lib_order.php'); |
|
145 |
clear_cart(6); |
|
146 |
|
|
147 |
/* 更新:加入购物车 */ |
|
148 |
$goods_price = $pre_sale['deposit'] > 0 ? $pre_sale['deposit'] : $pre_sale['cur_price']; |
|
149 |
$cart = array( |
|
150 |
'user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $pre_sale['goods_id'], 'product_id' => $product_info['product_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => $goods_price, 'goods_number' => $number, 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $specs, 'is_real' => $goods['is_real'], 'extension_code' => addslashes($goods['extension_code']), 'parent_id' => 0, 'rec_type' => 6, 'is_gift' => 0 |
|
151 |
); |
|
152 |
$db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); |
|
153 |
$_SESSION['sel_cartgoods'] = $db->insert_id(); |
|
154 |
$_SESSION['pre_sale_cart'] = $cart; |
|
155 |
|
|
156 |
/* 更新:记录购物流程类型:预售 */ |
|
157 |
$_SESSION['flow_type'] = '6'; |
|
158 |
$_SESSION['extension_code'] = 'pre_sale'; |
|
159 |
$_SESSION['extension_id'] = $pre_sale_id; |
|
160 |
|
|
161 |
|
|
162 |
$GLOBALS['db']->query("UPDATE ".$GLOBALS['ecs']->table('cart')." set extension_code='pre_sale',rec_type='6' where goods_id=".$goods['goods_id']." AND user_id=".$_SESSION['user_id']); |
|
163 |
|
|
164 |
ecs_header("Location: ./flow.php?step=consignee\n"); |
|
165 |
return ; |
|
166 |
} |
|
167 |
|
|
168 |
|
|
169 |
$function_name = 'action_' . $_REQUEST['act']; |
|
170 |
|
|
171 |
if(! function_exists($function_name)) |
|
172 |
{ |
|
173 |
|
|
174 |
$function_name = 'action_list'; |
|
175 |
} |
|
176 |
|
|
177 |
call_user_func($function_name); |
|
178 |
|
|
179 |
return; |
|
180 |
|
|
181 |
/* ------------------------------------------------------ */ |
|
182 |
// -- 预售商品 --> 预售活动商品列表 |
|
183 |
/* ------------------------------------------------------ */ |
|
184 |
function action_list () |
|
185 |
{ |
|
186 |
$smarty = $GLOBALS['smarty']; |
|
187 |
|
|
188 |
/* 取得预售活动总数 */ |
|
189 |
$count = pre_sale_count(); |
|
190 |
if($count > 0) |
|
191 |
{ |
|
192 |
/* 取得每页记录数 */ |
|
193 |
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 12; |
|
194 |
|
|
195 |
/* 计算总页数 */ |
|
196 |
$page_count = ceil($count / $size); |
|
197 |
|
|
198 |
/* 取得当前页 */ |
|
199 |
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1; |
|
200 |
$page = $page > $page_count ? $page_count : $page; |
|
201 |
|
|
202 |
/* 缓存id:语言 - 每页记录数 - 当前页 */ |
|
203 |
$cache_id = $_CFG['lang'] . '-' . $size . '-' . $page; |
|
204 |
$cache_id = sprintf('%X', crc32($cache_id)); |
|
205 |
} |
|
206 |
else |
|
207 |
{ |
|
208 |
/* 缓存id:语言 */ |
|
209 |
$cache_id = $_CFG['lang']; |
|
210 |
$cache_id = sprintf('%X', crc32($cache_id)); |
|
211 |
} |
|
212 |
|
|
213 |
assign_template(); |
|
214 |
clear_cache_files(); |
|
215 |
/* 如果没有缓存,生成缓存 */ |
|
216 |
if(! $smarty->is_cached('pre_sale_list.dwt', $cache_id) || true) |
|
217 |
{ |
|
218 |
if($count > 0) |
|
219 |
{ |
|
220 |
/* 取得当前页的预售活动 */ |
|
221 |
$ps_list = pre_sale_list($size, $page); |
|
222 |
$smarty->assign('ps_list', $ps_list); |
|
223 |
|
|
224 |
/* 设置分页链接 */ |
|
225 |
$pager = get_pager('pre_sale.php', array( |
|
226 |
'act' => 'list' |
|
227 |
), $count, $page, $size); |
|
228 |
$smarty->assign('pager', $pager); |
|
229 |
} |
|
230 |
|
|
231 |
/* 模板赋值 */ |
|
232 |
$smarty->assign('cfg', $GLOBALS['_CFG']); |
|
233 |
assign_template(); |
|
234 |
$position = assign_ur_here('pre_sale'); |
|
235 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
236 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
237 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
238 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
239 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
240 |
$smarty->assign('promotion_info', get_promotion_info()); |
|
241 |
$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-typepre_sale.xml" : 'feed.php?type=pre_sale'); // RSS |
|
242 |
// URL |
|
243 |
|
|
244 |
assign_dynamic('pre_sale_list'); |
|
245 |
} |
|
246 |
|
|
247 |
|
|
248 |
//判断 弹框登陆 验证码是否显示 |
|
249 |
$captcha = intval($_CFG['captcha']); |
|
250 |
if(($captcha & CAPTCHA_LOGIN) && (! ($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0) |
|
251 |
{ |
|
252 |
$GLOBALS['smarty']->assign('enabled_captcha', 1); |
|
253 |
$GLOBALS['smarty']->assign('rand', mt_rand()); |
|
254 |
} |
|
255 |
|
|
256 |
|
|
257 |
/* 显示模板 */ |
|
258 |
$smarty->display('pre_sale_list.dwt', $cache_id); |
|
259 |
} |
|
260 |
|
|
261 |
/* ------------------------------------------------------ */ |
|
262 |
// -- 预售商品 --> 商品详情 |
|
263 |
/* ------------------------------------------------------ */ |
|
264 |
function action_view () |
|
265 |
{ |
|
266 |
$smarty = $GLOBALS['smarty']; |
|
267 |
$db = $GLOBALS['db']; |
|
268 |
$ecs = $GLOBALS['ecs']; |
|
269 |
|
|
270 |
/* 取得参数:预售活动id */ |
|
271 |
$pre_sale_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; |
|
272 |
if($pre_sale_id <= 0) |
|
273 |
{ |
|
274 |
ecs_header("Location: pre_sale.php\n"); |
|
275 |
exit(); |
|
276 |
} |
|
277 |
|
|
278 |
/* 取得预售活动信息 */ |
|
279 |
$pre_sale = pre_sale_info($pre_sale_id); |
|
280 |
|
|
281 |
if(empty($pre_sale)) |
|
282 |
{ |
|
283 |
ecs_header("Location: pre_sale.php\n"); |
|
284 |
exit(); |
|
285 |
} |
|
286 |
// elseif ($pre_sale['is_on_sale'] == 0 || $pre_sale['is_alone_sale'] == 0) |
|
287 |
// { |
|
288 |
// header("Location: ./\n"); |
|
289 |
// exit; |
|
290 |
// } |
|
291 |
|
|
292 |
/* 评价数量 */ |
|
293 |
$pre_sale['comment_count'] = goods_comment_count($pre_sale['goods_id']); |
|
294 |
/* 累计销量 */ |
|
295 |
$pre_sale['sale_count'] = goods_sale_count($pre_sale['goods_id']); |
|
296 |
/* 赠送积分 */ |
|
297 |
$pre_sale['give_integral'] = $pre_sale['gift_integral']; |
|
298 |
|
|
299 |
/* 缓存id:语言,预售活动id,状态,(如果是进行中)当前数量和是否登录 */ |
|
300 |
$cache_id = $_CFG['lang'] . '-' . $pre_sale_id . '-' . $pre_sale['status']; |
|
301 |
// 活动进行中 |
|
302 |
if($pre_sale['status'] == PSS_UNDER_WAY) |
|
303 |
{ |
|
304 |
$cache_id = $cache_id . '-' . $pre_sale['valid_goods'] . '-' . intval($_SESSION['user_id'] > 0); |
|
305 |
} |
|
306 |
$cache_id = sprintf('%X', crc32($cache_id)); |
|
307 |
|
|
308 |
/* 如果没有缓存,生成缓存 */ |
|
309 |
if(! $smarty->is_cached('pre_sale_goods.dwt', $cache_id) || true) |
|
310 |
{ |
|
311 |
$pre_sale['gmt_end_date'] = $pre_sale['end_date']; |
|
312 |
$smarty->assign('pre_sale', $pre_sale); |
|
313 |
|
|
314 |
/* 取得预售商品信息 */ |
|
315 |
$goods_id = $pre_sale['goods_id']; |
|
316 |
$goods = get_goods_info($goods_id); |
|
317 |
if(empty($goods)) |
|
318 |
{ |
|
319 |
ecs_header("Location: pre_sale.php\n"); |
|
320 |
exit(); |
|
321 |
} |
|
322 |
$goods['url'] = build_uri('goods', array( |
|
323 |
'gid' => $goods_id |
|
324 |
), $goods['goods_name']); |
|
325 |
|
|
326 |
$goods = array_merge($goods, $pre_sale); |
|
327 |
|
|
328 |
$gift_integral = $pre_sale['gift_integral']; |
|
329 |
|
|
330 |
$goods['give_integral'] = $pre_sale['gift_integral']; |
|
331 |
|
|
332 |
// $parent_cat_id = get_parent_cat_id($goods['cat_id']); |
|
333 |
// $goods['child_cat'] = get_child_cat($parent_cat_id); // 相关分类 |
|
334 |
// $goods['get_cat_brands'] = get_cat_brands($parent_cat_id);; // 同类品牌 |
|
335 |
|
|
336 |
if ($goods['brand_id'] > 0) |
|
337 |
{ |
|
338 |
$goods['goods_brand_url'] = build_uri('brand', array('bid'=>$goods['brand_id']), $goods['goods_brand']); |
|
339 |
} |
|
340 |
|
|
341 |
$smarty->assign('url', $_SERVER["REQUEST_URI"]); |
|
342 |
$smarty->assign('volume_price', $goods_volume_price); |
|
343 |
$smarty->assign('goods_id', $goods['goods_id']); |
|
344 |
$smarty->assign('promote_end_time', $goods['gmt_end_time']); |
|
345 |
|
|
346 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
347 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
348 |
$smarty->assign('promotion_info', get_promotion_info()); |
|
349 |
|
|
350 |
|
|
351 |
$count1 = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('comment') . " where comment_type=0 and id_value ='$goods_id' and status=1"); |
|
352 |
$smarty->assign('review_count', $count1); // 评论数 |
|
353 |
|
|
354 |
|
|
355 |
$rank_num['rank_a'] = $GLOBALS['db']->getOne("SELECT COUNT(*) AS num FROM " . $GLOBALS['ecs']->table('comment') . " WHERE id_value = '$goods_id' AND status = 1 AND comment_rank in (5,4)"); |
|
356 |
$rank_num['rank_b'] = $GLOBALS['db']->getOne("SELECT COUNT(*) AS num FROM " . $GLOBALS['ecs']->table('comment') . " WHERE id_value = '$goods_id' AND status = 1 AND comment_rank in (3,2)"); |
|
357 |
$rank_num['rank_c'] = $GLOBALS['db']->getOne("SELECT COUNT(*) AS num FROM " . $GLOBALS['ecs']->table('comment') . " WHERE id_value = '$goods_id' AND status = 1 AND comment_rank = 1"); |
|
358 |
$rank_num['rank_total'] = $rank_num['rank_a'] + $rank_num['rank_b'] + $rank_num['rank_c']; |
|
359 |
$rank_num['rank_pa'] = ($rank_num['rank_a'] > 0) ? round(($rank_num['rank_a'] / $rank_num['rank_total']) * 100, 1) : 0; |
|
360 |
$rank_num['rank_pb'] = ($rank_num['rank_b'] > 0) ? round(($rank_num['rank_b'] / $rank_num['rank_total']) * 100, 1) : 0; |
|
361 |
$rank_num['rank_pc'] = ($rank_num['rank_c'] > 0) ? round(($rank_num['rank_c'] / $rank_num['rank_total']) * 100, 1) : 0; |
|
362 |
$rank_num['shaidan_num'] = $GLOBALS['db']->getOne("SELECT COUNT(*) AS num FROM " . $GLOBALS['ecs']->table('shaidan') . " WHERE goods_id = '$goods_id' AND status = 1"); |
|
363 |
$smarty->assign('rank_num', $rank_num); |
|
364 |
|
|
365 |
$res = $GLOBALS['db']->getAll("SELECT * FROM " . $GLOBALS['ecs']->table('goods_tag') . " WHERE goods_id = '$goods_id' AND state = 1"); |
|
366 |
foreach($res as $v) |
|
367 |
{ |
|
368 |
$v['tag_num'] = $GLOBALS['db']->getOne("SELECT COUNT(*) AS num FROM " . $GLOBALS['ecs']->table('comment') . " WHERE id_value = '$goods_id' AND status = 1 AND FIND_IN_SET($v[tag_id],comment_tag)"); |
|
369 |
$tag_arr[] = $v; |
|
370 |
} |
|
371 |
require_once 'includes/lib_comment.php'; |
|
372 |
$tag_arr = array_sort($tag_arr, 'tag_num', 'desc'); |
|
373 |
if($tag_arr) |
|
374 |
{ |
|
375 |
foreach($tag_arr as $key => $val) |
|
376 |
{ |
|
377 |
if($_CFG['tag_show_num'] > 0) |
|
378 |
{ |
|
379 |
if(($key + 1) <= $_CFG['tag_show_num']) |
|
380 |
{ |
|
381 |
$comment_tags[] = $val; |
|
382 |
} |
|
383 |
} |
|
384 |
else |
|
385 |
{ |
|
386 |
$comment_tags[] = $val; |
|
387 |
} |
|
388 |
} |
|
389 |
} |
|
390 |
$smarty->assign('comment_tags', $comment_tags); |
|
391 |
|
|
392 |
/* meta */ |
|
393 |
$smarty->assign('keywords', htmlspecialchars($goods['keywords'])); |
|
394 |
$smarty->assign('description', htmlspecialchars($goods['goods_brief'])); |
|
395 |
|
|
396 |
$goods['goods_style_name'] = add_style($goods['goods_name'], $goods['goods_name_style']); |
|
397 |
$smarty->assign('goods', $goods); |
|
398 |
$smarty->assign('goods_id', $goods['goods_id']); |
|
399 |
|
|
400 |
/* 取得商品的规格 */ |
|
401 |
$properties = get_goods_properties($goods_id); |
|
402 |
$smarty->assign('specification', $properties['spe']); // 商品规格 |
|
403 |
$smarty->assign('pictures', get_goods_gallery_attr_2($goods_id, $goods_attr_id)); // 商品相册 |
|
404 |
$smarty->assign('new_goods', get_recommend_goods('new')); // 最新商品 |
|
405 |
$smarty->assign('shop_country', $_CFG['shop_country']); |
|
406 |
|
|
407 |
|
|
408 |
$sql_attr = "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 "; |
|
409 |
$goods_attr = $GLOBALS['db']->getRow($sql_attr); |
|
410 |
if($goods_attr) |
|
411 |
{ |
|
412 |
$goods_attr_id = $goods_attr['goods_attr_id']; |
|
413 |
$smarty->assign('attr_id', $goods_attr['attr_id']); |
|
414 |
} |
|
415 |
else |
|
416 |
{ |
|
417 |
$smarty->assign('attr_id', 0); |
|
418 |
} |
|
419 |
|
|
420 |
$prod_exist_arr = array(); |
|
421 |
$sql_prod = "select goods_attr from " . $GLOBALS['ecs']->table('products') . " where product_number>0 and goods_id='$goods_id' order by goods_attr"; |
|
422 |
$res_prod = $GLOBALS['db']->query($sql_prod); |
|
423 |
while($row_prod = $GLOBALS['db']->fetchRow($res_prod)) |
|
424 |
{ |
|
425 |
$prod_exist_arr[] = "|" . $row_prod['goods_attr'] . "|"; |
|
426 |
} |
|
427 |
$smarty->assign('prod_exist_arr', $prod_exist_arr); |
|
428 |
|
|
429 |
// 模板赋值 |
|
430 |
$smarty->assign('cfg', $GLOBALS['_CFG']); |
|
431 |
assign_template(); |
|
432 |
|
|
433 |
$position = assign_ur_here(0, $goods['goods_name']); |
|
434 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
435 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
436 |
|
|
437 |
|
|
438 |
$goods['supplier_name'] = "网站自营"; |
|
439 |
if($goods['supplier_id'] > 0) |
|
440 |
{ |
|
441 |
$sql_supplier = "SELECT s.supplier_id,s.supplier_name,s.add_time,sr.rank_name FROM " . $ecs->table("supplier") . " as s left join " . $ecs->table("supplier_rank") . " as sr ON s.rank_id=sr.rank_id WHERE s.supplier_id=" . $goods[supplier_id] . " AND s.status=1"; |
|
442 |
$shopuserinfo = $db->getRow($sql_supplier); |
|
443 |
$goods['supplier_name'] = $shopuserinfo['supplier_name']; |
|
444 |
get_dianpu_baseinfo($goods['supplier_id'], $shopuserinfo); |
|
445 |
} |
|
446 |
|
|
447 |
assign_dynamic('pre_sale_goods'); |
|
448 |
} |
|
449 |
|
|
450 |
// 更新商品点击次数 |
|
451 |
$sql = 'UPDATE ' . $GLOBALS['ecs']->table('goods') . ' SET click_count = click_count + 1 ' . "WHERE goods_id = '" . $pre_sale['goods_id'] . "'"; |
|
452 |
$GLOBALS['db']->query($sql); |
|
453 |
|
|
454 |
$smarty->assign('now_time', gmtime()); // 当前系统时间 |
|
455 |
|
|
456 |
|
|
457 |
//判断 弹框登陆 验证码是否显示 |
|
458 |
$captcha = intval($_CFG['captcha']); |
|
459 |
if(($captcha & CAPTCHA_LOGIN) && (! ($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0) |
|
460 |
{ |
|
461 |
$GLOBALS['smarty']->assign('enabled_captcha', 1); |
|
462 |
$GLOBALS['smarty']->assign('rand', mt_rand()); |
|
463 |
} |
|
464 |
|
|
465 |
$smarty->display('pre_sale_goods.dwt', $cache_id); |
|
466 |
} |
|
467 |
|
|
468 |
/* ------------------------------------------------------ */ |
|
469 |
// -- 预售商品 --> 购买 |
|
470 |
/* ------------------------------------------------------ */ |
|
471 |
function action_buy () |
|
472 |
{ |
|
473 |
$smarty = $GLOBALS['smarty']; |
|
474 |
$db = $GLOBALS['db']; |
|
475 |
$ecs = $GLOBALS['ecs']; |
|
476 |
|
|
477 |
/* 查询:判断是否登录 */ |
|
478 |
if($_SESSION['user_id'] <= 0) |
|
479 |
{ |
|
480 |
show_message($_LANG['ps_error_login'], '', '', 'error'); |
|
481 |
} |
|
482 |
|
|
483 |
/* 查询:取得参数:预售活动id */ |
|
484 |
$pre_sale_id = isset($_POST['pre_sale_id']) ? intval($_POST['pre_sale_id']) : 0; |
|
485 |
if($pre_sale_id <= 0) |
|
486 |
{ |
|
487 |
ecs_header("Location: pre_sale.php\n"); |
|
488 |
exit(); |
|
489 |
} |
|
490 |
|
|
491 |
/* 查询:取得数量 */ |
|
492 |
$number = isset($_POST['number']) ? intval($_POST['number']) : 1; |
|
493 |
$number = $number < 1 ? 1 : $number; |
|
494 |
|
|
495 |
/* 查询:取得预售活动信息 */ |
|
496 |
$pre_sale = pre_sale_info($pre_sale_id, $number); |
|
497 |
if(empty($pre_sale)) |
|
498 |
{ |
|
499 |
ecs_header("Location: pre_sale.php\n"); |
|
500 |
exit(); |
|
501 |
} |
|
502 |
|
|
503 |
/* 查询:检查预售活动是否是进行中 */ |
|
504 |
if($pre_sale['status'] != PSS_UNDER_WAY) |
|
505 |
{ |
|
506 |
show_message($_LANG['ps_error_status'], '', '', 'error'); |
|
507 |
} |
|
508 |
|
|
509 |
/* 查询:取得预售商品信息 */ |
|
510 |
$goods = goods_info($pre_sale['goods_id']); |
|
511 |
if(empty($goods)) |
|
512 |
{ |
|
513 |
ecs_header("Location: pre_sale.php\n"); |
|
514 |
exit(); |
|
515 |
} |
|
516 |
|
|
517 |
/* 查询:判断数量是否足够 */ |
|
518 |
if(($pre_sale['restrict_amount'] > 0 && $number > ($pre_sale['restrict_amount'] - $pre_sale['valid_goods'])) || $number > $goods['goods_number']) |
|
519 |
{ |
|
520 |
show_message($_LANG['ps_error_goods_lacking'], '', '', 'error'); |
|
521 |
} |
|
522 |
|
|
523 |
/* 查询:取得规格 */ |
|
524 |
$specs = ''; |
|
525 |
foreach($_POST as $key => $value) |
|
526 |
{ |
|
527 |
if(strpos($key, 'spec_') !== false) |
|
528 |
{ |
|
529 |
$specs .= ',' . intval($value); |
|
530 |
} |
|
531 |
} |
|
532 |
$specs = trim($specs, ','); |
|
533 |
|
|
534 |
/* 查询:如果商品有规格则取规格商品信息 配件除外 */ |
|
535 |
if($specs) |
|
536 |
{ |
|
537 |
$_specs = explode(',', $specs); |
|
538 |
$product_info = get_products_info($goods['goods_id'], $_specs); |
|
539 |
} |
|
540 |
|
|
541 |
empty($product_info) ? $product_info = array( |
|
542 |
'product_number' => 0, 'product_id' => 0 |
|
543 |
) : ''; |
|
544 |
|
|
545 |
/* 查询:判断指定规格的货品数量是否足够 */ |
|
546 |
if($specs && $number > $product_info['product_number'] && false) // 测试 |
|
547 |
{ |
|
548 |
show_message($_LANG['ps_error_goods_lacking'], '', '', 'error'); |
|
549 |
} |
|
550 |
|
|
551 |
/* 查询:查询规格名称和值,不考虑价格 */ |
|
552 |
$attr_list = array(); |
|
553 |
$sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs); |
|
554 |
$res = $db->query($sql); |
|
555 |
while($row = $db->fetchRow($res)) |
|
556 |
{ |
|
557 |
$attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; |
|
558 |
} |
|
559 |
$goods_attr = join(chr(13) . chr(10), $attr_list); |
|
560 |
|
|
561 |
/* 更新:清空购物车中所有预售商品 */ |
|
562 |
include_once (ROOT_PATH . 'includes/lib_order.php'); |
|
563 |
clear_cart(CART_pre_sale_GOODS); |
|
564 |
|
|
565 |
/* 更新:加入购物车 */ |
|
566 |
$goods_price = $pre_sale['deposit'] > 0 ? $pre_sale['deposit'] : $pre_sale['cur_price']; |
|
567 |
$cart = array( |
|
568 |
'user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $pre_sale['goods_id'], 'product_id' => $product_info['product_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => $goods_price, 'goods_number' => $number, 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $specs, 'is_real' => $goods['is_real'], 'extension_code' => addslashes($goods['extension_code']), 'parent_id' => 0, 'rec_type' => CART_PRE_SALE_GOODS, 'is_gift' => 0 |
|
569 |
); |
|
570 |
$db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); |
|
571 |
$_SESSION['sel_cartgoods'] = $db->insert_id(); |
|
572 |
$_SESSION['pre_sale_cart'] = $cart; |
|
573 |
|
|
574 |
/* 更新:记录购物流程类型:预售 */ |
|
575 |
$_SESSION['flow_type'] = CART_PRE_SALE_GOODS; |
|
576 |
$_SESSION['extension_code'] = PRE_SALE_CODE; |
|
577 |
$_SESSION['extension_id'] = $pre_sale_id; |
|
578 |
|
|
579 |
/* 进入收货人页面 */ |
|
580 |
ecs_header("Location: ./flow.php?step=checkout\n"); |
|
581 |
exit(); |
|
582 |
} |
|
583 |
|
|
584 |
/* ------------------------------------------------------ */ |
|
585 |
// -- 预售商品 --> 检查预售订单,取消在尾款支付时间范围内尚未支付尾款的订单 |
|
586 |
/* ------------------------------------------------------ */ |
|
587 |
function action_check_order () |
|
588 |
{ |
|
589 |
$smarty = $GLOBALS['smarty']; |
|
590 |
$db = $GLOBALS['db']; |
|
591 |
$ecs = $GLOBALS['ecs']; |
|
592 |
|
|
593 |
/* 获取订单状态为 已确认、未付款、未发货 的 预售订单列表 */ |
|
594 |
$sql = "select a.*, (a.money_paid + a.surplus + a.integral_money + a.bonus) AS total_money, b.ext_info from " . $GLOBALS['ecs']->table('order_info') . " as a LEFT JOIN " . $GLOBALS['ecs']->table('goods_activity') . " as b on (a.extension_id = b.act_id) where (a.money_paid + a.surplus + a.integral_money + a.bonus) > 0 and a.extension_code = '" . PRE_SALE_CODE . "' and b.is_finished = " . PSS_SUCCEED . " and a.shipping_status = " . SS_UNSHIPPED . " and order_status = " . OS_CONFIRMED . " and pay_status = " . PS_UNPAYED; |
|
595 |
$order_list = $GLOBALS['db']->getAll($sql); |
|
596 |
|
|
597 |
foreach($order_list as $order) |
|
598 |
{ |
|
599 |
$ext_info = unserialize($order['ext_info']); |
|
600 |
// $order = array_merge($order, $ext_info); |
|
601 |
|
|
602 |
// 总金额:goods_amount + shipping_fee + insure_fee + pay_fee + pack_fee + |
|
603 |
// card_fee + tax - discount |
|
604 |
// $total_fee = $order['goods_amount'] + $order['shipping_fee'] + |
|
605 |
// $order['insure_fee'] + $order['pay_fee'] + $order['pack_fee'] + |
|
606 |
// $order['card_fee'] + $order['tax'] - $order['discount']; |
|
607 |
// 已支付:money_paid + surplus + integral_money + bonus |
|
608 |
// $total_money = $order['money_paid'] + $order['surplus'] + |
|
609 |
// $order['integral_money'] + $order['bonus']; |
|
610 |
|
|
611 |
// 已付金额 |
|
612 |
$total_money = $order['total_money']; |
|
613 |
// 定金 |
|
614 |
$deposit = $ext_info['deposit']; |
|
615 |
|
|
616 |
// 定金为0跳过 |
|
617 |
if($deposit == 0) |
|
618 |
{ |
|
619 |
continue; |
|
620 |
} |
|
621 |
|
|
622 |
// 已支付金额等于定金 |
|
623 |
if($total_money == $deposit) |
|
624 |
{ |
|
625 |
$retainage_start = $ext_info['retainage_start']; |
|
626 |
$retainage_end = $ext_info['retainage_end']; |
|
627 |
|
|
628 |
$cur_time = gmtime(); |
|
629 |
|
|
630 |
// 当前时间大于尾款支付结束时间则支付超时,取消订单 |
|
631 |
if($cur_time > $retainage_end) |
|
632 |
{ |
|
633 |
cancel_ps_order($order['order_id'], $order['user_id']); |
|
634 |
} |
|
635 |
} |
|
636 |
} |
|
637 |
} |
|
638 |
|
|
639 |
/* 取得预售活动总数 */ |
|
640 |
function pre_sale_count () |
|
641 |
{ |
|
642 |
$now = gmtime(); |
|
643 |
// $sql = "SELECT COUNT(*) " . "FROM " . |
|
644 |
// $GLOBALS['ecs']->table('goods_activity') . "WHERE act_type = '" . |
|
645 |
// GAT_PRE_SALE . "' " . "AND start_time <= '$now' AND is_finished < 3"; |
|
646 |
$sql = "SELECT COUNT(*) " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . "WHERE act_type = '" . GAT_PRE_SALE . "' " . " AND is_finished < 3"; |
|
647 |
|
|
648 |
return $GLOBALS['db']->getOne($sql); |
|
649 |
} |
|
650 |
|
|
651 |
/** |
|
652 |
* 取得某页的所有预售活动 |
|
653 |
* |
|
654 |
* @param int $size |
|
655 |
* 每页记录数 |
|
656 |
* @param int $page |
|
657 |
* 当前页 |
|
658 |
* @return array |
|
659 |
*/ |
|
660 |
function pre_sale_list ($size, $page) |
|
661 |
{ |
|
662 |
/* 取得预售活动 */ |
|
663 |
$ps_list = array(); |
|
664 |
$now = gmtime(); |
|
665 |
// $sql = "SELECT b.*, IFNULL(g.goods_thumb, '') AS goods_thumb, b.act_id AS |
|
666 |
// pre_sale_id, " . "b.start_time AS start_date, b.end_time AS end_date, |
|
667 |
// g.shop_price " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " |
|
668 |
// AS b " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON |
|
669 |
// b.goods_id = g.goods_id " . "WHERE b.act_type = '" . GAT_PRE_SALE . "' " |
|
670 |
// . "AND b.start_time <= '$now' AND b.is_finished < '" . PSS_SUCCEED . "' |
|
671 |
// ORDER BY b.act_id DESC"; |
|
672 |
/* 代码修改 By Start */ |
|
673 |
// $sql = "SELECT b.*, IFNULL(g.goods_thumb, '') AS goods_thumb, b.act_id AS pre_sale_id, " . "b.start_time AS start_date, b.end_time AS end_date, g.shop_price " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS b " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON b.goods_id = g.goods_id " . "WHERE b.act_type = '" . GAT_PRE_SALE . "' " . " AND b.is_finished < '" . PSS_SUCCEED . "' ORDER BY b.is_finished ASC"; |
|
674 |
$sql = "SELECT b.*, IFNULL(g.goods_thumb, '') AS goods_thumb, b.act_id AS pre_sale_id, " . "b.start_time AS start_date, b.end_time AS end_date, g.shop_price " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS b " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON b.goods_id = g.goods_id " . "WHERE b.act_type = '" . GAT_PRE_SALE . "' " . " AND b.is_finished < '" . PSS_SUCCEED . "' AND g.is_delete = 0 ORDER BY b.is_finished ASC"; |
|
675 |
|
|
676 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); |
|
677 |
while($pre_sale = $GLOBALS['db']->fetchRow($res)) |
|
678 |
{ |
|
679 |
$ext_info = unserialize($pre_sale['ext_info']); |
|
680 |
$pre_sale = array_merge($pre_sale, $ext_info); |
|
681 |
|
|
682 |
// $stat = pre_sale_stat($row['act_id'], $ext_info['deposit']); |
|
683 |
$stat = pre_sale_stat($pre_sale['act_id'], $ext_info['deposit']); |
|
684 |
|
|
685 |
$pre_sale = array_merge($pre_sale, $stat); |
|
686 |
|
|
687 |
/* 格式化时间 */ |
|
688 |
$pre_sale['formated_start_date'] = local_date($GLOBALS['_CFG']['time_format'], $pre_sale['start_time']); |
|
689 |
$pre_sale['formated_end_date'] = local_date($GLOBALS['_CFG']['time_format'], $pre_sale['end_time']); |
|
690 |
|
|
691 |
// 本地时间,用于倒计时显示,符合JS格式 |
|
692 |
$pre_sale['local_end_date'] = local_date('Y, m-1, d, H, i, s', $pre_sale['end_time']); |
|
693 |
$pre_sale['local_start_date'] = local_date('Y, m-1, d, H, i, s', $pre_sale['start_time']); |
|
694 |
|
|
695 |
/* 格式化保证金 */ |
|
696 |
$pre_sale['formated_deposit'] = price_format($pre_sale['deposit'], false); |
|
697 |
|
|
698 |
/* 处理价格阶梯 */ |
|
699 |
$price_ladder = $pre_sale['price_ladder']; |
|
700 |
if(! is_array($price_ladder) || empty($price_ladder)) |
|
701 |
{ |
|
702 |
$price_ladder = array( |
|
703 |
array( |
|
704 |
'amount' => 0, 'price' => 0 |
|
705 |
) |
|
706 |
); |
|
707 |
} |
|
708 |
else |
|
709 |
{ |
|
710 |
foreach($price_ladder as $key => $amount_price) |
|
711 |
{ |
|
712 |
$price_ladder[$key]['formated_price'] = price_format($amount_price['price']); |
|
713 |
} |
|
714 |
} |
|
715 |
$pre_sale['price_ladder'] = $price_ladder; |
|
716 |
|
|
717 |
/* 计算当前价 */ |
|
718 |
$cur_price = $price_ladder[0]['price']; // 初始化 |
|
719 |
$cur_amount = $stat['valid_goods']; // 当前数量 |
|
720 |
foreach($price_ladder as $amount_price) |
|
721 |
{ |
|
722 |
if($cur_amount >= $amount_price['amount']) |
|
723 |
{ |
|
724 |
$cur_price = $amount_price['price']; |
|
725 |
} |
|
726 |
else |
|
727 |
{ |
|
728 |
break; |
|
729 |
} |
|
730 |
} |
|
731 |
|
|
732 |
$pre_sale['cur_price'] = $cur_price; |
|
733 |
$pre_sale['formated_cur_price'] = price_format($cur_price, false); |
|
734 |
$pre_sale['formated_shope_price'] = price_format($pre_sale['shope_price'], false); |
|
735 |
|
|
736 |
$status = pre_sale_status($pre_sale); |
|
737 |
|
|
738 |
$pre_sale['start_time'] = local_date($GLOBALS['_CFG']['date_format'], $pre_sale['start_time']); |
|
739 |
$pre_sale['end_time'] = local_date($GLOBALS['_CFG']['date_format'], $pre_sale['end_time']); |
|
740 |
$pre_sale['cur_status'] = $GLOBALS['_LANG']['pss'][$status]; |
|
741 |
$pre_sale['status'] = $status; |
|
742 |
|
|
743 |
/* 处理图片 */ |
|
744 |
if(empty($pre_sale['goods_thumb'])) |
|
745 |
{ |
|
746 |
$pre_sale['goods_thumb'] = get_image_path($pre_sale['goods_id'], $pre_sale['goods_thumb'], true); |
|
747 |
} |
|
748 |
/* 处理链接 */ |
|
749 |
$pre_sale['url'] = build_uri('pre_sale', array( |
|
750 |
'pre_sale_id' => $pre_sale['pre_sale_id'] |
|
751 |
)); |
|
752 |
|
|
753 |
/* 加入数组 */ |
|
754 |
$ps_list[] = $pre_sale; |
|
755 |
} |
|
756 |
|
|
757 |
return $ps_list; |
|
758 |
} |
|
759 |
|
|
760 |
/** |
|
761 |
* 取消一个用户的预售订单 |
|
762 |
* |
|
763 |
* @access public |
|
764 |
* @param int $order_id |
|
765 |
* 订单ID |
|
766 |
* @param int $user_id |
|
767 |
* 用户ID |
|
768 |
* |
|
769 |
* @return void |
|
770 |
*/ |
|
771 |
function cancel_ps_order ($order_id, $user_id = 0) |
|
772 |
{ |
|
773 |
|
|
774 |
/* 查询订单信息,检查状态 */ |
|
775 |
$sql = "SELECT user_id, order_id, order_sn , surplus , integral , bonus_id, order_status, shipping_status, pay_status FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_id = '$order_id' and extension_code = '" . PRE_SALE_CODE . "'"; |
|
776 |
$order = $GLOBALS['db']->GetRow($sql); |
|
777 |
|
|
778 |
if(empty($order)) |
|
779 |
{ |
|
780 |
$GLOBALS['err']->add($GLOBALS['_LANG']['order_exist']); |
|
781 |
return false; |
|
782 |
} |
|
783 |
|
|
784 |
// 如果用户ID大于0,检查订单是否属于该用户 |
|
785 |
if($user_id > 0 && $order['user_id'] != $user_id) |
|
786 |
{ |
|
787 |
$GLOBALS['err']->add($GLOBALS['_LANG']['no_priv']); |
|
788 |
|
|
789 |
return false; |
|
790 |
} |
|
791 |
|
|
792 |
// 订单状态只能是“未确认”或“已确认” |
|
793 |
if($order['order_status'] != OS_UNCONFIRMED && $order['order_status'] != OS_CONFIRMED) |
|
794 |
{ |
|
795 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_os_not_unconfirmed']); |
|
796 |
|
|
797 |
return false; |
|
798 |
} |
|
799 |
|
|
800 |
// 发货状态只能是“未发货” |
|
801 |
if($order['shipping_status'] != SS_UNSHIPPED) |
|
802 |
{ |
|
803 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_ss_not_cancel']); |
|
804 |
|
|
805 |
return false; |
|
806 |
} |
|
807 |
|
|
808 |
// 如果付款状态是“已付款”、“付款中”,不允许取消,要取消和商家联系 |
|
809 |
if($order['pay_status'] != PS_UNPAYED) |
|
810 |
{ |
|
811 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_ps_not_cancel']); |
|
812 |
|
|
813 |
return false; |
|
814 |
} |
|
815 |
|
|
816 |
// 将用户订单设置为取消 |
|
817 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('order_info') . " SET order_status = '" . OS_CANCELED . "' WHERE order_id = '$order_id'"; |
|
818 |
if($GLOBALS['db']->query($sql)) |
|
819 |
{ |
|
820 |
/* 载入语言文件 */ |
|
821 |
require (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php'); |
|
822 |
|
|
823 |
// 记录log |
|
824 |
$note = $GLOBALS['_LANG']['ps_timeout_system_cancel']; |
|
825 |
order_action($order['order_sn'], OS_CANCELED, $order['shipping_status'], PS_UNPAYED, $note, 'system'); |
|
826 |
|
|
827 |
/** |
|
828 |
* // 退货用户余额、积分、红包 |
|
829 |
* if ($order['user_id'] > 0 && $order['surplus'] > 0) |
|
830 |
* { |
|
831 |
* $change_desc = sprintf($GLOBALS['_LANG']['return_surplus_on_cancel'], |
|
832 |
* $order['order_sn']); |
|
833 |
* log_account_change($order['user_id'], $order['surplus'], 0, 0, 0, |
|
834 |
* $change_desc); |
|
835 |
* } |
|
836 |
* if ($order['user_id'] > 0 && $order['integral'] > 0) |
|
837 |
* { |
|
838 |
* $change_desc = |
|
839 |
* sprintf($GLOBALS['_LANG']['return_integral_on_cancel'], |
|
840 |
* $order['order_sn']); |
|
841 |
* log_account_change($order['user_id'], 0, 0, 0, $order['integral'], |
|
842 |
* $change_desc); |
|
843 |
* } |
|
844 |
* if ($order['user_id'] > 0 && $order['bonus_id'] > 0) |
|
845 |
* { |
|
846 |
* change_user_bonus($order['bonus_id'], $order['order_id'], false); |
|
847 |
* } |
|
848 |
*/ |
|
849 |
|
|
850 |
// 如果使用库存,且下订单时减库存,则增加库存 |
|
851 |
if($GLOBALS['_CFG']['use_storage'] == '1' && $GLOBALS['_CFG']['stock_dec_time'] == SDT_PLACE) |
|
852 |
{ |
|
853 |
change_order_goods_storage($order['order_id'], false, 1); |
|
854 |
} |
|
855 |
|
|
856 |
/** |
|
857 |
* // 修改订单 |
|
858 |
* $arr = array( |
|
859 |
* 'bonus_id' => 0, |
|
860 |
* 'bonus' => 0, |
|
861 |
* 'integral' => 0, |
|
862 |
* 'integral_money' => 0, |
|
863 |
* 'surplus' => 0 |
|
864 |
* ); |
|
865 |
* update_order($order['order_id'], $arr); |
|
866 |
*/ |
|
867 |
|
|
868 |
return true; |
|
869 |
} |
|
870 |
else |
|
871 |
{ |
|
872 |
die($GLOBALS['db']->errorMsg()); |
|
873 |
} |
|
874 |
} |
|
875 |
|
|
876 |
/* ------------------------------------------------------ */ |
|
877 |
// -- PRIVATE FUNCTION |
|
878 |
/* ------------------------------------------------------ */ |
|
879 |
|
|
880 |
/** |
|
881 |
* 获得指定商品的关联商品 |
|
882 |
* |
|
883 |
* @access public |
|
884 |
* @param integer $goods_id |
|
885 |
* @return array |
|
886 |
*/ |
|
887 |
function get_linked_goods ($goods_id) |
|
888 |
{ |
|
889 |
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, " . 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' . 'FROM ' . $GLOBALS['ecs']->table('link_goods') . ' lg ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = lg.link_goods_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 lg.goods_id = '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . "LIMIT " . $GLOBALS['_CFG']['related_goods_number']; |
|
890 |
$res = $GLOBALS['db']->query($sql); |
|
891 |
|
|
892 |
$arr = array(); |
|
893 |
while($row = $GLOBALS['db']->fetchRow($res)) |
|
894 |
{ |
|
895 |
$arr[$row['goods_id']]['goods_id'] = $row['goods_id']; |
|
896 |
$arr[$row['goods_id']]['goods_name'] = $row['goods_name']; |
|
897 |
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; |
|
898 |
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
899 |
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
900 |
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); |
|
901 |
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); |
|
902 |
$arr[$row['goods_id']]['url'] = build_uri('goods', array( |
|
903 |
'gid' => $row['goods_id'] |
|
904 |
), $row['goods_name']); |
|
905 |
|
|
906 |
if($row['promote_price'] > 0) |
|
907 |
{ |
|
908 |
$arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); |
|
909 |
$arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']); |
|
910 |
} |
|
911 |
else |
|
912 |
{ |
|
913 |
$arr[$row['goods_id']]['promote_price'] = 0; |
|
914 |
} |
|
915 |
} |
|
916 |
|
|
917 |
return $arr; |
|
918 |
} |
|
919 |
|
|
920 |
/** |
|
921 |
* 获得指定商品的关联文章 |
|
922 |
* |
|
923 |
* @access public |
|
924 |
* @param integer $goods_id |
|
925 |
* @return void |
|
926 |
*/ |
|
927 |
function get_linked_articles ($goods_id) |
|
928 |
{ |
|
929 |
$sql = 'SELECT a.article_id, a.title, a.file_url, a.open_type, a.add_time ' . 'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' AS g, ' . $GLOBALS['ecs']->table('article') . ' AS a ' . "WHERE g.article_id = a.article_id AND g.goods_id = '$goods_id' AND a.is_open = 1 " . 'ORDER BY a.add_time DESC'; |
|
930 |
$res = $GLOBALS['db']->query($sql); |
|
931 |
|
|
932 |
$arr = array(); |
|
933 |
while($row = $GLOBALS['db']->fetchRow($res)) |
|
934 |
{ |
|
935 |
$row['url'] = $row['open_type'] != 1 ? build_uri('article', array( |
|
936 |
'aid' => $row['article_id'] |
|
937 |
), $row['title']) : trim($row['file_url']); |
|
938 |
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); |
|
939 |
$row['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; |
|
940 |
|
|
941 |
$arr[] = $row; |
|
942 |
} |
|
943 |
|
|
944 |
return $arr; |
|
945 |
} |
|
946 |
|
|
947 |
/** |
|
948 |
* 获得指定商品的各会员等级对应的价格 |
|
949 |
* |
|
950 |
* @access public |
|
951 |
* @param integer $goods_id |
|
952 |
* @return array |
|
953 |
*/ |
|
954 |
function get_user_rank_prices ($goods_id, $shop_price) |
|
955 |
{ |
|
956 |
$sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price / 100) AS price, r.rank_name, r.discount " . 'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " . "WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'"; |
|
957 |
$res = $GLOBALS['db']->query($sql); |
|
958 |
|
|
959 |
$arr = array(); |
|
960 |
while($row = $GLOBALS['db']->fetchRow($res)) |
|
961 |
{ |
|
962 |
|
|
963 |
$arr[$row['rank_id']] = array( |
|
964 |
'rank_name' => htmlspecialchars($row['rank_name']), 'price' => price_format($row['price']) |
|
965 |
); |
|
966 |
} |
|
967 |
|
|
968 |
return $arr; |
|
969 |
} |
|
970 |
|
|
971 |
/** |
|
972 |
* 获得购买过该商品的人还买过的商品 |
|
973 |
* |
|
974 |
* @access public |
|
975 |
* @param integer $goods_id |
|
976 |
* @return array |
|
977 |
*/ |
|
978 |
function get_also_bought ($goods_id) |
|
979 |
{ |
|
980 |
$sql = 'SELECT COUNT(b.goods_id ) AS num, g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price, g.promote_price, g.promote_start_date, g.promote_end_date ' . 'FROM ' . $GLOBALS['ecs']->table('order_goods') . ' AS a ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('order_goods') . ' AS b ON b.order_id = a.order_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = b.goods_id ' . "WHERE a.goods_id = '$goods_id' AND b.goods_id <> '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . 'GROUP BY b.goods_id ' . 'ORDER BY num DESC ' . 'LIMIT ' . $GLOBALS['_CFG']['bought_goods']; |
|
981 |
$res = $GLOBALS['db']->query($sql); |
|
982 |
|
|
983 |
$key = 0; |
|
984 |
$arr = array(); |
|
985 |
while($row = $GLOBALS['db']->fetchRow($res)) |
|
986 |
{ |
|
987 |
$arr[$key]['goods_id'] = $row['goods_id']; |
|
988 |
$arr[$key]['goods_name'] = $row['goods_name']; |
|
989 |
$arr[$key]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; |
|
990 |
$arr[$key]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
991 |
$arr[$key]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
992 |
$arr[$key]['shop_price'] = price_format($row['shop_price']); |
|
993 |
$arr[$key]['url'] = build_uri('goods', array( |
|
994 |
'gid' => $row['goods_id'] |
|
995 |
), $row['goods_name']); |
|
996 |
|
|
997 |
if($row['promote_price'] > 0) |
|
998 |
{ |
|
999 |
$arr[$key]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); |
|
1000 |
$arr[$key]['formated_promote_price'] = price_format($arr[$key]['promote_price']); |
|
1001 |
} |
|
1002 |
else |
|
1003 |
{ |
|
1004 |
$arr[$key]['promote_price'] = 0; |
|
1005 |
} |
|
1006 |
|
|
1007 |
$key ++; |
|
1008 |
} |
|
1009 |
|
|
1010 |
return $arr; |
|
1011 |
} |
|
1012 |
|
|
1013 |
/** |
|
1014 |
* 获得指定商品的销售排名 |
|
1015 |
* |
|
1016 |
* @access public |
|
1017 |
* @param integer $goods_id |
|
1018 |
* @return integer |
|
1019 |
*/ |
|
1020 |
function get_goods_rank ($goods_id) |
|
1021 |
{ |
|
1022 |
/* 统计时间段 */ |
|
1023 |
$period = intval($GLOBALS['_CFG']['top10_time']); |
|
1024 |
if($period == 1) // 一年 |
|
1025 |
{ |
|
1026 |
$ext = " AND o.add_time > '" . local_strtotime('-1 years') . "'"; |
|
1027 |
} |
|
1028 |
elseif($period == 2) // 半年 |
|
1029 |
{ |
|
1030 |
$ext = " AND o.add_time > '" . local_strtotime('-6 months') . "'"; |
|
1031 |
} |
|
1032 |
elseif($period == 3) // 三个月 |
|
1033 |
{ |
|
1034 |
$ext = " AND o.add_time > '" . local_strtotime('-3 months') . "'"; |
|
1035 |
} |
|
1036 |
elseif($period == 4) // 一个月 |
|
1037 |
{ |
|
1038 |
$ext = " AND o.add_time > '" . local_strtotime('-1 months') . "'"; |
|
1039 |
} |
|
1040 |
else |
|
1041 |
{ |
|
1042 |
$ext = ''; |
|
1043 |
} |
|
1044 |
|
|
1045 |
/* 查询该商品销量 */ |
|
1046 |
$sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS g ' . "WHERE o.order_id = g.order_id " . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND o.shipping_status " . db_create_in(array( |
|
1047 |
SS_SHIPPED, SS_RECEIVED |
|
1048 |
)) . " AND o.pay_status " . db_create_in(array( |
|
1049 |
PS_PAYED, PS_PAYING |
|
1050 |
)) . " AND g.goods_id = '$goods_id'" . $ext; |
|
1051 |
$sales_count = $GLOBALS['db']->getOne($sql); |
|
1052 |
|
|
1053 |
if($sales_count > 0) |
|
1054 |
{ |
|
1055 |
/* 只有在商品销售量大于0时才去计算该商品的排行 */ |
|
1056 |
$sql = 'SELECT DISTINCT SUM(goods_number) AS num ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS g ' . "WHERE o.order_id = g.order_id " . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND o.shipping_status " . db_create_in(array( |
|
1057 |
SS_SHIPPED, SS_RECEIVED |
|
1058 |
)) . " AND o.pay_status " . db_create_in(array( |
|
1059 |
PS_PAYED, PS_PAYING |
|
1060 |
)) . $ext . " GROUP BY g.goods_id HAVING num > $sales_count"; |
|
1061 |
$res = $GLOBALS['db']->query($sql); |
|
1062 |
|
|
1063 |
$rank = $GLOBALS['db']->num_rows($res) + 1; |
|
1064 |
|
|
1065 |
if($rank > 10) |
|
1066 |
{ |
|
1067 |
$rank = 0; |
|
1068 |
} |
|
1069 |
} |
|
1070 |
else |
|
1071 |
{ |
|
1072 |
$rank = 0; |
|
1073 |
} |
|
1074 |
|
|
1075 |
return $rank; |
|
1076 |
} |
|
1077 |
|
|
1078 |
/** |
|
1079 |
* 获得商品选定的属性的附加总价格 |
|
1080 |
* |
|
1081 |
* @param integer $goods_id |
|
1082 |
* @param array $attr |
|
1083 |
* |
|
1084 |
* @return void |
|
1085 |
*/ |
|
1086 |
function get_attr_amount ($goods_id, $attr) |
|
1087 |
{ |
|
1088 |
$sql = "SELECT SUM(attr_price) FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id='$goods_id' AND " . db_create_in($attr, 'goods_attr_id'); |
|
1089 |
|
|
1090 |
return $GLOBALS['db']->getOne($sql); |
|
1091 |
} |
|
1092 |
|
|
1093 |
/** |
|
1094 |
* 取得跟商品关联的礼包列表 |
|
1095 |
* |
|
1096 |
* @param string $goods_id |
|
1097 |
* 商品编号 |
|
1098 |
* |
|
1099 |
* @return 礼包列表 |
|
1100 |
*/ |
|
1101 |
function get_package_goods_list ($goods_id) |
|
1102 |
{ |
|
1103 |
$now = gmtime(); |
|
1104 |
$sql = "SELECT pg.goods_id, ga.act_id, ga.act_name, ga.act_desc, ga.goods_name, ga.start_time, |
|
1105 |
ga.end_time, ga.is_finished, ga.ext_info |
|
1106 |
FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga, " . $GLOBALS['ecs']->table('package_goods') . " AS pg |
|
1107 |
WHERE pg.package_id = ga.act_id |
|
1108 |
AND ga.start_time <= '" . $now . "' |
|
1109 |
AND ga.end_time >= '" . $now . "' |
|
1110 |
AND pg.goods_id = " . $goods_id . " |
|
1111 |
GROUP BY ga.act_id |
|
1112 |
ORDER BY ga.act_id "; |
|
1113 |
$res = $GLOBALS['db']->getAll($sql); |
|
1114 |
|
|
1115 |
foreach($res as $tempkey => $value) |
|
1116 |
{ |
|
1117 |
$subtotal = 0; |
|
1118 |
$row = unserialize($value['ext_info']); |
|
1119 |
unset($value['ext_info']); |
|
1120 |
if($row) |
|
1121 |
{ |
|
1122 |
foreach($row as $key => $val) |
|
1123 |
{ |
|
1124 |
$res[$tempkey][$key] = $val; |
|
1125 |
} |
|
1126 |
} |
|
1127 |
|
|
1128 |
$sql = "SELECT pg.package_id, pg.goods_id, pg.goods_number, pg.admin_id, p.goods_attr, g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price |
|
1129 |
FROM " . $GLOBALS['ecs']->table('package_goods') . " AS pg |
|
1130 |
LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g |
|
1131 |
ON g.goods_id = pg.goods_id |
|
1132 |
LEFT JOIN " . $GLOBALS['ecs']->table('products') . " AS p |
|
1133 |
ON p.product_id = pg.product_id |
|
1134 |
LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp |
|
1135 |
ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' |
|
1136 |
WHERE pg.package_id = " . $value['act_id'] . " |
|
1137 |
ORDER BY pg.package_id, pg.goods_id"; |
|
1138 |
|
|
1139 |
$goods_res = $GLOBALS['db']->getAll($sql); |
|
1140 |
|
|
1141 |
foreach($goods_res as $key => $val) |
|
1142 |
{ |
|
1143 |
$goods_id_array[] = $val['goods_id']; |
|
1144 |
$goods_res[$key]['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true); |
|
1145 |
$goods_res[$key]['market_price'] = price_format($val['market_price']); |
|
1146 |
$goods_res[$key]['rank_price'] = price_format($val['rank_price']); |
|
1147 |
$subtotal += $val['rank_price'] * $val['goods_number']; |
|
1148 |
} |
|
1149 |
|
|
1150 |
/* 取商品属性 */ |
|
1151 |
$sql = "SELECT ga.goods_attr_id, ga.attr_value |
|
1152 |
FROM " . $GLOBALS['ecs']->table('goods_attr') . " AS ga, " . $GLOBALS['ecs']->table('attribute') . " AS a |
|
1153 |
WHERE a.attr_id = ga.attr_id |
|
1154 |
AND a.attr_type = 1 |
|
1155 |
AND " . db_create_in($goods_id_array, 'goods_id'); |
|
1156 |
$result_goods_attr = $GLOBALS['db']->getAll($sql); |
|
1157 |
|
|
1158 |
$_goods_attr = array(); |
|
1159 |
foreach($result_goods_attr as $value) |
|
1160 |
{ |
|
1161 |
$_goods_attr[$value['goods_attr_id']] = $value['attr_value']; |
|
1162 |
} |
|
1163 |
|
|
1164 |
/* 处理货品 */ |
|
1165 |
$format = '[%s]'; |
|
1166 |
foreach($goods_res as $key => $val) |
|
1167 |
{ |
|
1168 |
if($val['goods_attr'] != '') |
|
1169 |
{ |
|
1170 |
$goods_attr_array = explode('|', $val['goods_attr']); |
|
1171 |
|
|
1172 |
$goods_attr = array(); |
|
1173 |
foreach($goods_attr_array as $_attr) |
|
1174 |
{ |
|
1175 |
$goods_attr[] = $_goods_attr[$_attr]; |
|
1176 |
} |
|
1177 |
|
|
1178 |
$goods_res[$key]['goods_attr_str'] = sprintf($format, implode(',', $goods_attr)); |
|
1179 |
} |
|
1180 |
} |
|
1181 |
|
|
1182 |
$res[$tempkey]['goods_list'] = $goods_res; |
|
1183 |
$res[$tempkey]['subtotal'] = price_format($subtotal); |
|
1184 |
$res[$tempkey]['saving'] = price_format(($subtotal - $res[$tempkey]['package_price'])); |
|
1185 |
$res[$tempkey]['package_price'] = price_format($res[$tempkey]['package_price']); |
|
1186 |
} |
|
1187 |
|
|
1188 |
return $res; |
|
1189 |
} |
|
1190 |
|
|
1191 |
function get_package_goods_list_1 ($goods_id) |
|
1192 |
{ |
|
1193 |
$now = gmtime(); |
|
1194 |
$sql = "SELECT ga.act_id,ga.ext_info |
|
1195 |
FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga, " . $GLOBALS['ecs']->table('package_goods') . " AS pg |
|
1196 |
WHERE pg.package_id = ga.act_id |
|
1197 |
AND ga.start_time <= '" . $now . "' |
|
1198 |
AND ga.end_time >= '" . $now . "' |
|
1199 |
AND pg.goods_id = " . $goods_id . " |
|
1200 |
GROUP BY pg.package_id |
|
1201 |
ORDER BY ga.act_id"; |
|
1202 |
|
|
1203 |
$res = $GLOBALS['db']->getAll($sql); |
|
1204 |
|
|
1205 |
foreach($res as $tempkey => $value) |
|
1206 |
{ |
|
1207 |
$subtotal = 0; |
|
1208 |
$i = 1; |
|
1209 |
|
|
1210 |
// 获取礼包价 |
|
1211 |
$row = unserialize($value['ext_info']); |
|
1212 |
unset($value['ext_info']); |
|
1213 |
if($row) |
|
1214 |
{ |
|
1215 |
foreach($row as $key => $val) |
|
1216 |
{ |
|
1217 |
$res[$tempkey][$key] = $val; |
|
1218 |
} |
|
1219 |
} |
|
1220 |
|
|
1221 |
$sql = "SELECT pg.package_id, pg.goods_id, pg.product_id, pg.goods_number, pg.admin_id, p.goods_attr, g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price |
|
1222 |
FROM " . $GLOBALS['ecs']->table('package_goods') . " AS pg |
|
1223 |
LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g |
|
1224 |
ON g.goods_id = pg.goods_id |
|
1225 |
LEFT JOIN " . $GLOBALS['ecs']->table('products') . " AS p |
|
1226 |
ON p.product_id = pg.product_id |
|
1227 |
LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp |
|
1228 |
ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' |
|
1229 |
WHERE pg.package_id = " . $value['act_id'] . " |
|
1230 |
ORDER BY pg.package_id, pg.goods_id"; |
|
1231 |
|
|
1232 |
$goods_ress = $GLOBALS['db']->query($sql); |
|
1233 |
$goods_res = array(); |
|
1234 |
while($row = $GLOBALS['db']->fetchRow($goods_ress)) |
|
1235 |
{ |
|
1236 |
if($row['goods_id'] == $goods_id) |
|
1237 |
{ |
|
1238 |
$goods_res[0] = $row; |
|
1239 |
} |
|
1240 |
else |
|
1241 |
{ |
|
1242 |
$goods_res[$i] = $row; |
|
1243 |
$i ++; |
|
1244 |
} |
|
1245 |
} |
|
1246 |
|
|
1247 |
foreach($goods_res as $key => $val) |
|
1248 |
{ |
|
1249 |
$goods_id_array[] = $val['goods_id']; |
|
1250 |
$goods_res[$key]['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true); |
|
1251 |
$goods_res[$key]['market_price'] = price_format($val['market_price']); |
|
1252 |
$goods_res[$key]['rank_price'] = $val['rank_price']; |
|
1253 |
$subtotal += $val['rank_price'] * $val['goods_number']; |
|
1254 |
} |
|
1255 |
|
|
1256 |
/* 取商品属性 */ |
|
1257 |
$sql = "SELECT ga.goods_attr_id, ga.attr_value |
|
1258 |
FROM " . $GLOBALS['ecs']->table('goods_attr') . " AS ga, " . $GLOBALS['ecs']->table('attribute') . " AS a |
|
1259 |
WHERE a.attr_id = ga.attr_id |
|
1260 |
AND a.attr_type = 1 |
|
1261 |
AND " . db_create_in($goods_id_array, 'goods_id'); |
|
1262 |
$result_goods_attr = $GLOBALS['db']->getAll($sql); |
|
1263 |
|
|
1264 |
$_goods_attr = array(); |
|
1265 |
foreach($result_goods_attr as $value) |
|
1266 |
{ |
|
1267 |
$_goods_attr[$value['goods_attr_id']] = $value['attr_value']; |
|
1268 |
} |
|
1269 |
|
|
1270 |
/* 处理货品 */ |
|
1271 |
$format = '[%s]'; |
|
1272 |
foreach($goods_res as $key => $val) |
|
1273 |
{ |
|
1274 |
if($val['goods_attr'] != '') |
|
1275 |
{ |
|
1276 |
$goods_attr_array = explode('|', $val['goods_attr']); |
|
1277 |
|
|
1278 |
$goods_attr = array(); |
|
1279 |
foreach($goods_attr_array as $_attr) |
|
1280 |
{ |
|
1281 |
$goods_attr[] = $_goods_attr[$_attr]; |
|
1282 |
} |
|
1283 |
|
|
1284 |
$goods_res[$key]['goods_attr_str'] = sprintf($format, implode(',', $goods_attr)); |
|
1285 |
} |
|
1286 |
} |
|
1287 |
|
|
1288 |
ksort($goods_res); // 重新排序数组 |
|
1289 |
|
|
1290 |
/* 重新计算套餐内的商品折扣价 */ |
|
1291 |
$zhekou = round(($res[$tempkey]['package_price'] / $subtotal), 8); |
|
1292 |
foreach($goods_res as $key => $val) |
|
1293 |
{ |
|
1294 |
$goods_res[$key]['rank_price_zk'] = $val['rank_price'] * $zhekou; |
|
1295 |
$goods_res[$key]['rank_price_zk_format'] = price_format($goods_res[$key]['rank_price_zk']); |
|
1296 |
} |
|
1297 |
|
|
1298 |
$res[$tempkey]['goods_list'] = $goods_res; |
|
1299 |
$res[$tempkey]['subtotal'] = price_format($subtotal); |
|
1300 |
$res[$tempkey]['zhekou'] = $zhekou * 100; |
|
1301 |
$res[$tempkey]['saving'] = price_format(($subtotal - $res[$tempkey]['package_price'])); |
|
1302 |
$res[$tempkey]['package_price'] = price_format($res[$tempkey]['package_price']); |
|
1303 |
} |
|
1304 |
|
|
1305 |
return $res; |
|
1306 |
} |
|
1307 |
|
|
1308 |
/** |
|
1309 |
* 获得指定商品的相册 |
|
1310 |
* |
|
1311 |
* @access public |
|
1312 |
* @param integer $goods_id |
|
1313 |
* @return array |
|
1314 |
*/ |
|
1315 |
function get_goods_gallery_attr_2 ($goods_id, $goods_attr_id) |
|
1316 |
{ |
|
1317 |
$sql = 'SELECT img_id, img_original, img_url, thumb_url, img_desc' . ' FROM ' . $GLOBALS['ecs']->table('goods_gallery') . " WHERE goods_id = '$goods_id' and goods_attr_id='$goods_attr_id' LIMIT " . $GLOBALS['_CFG']['goods_gallery_number']; |
|
1318 |
$row = $GLOBALS['db']->getAll($sql); |
|
1319 |
if(count($row) == 0) |
|
1320 |
{ |
|
1321 |
$sql = 'SELECT img_id, img_original, img_url, thumb_url, img_desc' . ' FROM ' . $GLOBALS['ecs']->table('goods_gallery') . " WHERE goods_id = '$goods_id' and goods_attr_id='0' LIMIT " . $GLOBALS['_CFG']['goods_gallery_number']; |
|
1322 |
$row = $GLOBALS['db']->getAll($sql); |
|
1323 |
} |
|
1324 |
/* 格式化相册图片路径 */ |
|
1325 |
foreach($row as $key => $gallery_img) |
|
1326 |
{ |
|
1327 |
$row[$key]['img_url'] = get_image_path($goods_id, $gallery_img['img_url'], false, 'gallery'); |
|
1328 |
$row[$key]['thumb_url'] = get_image_path($goods_id, $gallery_img['thumb_url'], true, 'gallery'); |
|
1329 |
$row[$key]['img_original'] = get_image_path($goods_id, $gallery_img['img_original'], true, 'gallery'); |
|
1330 |
} |
|
1331 |
return $row; |
|
1332 |
} |
|
1333 |
|
|
1334 |
/* |
|
1335 |
* 获取商品所对应店铺的店铺基本信息 |
|
1336 |
* @param int $suppid 店铺id |
|
1337 |
* @param int $suppinfo 入驻商的信息 |
|
1338 |
*/ |
|
1339 |
function get_dianpu_baseinfo ($suppid = 0, $suppinfo) |
|
1340 |
{ |
|
1341 |
if(intval($suppid) <= 0) |
|
1342 |
{ |
|
1343 |
return; |
|
1344 |
} |
|
1345 |
global $smarty; |
|
1346 |
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('supplier_shop_config') . " WHERE supplier_id = " . $suppid; |
|
1347 |
$shopinfo = $GLOBALS['db']->getAll($sql); |
|
1348 |
|
|
1349 |
$_goods_attr = array(); |
|
1350 |
foreach($shopinfo as $value) |
|
1351 |
{ |
|
1352 |
$_goods_attr[$value['code']] = $value['value']; |
|
1353 |
} |
|
1354 |
// 代码增加 |
|
1355 |
$sql1 = "SELECT AVG(comment_rank) FROM " . $GLOBALS['ecs']->table('comment') . " c" . " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " o" . " ON o.order_id = c.order_id" . " WHERE c.status > 0 AND o.supplier_id = " . $suppid; |
|
1356 |
$avg_comment = $GLOBALS['db']->getOne($sql1); |
|
1357 |
$avg_comment = round($avg_comment, 1); |
|
1358 |
|
|
1359 |
$sql2 = "SELECT AVG(server), AVG(shipping) FROM " . $GLOBALS['ecs']->table('shop_grade') . " s" . " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " o" . " ON o.order_id = s.order_id" . " WHERE s.is_comment > 0 AND s.server >0 AND o.supplier_id = " . $suppid; |
|
1360 |
$row = $GLOBALS['db']->getRow($sql2); |
|
1361 |
|
|
1362 |
$avg_server = round($row['AVG(server)'], 1); |
|
1363 |
$avg_shipping = round($row['AVG(shipping)'], 1); |
|
1364 |
$haoping = round((($avg_comment + $avg_server + $avg_shipping) / 3) / 5, 2) * 100; |
|
1365 |
// 代码增加 |
|
1366 |
|
|
1367 |
$smarty->assign('ghs_css_path', 'themes/' . $_goods_attr['template'] . '/images/ghs/css/ghs_style.css'); // 入驻商所选模板样式路径 |
|
1368 |
$shoplogo = empty($_goods_attr['shop_logo']) ? 'themes/' . $_goods_attr['template'] . '/images/dianpu.jpg' : $_goods_attr['shop_logo']; |
|
1369 |
$smarty->assign('shoplogo', $shoplogo); // 商家logo |
|
1370 |
$smarty->assign('shopname', htmlspecialchars($_goods_attr['shop_name'])); // 店铺名称 |
|
1371 |
$smarty->assign('suppid', $suppinfo['supplier_id']); // 商家名称 |
|
1372 |
$smarty->assign('suppliername', htmlspecialchars($suppinfo['supplier_name'])); // 商家名称 |
|
1373 |
$smarty->assign('userrank', htmlspecialchars($suppinfo['rank_name'])); // 商家等级 |
|
1374 |
$smarty->assign('region', get_province_city($_goods_attr['shop_province'], $_goods_attr['shop_city'])); |
|
1375 |
$smarty->assign('address', $_goods_attr['shop_address']); |
|
1376 |
$smarty->assign('serviceqq', $_goods_attr['qq']); |
|
1377 |
$smarty->assign('serviceww', $_goods_attr['ww']); |
|
1378 |
$smarty->assign('serviceemail', $_goods_attr['service_email']); |
|
1379 |
$smarty->assign('servicephone', $_goods_attr['service_phone']); |
|
1380 |
$smarty->assign('createtime', gmdate('Y-m-d', $suppinfo['add_time'])); // 商家创建时间 |
|
1381 |
// 代码增加 |
|
1382 |
$smarty->assign('c_rank', $avg_comment); |
|
1383 |
$smarty->assign('serv_rank', $avg_server); |
|
1384 |
$smarty->assign('shipp_rank', $avg_shipping); |
|
1385 |
$smarty->assign('haoping', $haoping); |
|
1386 |
// 代码增加 |
|
1387 |
$suppid = (intval($suppid) > 0) ? intval($suppid) : intval($_GET['suppId']); |
|
1388 |
} |
|
1389 |
?> |