commit | author | age
|
19351a
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 用户交易相关函数库 |
|
5 |
*/ |
|
6 |
|
|
7 |
if (!defined('IN_ECS')) |
|
8 |
{ |
|
9 |
die('Hacking attempt'); |
|
10 |
} |
|
11 |
|
|
12 |
/** |
|
13 |
* 修改个人资料(Email, 性别,生日) |
|
14 |
* |
|
15 |
* @access public |
|
16 |
* @param array $profile array_keys(user_id int, user_name string, email string, sex int, birthday string); |
|
17 |
* |
|
18 |
* @return boolen $bool |
|
19 |
*/ |
|
20 |
function edit_profile($profile) |
|
21 |
{ |
|
22 |
if (empty($profile['user_id'])) |
|
23 |
{ |
|
24 |
$GLOBALS['err']->add($GLOBALS['_LANG']['not_login']); |
|
25 |
|
|
26 |
return false; |
|
27 |
} |
|
28 |
|
|
29 |
$cfg = array(); |
|
30 |
$cfg['user_id'] = $profile['user_id']; |
|
31 |
$cfg['username'] = $GLOBALS['db']->getOne("SELECT user_name FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id='" . $profile['user_id'] . "'"); |
|
32 |
if (isset($profile['sex'])) |
|
33 |
{ |
|
34 |
$cfg['gender'] = intval($profile['sex']); |
|
35 |
} |
|
36 |
if (isset($profile['user_name'])) |
|
37 |
{ |
|
38 |
$cfg['user_name'] = empty($profile['user_name']) ? $cfg['username'] : $profile['user_name']; |
|
39 |
} |
|
40 |
if (!empty($profile['email'])) |
|
41 |
{ |
|
42 |
if (!is_email($profile['email'])) |
|
43 |
{ |
|
44 |
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_invalid'], $profile['email'])); |
|
45 |
|
|
46 |
return false; |
|
47 |
} |
|
48 |
$cfg['email'] = $profile['email']; |
|
49 |
} |
|
50 |
if (!empty($profile['birthday'])) |
|
51 |
{ |
|
52 |
$cfg['bday'] = $profile['birthday']; |
|
53 |
} |
|
54 |
|
|
55 |
if (!$GLOBALS['user']->edit_user($cfg)) |
|
56 |
{ |
|
57 |
if ($GLOBALS['user']->error == ERR_EMAIL_EXISTS) |
|
58 |
{ |
|
59 |
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_exist'], $profile['email'])); |
|
60 |
} |
|
61 |
else |
|
62 |
{ |
|
63 |
$GLOBALS['err']->add('DB ERROR!'); |
|
64 |
} |
|
65 |
|
|
66 |
return false; |
|
67 |
} |
|
68 |
|
|
69 |
/* 过滤非法的键值 */ |
|
70 |
$other_key_array = array('user_name','msn', 'qq', 'office_phone', 'home_phone', 'mobile_phone'); |
|
71 |
foreach ($profile['other'] as $key => $val) |
|
72 |
{ |
|
73 |
//删除非法key值 |
|
74 |
if (!in_array($key, $other_key_array)) |
|
75 |
{ |
|
76 |
unset($profile['other'][$key]); |
|
77 |
} |
|
78 |
else |
|
79 |
{ |
|
80 |
$profile['other'][$key] = htmlspecialchars(trim($val)); //防止用户输入javascript代码 |
|
81 |
} |
|
82 |
} |
|
83 |
/* 修改在其他资料 */ |
|
84 |
|
|
85 |
if (!empty($profile['other'])) |
|
86 |
{ |
|
87 |
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('users'), $profile['other'], 'UPDATE', "user_id = '$profile[user_id]'"); |
|
88 |
} |
|
89 |
|
|
90 |
return true; |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* 获取用户帐号信息 |
|
95 |
* |
|
96 |
* @access public |
|
97 |
* @param int $user_id 用户user_id |
|
98 |
* |
|
99 |
* @return void |
|
100 |
*/ |
|
101 |
function get_profile($user_id) |
|
102 |
{ |
|
103 |
global $user; |
|
104 |
|
|
105 |
|
|
106 |
/* 会员帐号信息 */ |
|
107 |
$info = array(); |
|
108 |
$infos = array(); |
|
109 |
$sql = "SELECT * ". |
|
110 |
"FROM " .$GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"; |
|
111 |
$infos = $GLOBALS['db']->getRow($sql); |
|
112 |
$infos['user_name'] = addslashes($infos['user_name']); |
|
113 |
|
|
114 |
$row = $user->get_profile_by_name($infos['user_name']); //获取用户帐号信息 |
|
115 |
$_SESSION['email'] = $row['email']; //注册SESSION |
|
116 |
$_SESSION['user_name'] = $infos['user_name']; //注册SESSION |
|
117 |
|
|
118 |
/* 会员等级 */ |
|
119 |
if ($infos['user_rank'] > 0) |
|
120 |
{ |
|
121 |
$sql = "SELECT rank_id, rank_name, discount FROM ".$GLOBALS['ecs']->table('user_rank') . |
|
122 |
" WHERE rank_id = '$infos[user_rank]'"; |
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
$sql = "SELECT rank_id, rank_name, discount, min_points". |
|
127 |
" FROM ".$GLOBALS['ecs']->table('user_rank') . |
|
128 |
" WHERE min_points<= " . intval($infos['rank_points']) . " ORDER BY min_points DESC"; |
|
129 |
} |
|
130 |
|
|
131 |
if ($row = $GLOBALS['db']->getRow($sql)) |
|
132 |
{ |
|
133 |
$info['rank_name'] = $row['rank_name']; |
|
134 |
} |
|
135 |
else |
|
136 |
{ |
|
137 |
$info['rank_name'] = $GLOBALS['_LANG']['undifine_rank']; |
|
138 |
} |
|
139 |
|
|
140 |
$cur_date = date('Y-m-d H:i:s'); |
|
141 |
|
|
142 |
/* 会员红包 */ |
|
143 |
$bonus = array(); |
|
144 |
$sql = "SELECT type_name, type_money ". |
|
145 |
"FROM " .$GLOBALS['ecs']->table('bonus_type') . " AS t1, " .$GLOBALS['ecs']->table('user_bonus') . " AS t2 ". |
|
146 |
"WHERE t1.type_id = t2.bonus_type_id AND t2.user_id = '$user_id' AND t1.use_start_date <= '$cur_date' ". |
|
147 |
"AND t1.use_end_date > '$cur_date' AND t2.order_id = 0"; |
|
148 |
$bonus = $GLOBALS['db']->getAll($sql); |
|
149 |
if ($bonus) |
|
150 |
{ |
|
151 |
for ($i = 0, $count = count($bonus); $i < $count; $i++) |
|
152 |
{ |
|
153 |
$bonus[$i]['type_money'] = price_format($bonus[$i]['type_money'], false); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
$info['discount'] = $_SESSION['discount'] * 100 . "%"; |
|
158 |
$info['email'] = $_SESSION['email']; |
|
159 |
$info['headimg'] = $infos['headimg']; |
|
160 |
$info['user_name'] = $_SESSION['user_name']; |
|
161 |
$info['password'] = $infos['password']; |
|
162 |
$info['rank_points'] = isset($infos['rank_points']) ? $infos['rank_points'] : ''; |
|
163 |
$info['pay_points'] = isset($infos['pay_points']) ? $infos['pay_points'] : 0; |
|
164 |
$info['user_money'] = isset($infos['user_money']) ? $infos['user_money'] : 0; |
|
165 |
$info['sex'] = isset($infos['sex']) ? $infos['sex'] : 0; |
|
166 |
$info['birthday'] = isset($infos['birthday']) ? $infos['birthday'] : ''; |
|
167 |
$info['question'] = isset($infos['question']) ? htmlspecialchars($infos['question']) : ''; |
|
168 |
|
|
169 |
$info['user_money'] = price_format($info['user_money'], false); |
|
170 |
$info['pay_points'] = $info['pay_points'] . $GLOBALS['_CFG']['integral_name']; |
|
171 |
$info['bonus'] = $bonus; |
|
172 |
$info['qq'] = $infos['qq']; |
|
173 |
$info['msn'] = $infos['msn']; |
|
174 |
$info['office_phone']= $infos['office_phone']; |
|
175 |
$info['home_phone'] = $infos['home_phone']; |
|
176 |
$info['mobile_phone'] = $infos['mobile_phone']; |
|
177 |
$info['passwd_question'] = $infos['passwd_question']; |
|
178 |
$info['passwd_answer'] = $infos['passwd_answer']; |
|
179 |
$info['real_name'] = $infos['real_name']; |
|
180 |
$info['card'] = $infos['card']; |
|
181 |
$info['face_card'] = $infos['face_card']; |
|
182 |
$info['back_card'] = $infos['back_card']; |
|
183 |
$info['country'] = $infos['country']; |
|
184 |
$info['province'] = $infos['province']; |
|
185 |
$info['city'] = $infos['city']; |
|
186 |
$info['district'] = $infos['district']; |
|
187 |
$info['address'] = $infos['address']; |
|
188 |
$info['validated'] = $infos['validated']; |
|
189 |
$info['is_validated'] = $infos['is_validated']; |
|
190 |
$info['status'] = $infos['status']; |
|
191 |
$info['headimg'] = $infos['headimg']; |
|
192 |
$info['is_surplus_open'] = isset($infos['is_surplus_open']) ? $infos['is_surplus_open'] : '0'; |
|
193 |
$info['surplus_password'] = isset($infos['surplus_password']) ? $infos['surplus_password'] : ''; |
|
194 |
|
|
195 |
return $info; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* 取得收货人地址列表 |
|
200 |
* @param int $user_id 用户编号 |
|
201 |
* @return array |
|
202 |
*/ |
|
203 |
function get_consignee_list($user_id) |
|
204 |
{ |
|
205 |
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('user_address') . |
|
206 |
// 代码修改 By Start |
|
207 |
// " WHERE user_id = '$user_id' LIMIT 5"; |
|
208 |
" WHERE user_id = '$user_id'"; |
|
209 |
// 代码修改 By End |
|
210 |
|
|
211 |
return $GLOBALS['db']->getAll($sql); |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* 给指定用户添加一个指定红包 |
|
216 |
* |
|
217 |
* @access public |
|
218 |
* @param int $user_id 用户ID |
|
219 |
* @param string $bouns_sn 红包序列号 |
|
220 |
* |
|
221 |
* @return boolen $result |
|
222 |
*/ |
|
223 |
function add_bonus($user_id, $bouns_sn) |
|
224 |
{ |
|
225 |
if (empty($user_id)) |
|
226 |
{ |
|
227 |
$GLOBALS['err']->add($GLOBALS['_LANG']['not_login']); |
|
228 |
|
|
229 |
return false; |
|
230 |
} |
|
231 |
|
|
232 |
/* 查询红包序列号是否已经存在 */ |
|
233 |
$sql = "SELECT bonus_id, bonus_sn, user_id, bonus_type_id FROM " .$GLOBALS['ecs']->table('user_bonus') . |
|
234 |
" WHERE bonus_sn = '$bouns_sn'"; |
|
235 |
$row = $GLOBALS['db']->getRow($sql); |
|
236 |
if ($row) |
|
237 |
{ |
|
238 |
if ($row['user_id'] == 0) |
|
239 |
{ |
|
240 |
//红包没有被使用 |
|
241 |
$sql = "SELECT send_end_date, use_end_date ". |
|
242 |
" FROM " . $GLOBALS['ecs']->table('bonus_type') . |
|
243 |
" WHERE type_id = '" . $row['bonus_type_id'] . "'"; |
|
244 |
|
|
245 |
$bonus_time = $GLOBALS['db']->getRow($sql); |
|
246 |
|
|
247 |
$now = gmtime(); |
|
248 |
if ($now > $bonus_time['use_end_date']) |
|
249 |
{ |
|
250 |
$GLOBALS['err']->add($GLOBALS['_LANG']['bonus_use_expire']); |
|
251 |
return false; |
|
252 |
} |
|
253 |
|
|
254 |
if ($now > $bonus_time['send_end_date']) |
|
255 |
{ |
|
256 |
$GLOBALS['err']->add('该红包已经过期,不能添加。'); |
|
257 |
return false; |
|
258 |
} |
|
259 |
|
|
260 |
$sql = "UPDATE " .$GLOBALS['ecs']->table('user_bonus') . " SET user_id = '$user_id' ". |
|
261 |
"WHERE bonus_id = '$row[bonus_id]'"; |
|
262 |
$result = $GLOBALS['db'] ->query($sql); |
|
263 |
if ($result) |
|
264 |
{ |
|
265 |
return true; |
|
266 |
} |
|
267 |
else |
|
268 |
{ |
|
269 |
return $GLOBALS['db']->errorMsg(); |
|
270 |
} |
|
271 |
} |
|
272 |
else |
|
273 |
{ |
|
274 |
if ($row['user_id']== $user_id) |
|
275 |
{ |
|
276 |
//红包已经添加过了。 |
|
277 |
$GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used']); |
|
278 |
} |
|
279 |
else |
|
280 |
{ |
|
281 |
//红包被其他人使用过了。 |
|
282 |
$GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used_by_other']); |
|
283 |
} |
|
284 |
|
|
285 |
return false; |
|
286 |
} |
|
287 |
} |
|
288 |
else |
|
289 |
{ |
|
290 |
//红包不存在 |
|
291 |
$GLOBALS['err']->add($GLOBALS['_LANG']['bonus_not_exist']); |
|
292 |
return false; |
|
293 |
} |
|
294 |
|
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* 获取用户指定范围的订单列表 |
|
299 |
* |
|
300 |
* @access public |
|
301 |
* @param int $user_id 用户ID号 |
|
302 |
* @param int $num 列表最大数量 |
|
303 |
* @param int $start 列表起始位置 |
|
304 |
* @return array $order_list 订单列表 |
|
305 |
*/ |
|
306 |
function get_user_orders($user_id, $num = 10, $start = 0) |
|
307 |
{ |
|
308 |
/* 取得订单列表 */ |
|
309 |
$arr = array(); |
|
310 |
|
|
311 |
$sql = "SELECT order_id, order_sn, order_status, shipping_status, pay_status, add_time, shipping_time," . |
|
312 |
" supplier_id, rebate_id, parent_order_id, ". //代码增加 By |
|
313 |
"(goods_amount + shipping_fee + insure_fee + pay_fee + pack_fee + card_fee + tax - discount) AS total_fee ". |
|
314 |
" FROM " .$GLOBALS['ecs']->table('order_info') . |
|
315 |
" WHERE user_id = '$user_id' ORDER BY add_time DESC"; |
|
316 |
$res = $GLOBALS['db']->SelectLimit($sql, $num, $start); |
|
317 |
|
|
318 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
319 |
{ |
|
320 |
if ($row['order_status'] == OS_UNCONFIRMED) |
|
321 |
{ |
|
322 |
$row['handler'] = "<a href=\"user.php?act=cancel_order&order_id=" .$row['order_id']. "\" onclick=\"if (!confirm('".$GLOBALS['_LANG']['confirm_cancel']."')) return false;\">".$GLOBALS['_LANG']['cancel']."</a>"; |
|
323 |
} |
|
324 |
else if ($row['order_status'] == OS_SPLITED) |
|
325 |
{ |
|
326 |
/* 对配送状态的处理 */ |
|
327 |
if ($row['shipping_status'] == SS_SHIPPED) |
|
328 |
{ |
|
329 |
@$row['handler'] = "<a href=\"user.php?act=affirm_received&order_id=" .$row['order_id']. "\" onclick=\"if (!confirm('".$GLOBALS['_LANG']['confirm_received']."')) return false;\">".$GLOBALS['_LANG']['received']."</a>"; |
|
330 |
} |
|
331 |
elseif ($row['shipping_status'] == SS_RECEIVED) |
|
332 |
{ |
|
333 |
@$row['handler'] = '<span style="color:red">'.$GLOBALS['_LANG']['ss_received'] .'</span>'; |
|
334 |
} |
|
335 |
else |
|
336 |
{ |
|
337 |
if ($row['pay_status'] == PS_UNPAYED) |
|
338 |
{ |
|
339 |
@$row['handler'] = "<a href=\"user.php?act=order_detail&order_id=" .$row['order_id']. '">' .$GLOBALS['_LANG']['pay_money']. '</a>'; |
|
340 |
} |
|
341 |
else |
|
342 |
{ |
|
343 |
@$row['handler'] = "<a href=\"user.php?act=order_detail&order_id=" .$row['order_id']. '">' .$GLOBALS['_LANG']['view_order']. '</a>'; |
|
344 |
} |
|
345 |
|
|
346 |
} |
|
347 |
} |
|
348 |
else |
|
349 |
{ |
|
350 |
$row['handler'] = '<span style="color:red">'.$GLOBALS['_LANG']['os'][$row['order_status']] .'</span>'; |
|
351 |
} |
|
352 |
/* 代码增加_start By */ |
|
353 |
if ($row['shipping_status']==SS_SHIPPED || $row['shipping_status']==SS_RECEIVED || $row['shipping_status']==SS_SHIPPED_PART) |
|
354 |
{ |
|
355 |
$now_time = gmtime(); |
|
356 |
|
|
357 |
if ($GLOBALS['_CFG']['tuihuan_days_fahuo'] > 0) //退换货期限(发货后第几天起): |
|
358 |
{ |
|
359 |
if (($now_time - $row['shipping_time'])/86400 < $GLOBALS['_CFG']['tuihuan_days_fahuo']) |
|
360 |
{ |
|
361 |
$no = 1; |
|
362 |
} |
|
363 |
|
|
364 |
} |
|
365 |
if ($GLOBALS['_CFG']['tuihuan_days_qianshou'] > 0) //退换货期限(发货后第几天止): |
|
366 |
{ |
|
367 |
if (($now_time - $row['shipping_time'])/86400 > $GLOBALS['_CFG']['tuihuan_days_qianshou']) |
|
368 |
{ |
|
369 |
$no = 1; |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
if ($no != 1) |
|
374 |
{ |
|
375 |
$row['handler'] .= '<br /><a href="user.php?act=order_detail&order_id='. $row['order_id'] .'" >申请返修/退款/退货</a>'; |
|
376 |
} |
|
377 |
} |
|
378 |
/* 代码增加_end By */ |
|
379 |
$row['shipping_status'] = ($row['shipping_status'] == SS_SHIPPED_ING) ? SS_PREPARING : $row['shipping_status']; |
|
380 |
$row['order_status'] = $GLOBALS['_LANG']['os'][$row['order_status']] . ',' . $GLOBALS['_LANG']['ps'][$row['pay_status']] . ',' . $GLOBALS['_LANG']['ss'][$row['shipping_status']]; |
|
381 |
|
|
382 |
$arr[] = array('order_id' => $row['order_id'], |
|
383 |
'order_sn' => $row['order_sn'], |
|
384 |
'order_time' => local_date($GLOBALS['_CFG']['time_format'], $row['add_time']), |
|
385 |
'order_status' => $row['order_status'], |
|
386 |
'total_fee' => price_format($row['total_fee'], false), |
|
387 |
'is_suborder' => $row['parent_order_id'] ? "(子订单)" : "", //代码增加 By |
|
388 |
'handler' => $row['handler']); |
|
389 |
|
|
390 |
} |
|
391 |
|
|
392 |
return $arr; |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* 取消一个用户订单 |
|
397 |
* |
|
398 |
* @access public |
|
399 |
* @param int $order_id 订单ID |
|
400 |
* @param int $user_id 用户ID |
|
401 |
* |
|
402 |
* @return void |
|
403 |
*/ |
|
404 |
function cancel_order($order_id, $user_id = 0) |
|
405 |
{ |
|
406 |
/* 查询订单信息,检查状态 */ |
|
407 |
$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'"; |
|
408 |
$order = $GLOBALS['db']->GetRow($sql); |
|
409 |
|
|
410 |
if (empty($order)) |
|
411 |
{ |
|
412 |
$GLOBALS['err']->add($GLOBALS['_LANG']['order_exist']); |
|
413 |
return false; |
|
414 |
} |
|
415 |
|
|
416 |
// 如果用户ID大于0,检查订单是否属于该用户 |
|
417 |
if ($user_id > 0 && $order['user_id'] != $user_id) |
|
418 |
{ |
|
419 |
$GLOBALS['err'] ->add($GLOBALS['_LANG']['no_priv']); |
|
420 |
|
|
421 |
return false; |
|
422 |
} |
|
423 |
|
|
424 |
// 订单状态只能是“未确认”或“已确认” |
|
425 |
if ($order['order_status'] != OS_UNCONFIRMED && $order['order_status'] != OS_CONFIRMED) |
|
426 |
{ |
|
427 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_os_not_unconfirmed']); |
|
428 |
|
|
429 |
return false; |
|
430 |
} |
|
431 |
|
|
432 |
//订单一旦确认,不允许用户取消 |
|
433 |
if ( $order['order_status'] == OS_CONFIRMED) |
|
434 |
{ |
|
435 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_os_already_confirmed']); |
|
436 |
|
|
437 |
return false; |
|
438 |
} |
|
439 |
|
|
440 |
// 发货状态只能是“未发货” |
|
441 |
if ($order['shipping_status'] != SS_UNSHIPPED) |
|
442 |
{ |
|
443 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_ss_not_cancel']); |
|
444 |
|
|
445 |
return false; |
|
446 |
} |
|
447 |
|
|
448 |
// 如果付款状态是“已付款”、“付款中”,不允许取消,要取消和商家联系 |
|
449 |
if ($order['pay_status'] != PS_UNPAYED) |
|
450 |
{ |
|
451 |
$GLOBALS['err']->add($GLOBALS['_LANG']['current_ps_not_cancel']); |
|
452 |
|
|
453 |
return false; |
|
454 |
} |
|
455 |
|
|
456 |
//将用户订单设置为取消 |
|
457 |
$sql = "UPDATE ".$GLOBALS['ecs']->table('order_info') ." SET order_status = '".OS_CANCELED."' WHERE order_id = '$order_id'"; |
|
458 |
if ($GLOBALS['db']->query($sql)) |
|
459 |
{ |
|
460 |
/* 记录log */ |
|
461 |
order_action($order['order_sn'], OS_CANCELED, $order['shipping_status'], PS_UNPAYED,$GLOBALS['_LANG']['buyer_cancel'],'buyer'); |
|
462 |
/* 退货用户余额、积分、红包 */ |
|
463 |
if ($order['user_id'] > 0 && $order['surplus'] > 0) |
|
464 |
{ |
|
465 |
$change_desc = sprintf($GLOBALS['_LANG']['return_surplus_on_cancel'], $order['order_sn']); |
|
466 |
log_account_change($order['user_id'], $order['surplus'], 0, 0, 0, $change_desc); |
|
467 |
} |
|
468 |
if ($order['user_id'] > 0 && $order['integral'] > 0) |
|
469 |
{ |
|
470 |
$change_desc = sprintf($GLOBALS['_LANG']['return_integral_on_cancel'], $order['order_sn']); |
|
471 |
log_account_change($order['user_id'], 0, 0, 0, $order['integral'], $change_desc); |
|
472 |
} |
|
473 |
if ($order['user_id'] > 0 && $order['bonus_id'] > 0) |
|
474 |
{ |
|
475 |
change_user_bonus($order['bonus_id'], $order['order_id'], false); |
|
476 |
} |
|
477 |
|
|
478 |
/* 如果使用库存,且下订单时减库存,则增加库存 */ |
|
479 |
if ($GLOBALS['_CFG']['use_storage'] == '1' && $GLOBALS['_CFG']['stock_dec_time'] == SDT_PLACE) |
|
480 |
{ |
|
481 |
change_order_goods_storage($order['order_id'], false, 1); |
|
482 |
} |
|
483 |
|
|
484 |
/* 修改订单 */ |
|
485 |
$arr = array( |
|
486 |
'bonus_id' => 0, |
|
487 |
'bonus' => 0, |
|
488 |
'integral' => 0, |
|
489 |
'integral_money' => 0, |
|
490 |
'surplus' => 0 |
|
491 |
); |
|
492 |
update_order($order['order_id'], $arr); |
|
493 |
|
|
494 |
return true; |
|
495 |
} |
|
496 |
else |
|
497 |
{ |
|
498 |
die($GLOBALS['db']->errorMsg()); |
|
499 |
} |
|
500 |
|
|
501 |
} |
|
502 |
|
|
503 |
/** |
|
504 |
* 确认一个用户订单 |
|
505 |
* |
|
506 |
* @access public |
|
507 |
* @param int $order_id 订单ID |
|
508 |
* @param int $user_id 用户ID |
|
509 |
* |
|
510 |
* @return bool $bool |
|
511 |
*/ |
|
512 |
function affirm_received($order_id, $user_id = 0) |
|
513 |
{ |
|
514 |
/* 查询订单信息,检查状态 */ |
|
515 |
$sql = "SELECT user_id, order_sn , order_status, shipping_status, pay_status FROM ".$GLOBALS['ecs']->table('order_info') ." WHERE order_id = '$order_id'"; |
|
516 |
|
|
517 |
$order = $GLOBALS['db']->GetRow($sql); |
|
518 |
|
|
519 |
// 如果用户ID大于 0 。检查订单是否属于该用户 |
|
520 |
if ($user_id > 0 && $order['user_id'] != $user_id) |
|
521 |
{ |
|
522 |
$GLOBALS['err'] -> add($GLOBALS['_LANG']['no_priv']); |
|
523 |
|
|
524 |
return false; |
|
525 |
} |
|
526 |
/* 检查订单 */ |
|
527 |
elseif ($order['shipping_status'] == SS_RECEIVED) |
|
528 |
{ |
|
529 |
$GLOBALS['err'] ->add($GLOBALS['_LANG']['order_already_received']); |
|
530 |
|
|
531 |
return false; |
|
532 |
} |
|
533 |
elseif ($order['shipping_status'] != SS_SHIPPED) |
|
534 |
{ |
|
535 |
$GLOBALS['err']->add($GLOBALS['_LANG']['order_invalid']); |
|
536 |
|
|
537 |
return false; |
|
538 |
} |
|
539 |
/* 修改订单发货状态为“确认收货” */ |
|
540 |
else |
|
541 |
{ |
|
542 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('order_info') . " SET shipping_status = '" . SS_RECEIVED . "',shipping_time_end = '" . gmtime() . "' WHERE order_id = '$order_id'"; |
|
543 |
if ($GLOBALS['db']->query($sql)) |
|
544 |
{ |
|
545 |
if(get_cod_id($order_id)){ |
|
546 |
get_pingtai_rebate_from_supplier($order_id); |
|
547 |
$GLOBALS['db']->query("UPDATE " . $GLOBALS['ecs']->table('order_info') . " SET rebate_ispay = 2 WHERE order_id = ".$order_id); |
|
548 |
} |
|
549 |
$sql_2 = "SELECT back_id FROM " . $GLOBALS['ecs']->table('back_order') . " WHERE order_id = '$order_id' AND status_back < 6 AND status_back != 3"; |
|
550 |
$re_2 = $GLOBALS['db']->getCol($sql_2); |
|
551 |
if (count($re_2) > 0) |
|
552 |
{ |
|
553 |
$sql_3 = "UPDATE " . $GLOBALS['ecs']->table('back_goods') . " SET status_back = 8 WHERE back_id in (" . implode(',', $re_2) . ")"; |
|
554 |
$GLOBALS['db']->query($sql_3); |
|
555 |
} |
|
556 |
|
|
557 |
$sql_4 = "UPDATE " . $GLOBALS['ecs']->table('back_order') . " SET status_back = 8 WHERE order_id = '$order_id' AND status_back < 6 AND status_back != 3"; |
|
558 |
$GLOBALS['db']->query($sql_4); |
|
559 |
|
|
560 |
/* 记录日志 */ |
|
561 |
order_action($order['order_sn'], $order['order_status'], SS_RECEIVED, $order['pay_status'], '', $GLOBALS['_LANG']['buyer']); |
|
562 |
|
|
563 |
return true; |
|
564 |
} |
|
565 |
else |
|
566 |
{ |
|
567 |
die($GLOBALS['db']->errorMsg()); |
|
568 |
} |
|
569 |
} |
|
570 |
|
|
571 |
} |
|
572 |
|
|
573 |
/** |
|
574 |
* 保存用户的收货人信息 |
|
575 |
* 如果收货人信息中的 id 为 0 则新增一个收货人信息 |
|
576 |
* |
|
577 |
* @access public |
|
578 |
* @param array $consignee |
|
579 |
* @param boolean $default 是否将该收货人信息设置为默认收货人信息 |
|
580 |
* @return boolean |
|
581 |
*/ |
|
582 |
function save_consignee($consignee, $default=false) |
|
583 |
{ |
|
584 |
if ($consignee['address_id'] > 0) |
|
585 |
{ |
|
586 |
/* 修改地址 */ |
|
587 |
$res = $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('user_address'), $consignee, 'UPDATE', 'address_id = ' . $consignee['address_id']." AND `user_id`= '".$_SESSION['user_id']."'"); |
|
588 |
} |
|
589 |
else |
|
590 |
{ |
|
591 |
/* 添加地址 */ |
|
592 |
$res = $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('user_address'), $consignee, 'INSERT'); |
|
593 |
$consignee['address_id'] = $GLOBALS['db']->insert_id(); |
|
594 |
} |
|
595 |
|
|
596 |
if ($default) |
|
597 |
{ |
|
598 |
/* 保存为用户的默认收货地址 */ |
|
599 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('users') . |
|
600 |
" SET address_id = '$consignee[address_id]' WHERE user_id = '$_SESSION[user_id]'"; |
|
601 |
|
|
602 |
$res = $GLOBALS['db']->query($sql); |
|
603 |
} |
|
604 |
|
|
605 |
return $res !== false; |
|
606 |
} |
|
607 |
|
|
608 |
/** |
|
609 |
* 删除一个收货地址 |
|
610 |
* |
|
611 |
* @access public |
|
612 |
* @param integer $id |
|
613 |
* @return boolean |
|
614 |
*/ |
|
615 |
function drop_consignee($id) |
|
616 |
{ |
|
617 |
$sql = "SELECT user_id FROM " .$GLOBALS['ecs']->table('user_address') . " WHERE address_id = '$id'"; |
|
618 |
$uid = $GLOBALS['db']->getOne($sql); |
|
619 |
|
|
620 |
if ($uid != $_SESSION['user_id']) |
|
621 |
{ |
|
622 |
return false; |
|
623 |
} |
|
624 |
else |
|
625 |
{ |
|
626 |
$sql = "DELETE FROM " .$GLOBALS['ecs']->table('user_address') . " WHERE address_id = '$id'"; |
|
627 |
$res = $GLOBALS['db']->query($sql); |
|
628 |
|
|
629 |
return $res; |
|
630 |
} |
|
631 |
} |
|
632 |
|
|
633 |
/** |
|
634 |
* 添加或更新指定用户收货地址 |
|
635 |
* |
|
636 |
* @access public |
|
637 |
* @param array $address |
|
638 |
* @return bool |
|
639 |
*/ |
|
640 |
function update_address($address) |
|
641 |
{ |
|
642 |
$address_id = intval($address['address_id']); |
|
643 |
unset($address['address_id']); |
|
644 |
|
|
645 |
if ($address_id > 0) |
|
646 |
{ |
|
647 |
/* 更新指定记录 */ |
|
648 |
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('user_address'), $address, 'UPDATE', 'address_id = ' .$address_id . ' AND user_id = ' . $address['user_id']); |
|
649 |
} |
|
650 |
else |
|
651 |
{ |
|
652 |
/* 插入一条新记录 */ |
|
653 |
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('user_address'), $address, 'INSERT'); |
|
654 |
$address_id = $GLOBALS['db']->insert_id(); |
|
655 |
} |
|
656 |
|
|
657 |
if (isset($address['defalut']) && $address['default'] > 0 && isset($address['user_id'])) |
|
658 |
{ |
|
659 |
$sql = "UPDATE ".$GLOBALS['ecs']->table('users') . |
|
660 |
" SET address_id = '".$address_id."' ". |
|
661 |
" WHERE user_id = '" .$address['user_id']. "'"; |
|
662 |
$GLOBALS['db'] ->query($sql); |
|
663 |
} |
|
664 |
|
|
665 |
return true; |
|
666 |
} |
|
667 |
|
|
668 |
/** |
|
669 |
* 获取指订单的详情 |
|
670 |
* |
|
671 |
* @access public |
|
672 |
* @param int $order_id 订单ID |
|
673 |
* @param int $user_id 用户ID |
|
674 |
* |
|
675 |
* @return arr $order 订单所有信息的数组 |
|
676 |
*/ |
|
677 |
function get_order_detail($order_id, $user_id = 0) |
|
678 |
{ |
|
679 |
include_once(ROOT_PATH . 'includes/lib_order.php'); |
|
680 |
|
|
681 |
$order_id = intval($order_id); |
|
682 |
if ($order_id <= 0) |
|
683 |
{ |
|
684 |
$GLOBALS['err']->add($GLOBALS['_LANG']['invalid_order_id']); |
|
685 |
|
|
686 |
return false; |
|
687 |
} |
|
688 |
$order = order_info($order_id); |
|
689 |
|
|
690 |
//检查订单是否属于该用户 |
|
691 |
if ($user_id > 0 && $user_id != $order['user_id']) |
|
692 |
{ |
|
693 |
$GLOBALS['err']->add($GLOBALS['_LANG']['no_priv']); |
|
694 |
|
|
695 |
return false; |
|
696 |
} |
|
697 |
|
|
698 |
/* 对发货号处理 */ |
|
699 |
if (!empty($order['invoice_no'])) |
|
700 |
{ |
|
701 |
$shipping_code = $GLOBALS['db']->GetOne("SELECT shipping_code FROM ".$GLOBALS['ecs']->table('shipping') ." WHERE shipping_id = '$order[shipping_id]'"); |
|
702 |
$plugin = ROOT_PATH.'includes/modules/shipping/'. $shipping_code. '.php'; |
|
703 |
if (file_exists($plugin)) |
|
704 |
{ |
|
705 |
include_once($plugin); |
|
706 |
$shipping = new $shipping_code; |
|
707 |
$order['invoice_no_a'] = $shipping->query($order['invoice_no']); |
|
708 |
} |
|
709 |
} |
|
710 |
|
|
711 |
/* 只有未确认才允许用户修改订单地址 */ |
|
712 |
if ($order['order_status'] == OS_UNCONFIRMED) |
|
713 |
{ |
|
714 |
$order['allow_update_address'] = 1; //允许修改收货地址 |
|
715 |
} |
|
716 |
else |
|
717 |
{ |
|
718 |
$order['allow_update_address'] = 0; |
|
719 |
} |
|
720 |
|
|
721 |
/* 获取订单中实体商品数量 */ |
|
722 |
$order['exist_real_goods'] = exist_real_goods($order_id); |
|
723 |
|
|
724 |
/* 如果是未付款状态,生成支付按钮 */ |
|
725 |
if ($order['pay_status'] == PS_UNPAYED && |
|
726 |
($order['order_status'] == OS_UNCONFIRMED || |
|
727 |
$order['order_status'] == OS_CONFIRMED)) |
|
728 |
{ |
|
729 |
/* |
|
730 |
* 在线支付按钮 |
|
731 |
*/ |
|
732 |
//支付方式信息 |
|
733 |
$payment_info = array(); |
|
734 |
$payment_info = payment_info($order['pay_id']); |
|
735 |
|
|
736 |
//无效支付方式 |
|
737 |
if ($payment_info === false) |
|
738 |
{ |
|
739 |
$order['pay_online'] = ''; |
|
740 |
} |
|
741 |
else |
|
742 |
{ |
|
743 |
//取得支付信息,生成支付代码 |
|
744 |
$payment = unserialize_config($payment_info['pay_config']); |
|
745 |
if($payment_info['pay_code'] == 'alipay_bank') |
|
746 |
{ |
|
747 |
$payment['www_ecshop68_com_alipay_bank'] = $order['defaultbank']; |
|
748 |
} |
|
749 |
|
|
750 |
//获取需要支付的log_id |
|
751 |
$order['log_id'] = get_paylog_id($order['order_id'], $pay_type = PAY_ORDER); |
|
752 |
$order['user_name'] = $_SESSION['user_name']; |
|
753 |
$order['pay_desc'] = $payment_info['pay_desc']; |
|
754 |
|
|
755 |
/* 调用相应的支付方式文件 */ |
|
756 |
include_once(ROOT_PATH . 'includes/modules/payment/' . $payment_info['pay_code'] . '.php'); |
|
757 |
|
|
758 |
/* 取得在线支付方式的支付按钮 */ |
|
759 |
$pay_obj = new $payment_info['pay_code']; |
|
760 |
|
|
761 |
$order['pay_online'] = $pay_obj->get_code($order, $payment); |
|
762 |
} |
|
763 |
} |
|
764 |
else |
|
765 |
{ |
|
766 |
$order['pay_online'] = ''; |
|
767 |
} |
|
768 |
|
|
769 |
/* 无配送时的处理 */ |
|
770 |
$order['shipping_id'] == -1 and $order['shipping_name'] = $GLOBALS['_LANG']['shipping_not_need']; |
|
771 |
|
|
772 |
/* 其他信息初始化 */ |
|
773 |
$order['how_oos_name'] = $order['how_oos']; |
|
774 |
$order['how_surplus_name'] = $order['how_surplus']; |
|
775 |
|
|
776 |
/* 虚拟商品付款后处理 */ |
|
777 |
if ($order['pay_status'] != PS_UNPAYED) |
|
778 |
{ |
|
779 |
/* 取得已发货的虚拟商品信息 */ |
|
780 |
$virtual_goods = get_virtual_goods($order_id, true); |
|
781 |
$virtual_card = array(); |
|
782 |
foreach ($virtual_goods AS $code => $goods_list) |
|
783 |
{ |
|
784 |
/* 只处理虚拟卡 */ |
|
785 |
if ($code == 'virtual_card') |
|
786 |
{ |
|
787 |
foreach ($goods_list as $goods) |
|
788 |
{ |
|
789 |
if ($info = virtual_card_result($order['order_sn'], $goods)) |
|
790 |
{ |
|
791 |
$virtual_card[] = array('goods_id'=>$goods['goods_id'], 'goods_name'=>$goods['goods_name'], 'info'=>$info); |
|
792 |
} |
|
793 |
} |
|
794 |
} |
|
795 |
/* 处理超值礼包里面的虚拟卡 */ |
|
796 |
if ($code == 'package_buy') |
|
797 |
{ |
|
798 |
foreach ($goods_list as $goods) |
|
799 |
{ |
|
800 |
$sql = 'SELECT g.goods_id FROM ' . $GLOBALS['ecs']->table('package_goods') . ' AS pg, ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
801 |
"WHERE pg.goods_id = g.goods_id AND pg.package_id = '" . $goods['goods_id'] . "' AND extension_code = 'virtual_card'"; |
|
802 |
$vcard_arr = $GLOBALS['db']->getAll($sql); |
|
803 |
|
|
804 |
foreach ($vcard_arr AS $val) |
|
805 |
{ |
|
806 |
if ($info = virtual_card_result($order['order_sn'], $val)) |
|
807 |
{ |
|
808 |
$virtual_card[] = array('goods_id'=>$goods['goods_id'], 'goods_name'=>$goods['goods_name'], 'info'=>$info); |
|
809 |
} |
|
810 |
} |
|
811 |
} |
|
812 |
} |
|
813 |
} |
|
814 |
$var_card = deleteRepeat($virtual_card); |
|
815 |
$GLOBALS['smarty']->assign('virtual_card', $var_card); |
|
816 |
} |
|
817 |
|
|
818 |
/* 确认时间 支付时间 发货时间 */ |
|
819 |
if ($order['confirm_time'] > 0 && ($order['order_status'] == OS_CONFIRMED || $order['order_status'] == OS_SPLITED || $order['order_status'] == OS_SPLITING_PART)) |
|
820 |
{ |
|
821 |
$order['confirm_time'] = sprintf($GLOBALS['_LANG']['confirm_time'], local_date($GLOBALS['_CFG']['time_format'], $order['confirm_time'])); |
|
822 |
} |
|
823 |
else |
|
824 |
{ |
|
825 |
$order['confirm_time'] = ''; |
|
826 |
} |
|
827 |
if ($order['pay_time'] > 0 && $order['pay_status'] != PS_UNPAYED) |
|
828 |
{ |
|
829 |
$order['pay_time'] = sprintf($GLOBALS['_LANG']['pay_time'], local_date($GLOBALS['_CFG']['time_format'], $order['pay_time'])); |
|
830 |
} |
|
831 |
else |
|
832 |
{ |
|
833 |
$order['pay_time'] = ''; |
|
834 |
} |
|
835 |
if ($order['shipping_time'] > 0 && in_array($order['shipping_status'], array(SS_SHIPPED, SS_RECEIVED))) |
|
836 |
{ |
|
837 |
$order['shipping_time'] = sprintf($GLOBALS['_LANG']['shipping_time'], local_date($GLOBALS['_CFG']['time_format'], $order['shipping_time'])); |
|
838 |
} |
|
839 |
else |
|
840 |
{ |
|
841 |
$order['shipping_time'] = ''; |
|
842 |
} |
|
843 |
|
|
844 |
return $order; |
|
845 |
|
|
846 |
} |
|
847 |
|
|
848 |
/** |
|
849 |
* 获取用户可以和并的订单数组 |
|
850 |
* |
|
851 |
* @access public |
|
852 |
* @param int $user_id 用户ID |
|
853 |
* |
|
854 |
* @return array $merge 可合并订单数组 |
|
855 |
*/ |
|
856 |
function get_user_merge($user_id) |
|
857 |
{ |
|
858 |
include_once(ROOT_PATH . 'includes/lib_order.php'); |
|
859 |
$sql = "SELECT order_sn FROM ".$GLOBALS['ecs']->table('order_info') . |
|
860 |
" WHERE user_id = '$user_id' " . order_query_sql('unprocessed') . |
|
861 |
"AND extension_code = '' ". |
|
862 |
" ORDER BY add_time DESC"; |
|
863 |
$list = $GLOBALS['db']->GetCol($sql); |
|
864 |
|
|
865 |
$merge = array(); |
|
866 |
foreach ($list as $val) |
|
867 |
{ |
|
868 |
$merge[$val] = $val; |
|
869 |
} |
|
870 |
|
|
871 |
return $merge; |
|
872 |
} |
|
873 |
|
|
874 |
/** |
|
875 |
* 合并指定用户订单 |
|
876 |
* |
|
877 |
* @access public |
|
878 |
* @param string $from_order 合并的从订单号 |
|
879 |
* @param string $to_order 合并的主订单号 |
|
880 |
* |
|
881 |
* @return boolen $bool |
|
882 |
*/ |
|
883 |
function merge_user_order($from_order, $to_order, $user_id = 0) |
|
884 |
{ |
|
885 |
if ($user_id > 0) |
|
886 |
{ |
|
887 |
/* 检查订单是否属于指定用户 */ |
|
888 |
if (strlen($to_order) > 0) |
|
889 |
{ |
|
890 |
$sql = "SELECT user_id FROM " .$GLOBALS['ecs']->table('order_info'). |
|
891 |
" WHERE order_sn = '$to_order'"; |
|
892 |
$order_user = $GLOBALS['db']->getOne($sql); |
|
893 |
if ($order_user != $user_id) |
|
894 |
{ |
|
895 |
$GLOBALS['err']->add($GLOBALS['_LANG']['no_priv']); |
|
896 |
} |
|
897 |
} |
|
898 |
else |
|
899 |
{ |
|
900 |
$GLOBALS['err']->add($GLOBALS['_LANG']['order_sn_empty']); |
|
901 |
return false; |
|
902 |
} |
|
903 |
} |
|
904 |
|
|
905 |
$result = merge_order($from_order, $to_order); |
|
906 |
if ($result === true) |
|
907 |
{ |
|
908 |
return true; |
|
909 |
} |
|
910 |
else |
|
911 |
{ |
|
912 |
$GLOBALS['err']->add($result); |
|
913 |
return false; |
|
914 |
} |
|
915 |
} |
|
916 |
|
|
917 |
/** |
|
918 |
* 将指定订单中的商品添加到购物车 |
|
919 |
* |
|
920 |
* @access public |
|
921 |
* @param int $order_id |
|
922 |
* |
|
923 |
* @return mix $message 成功返回true, 错误返回出错信息 |
|
924 |
*/ |
|
925 |
function return_to_cart($order_id) |
|
926 |
{ |
|
927 |
/* 初始化基本件数量 goods_id => goods_number */ |
|
928 |
$basic_number = array(); |
|
929 |
|
|
930 |
/* 查订单商品:不考虑赠品 */ |
|
931 |
$sql = "SELECT goods_id, product_id,goods_number, goods_attr, parent_id, goods_attr_id" . |
|
932 |
" FROM " . $GLOBALS['ecs']->table('order_goods') . |
|
933 |
" WHERE order_id = '$order_id' AND is_gift = 0 AND extension_code <> 'package_buy'" . |
|
934 |
" ORDER BY parent_id ASC"; |
|
935 |
$res = $GLOBALS['db']->query($sql); |
|
936 |
|
|
937 |
$time = gmtime(); |
|
938 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
939 |
{ |
|
940 |
// 查该商品信息:是否删除、是否上架 |
|
941 |
|
|
942 |
$sql = "SELECT goods_sn, goods_name, goods_number, market_price, " . |
|
943 |
"IF(is_promote = 1 AND '$time' BETWEEN promote_start_date AND promote_end_date, promote_price, shop_price) AS goods_price," . |
|
944 |
"is_real, extension_code, is_alone_sale, goods_type " . |
|
945 |
"FROM " . $GLOBALS['ecs']->table('goods') . |
|
946 |
" WHERE goods_id = '$row[goods_id]' " . |
|
947 |
" AND is_delete = 0 LIMIT 1"; |
|
948 |
$goods = $GLOBALS['db']->getRow($sql); |
|
949 |
|
|
950 |
// 如果该商品不存在,处理下一个商品 |
|
951 |
if (empty($goods)) |
|
952 |
{ |
|
953 |
continue; |
|
954 |
} |
|
955 |
if($row['product_id']) |
|
956 |
{ |
|
957 |
$order_goods_product_id=$row['product_id']; |
|
958 |
$sql="SELECT product_number from ".$GLOBALS['ecs']->table('products')."where product_id='$order_goods_product_id'"; |
|
959 |
$product_number=$GLOBALS['db']->getOne($sql); |
|
960 |
} |
|
961 |
// 如果使用库存,且库存不足,修改数量 |
|
962 |
if ($GLOBALS['_CFG']['use_storage'] == 1 && ($row['product_id']?($product_number<$row['goods_number']):($goods['goods_number'] < $row['goods_number']))) |
|
963 |
{ |
|
964 |
if ($goods['goods_number'] == 0 || $product_number=== 0) |
|
965 |
{ |
|
966 |
// 如果库存为0,处理下一个商品 |
|
967 |
continue; |
|
968 |
} |
|
969 |
else |
|
970 |
{ |
|
971 |
if($row['product_id']) |
|
972 |
{ |
|
973 |
$row['goods_number']=$product_number; |
|
974 |
} |
|
975 |
else |
|
976 |
{ |
|
977 |
// 库存不为0,修改数量 |
|
978 |
$row['goods_number'] = $goods['goods_number']; |
|
979 |
} |
|
980 |
} |
|
981 |
} |
|
982 |
|
|
983 |
//检查商品价格是否有会员价格 |
|
984 |
$sql = "SELECT goods_number FROM" . $GLOBALS['ecs']->table('cart') . " " . |
|
985 |
"WHERE session_id = '" . SESS_ID . "' " . |
|
986 |
"AND goods_id = '" . $row['goods_id'] . "' " . |
|
987 |
"AND rec_type = '" . CART_GENERAL_GOODS . "' LIMIT 1"; |
|
988 |
$temp_number = $GLOBALS['db']->getOne($sql); |
|
989 |
$row['goods_number'] += $temp_number; |
|
990 |
|
|
991 |
$attr_array = empty($row['goods_attr_id']) ? array() : explode(',', $row['goods_attr_id']); |
|
992 |
$goods['goods_price'] = get_final_price($row['goods_id'], $row['goods_number'], true, $attr_array); |
|
993 |
|
|
994 |
// 要返回购物车的商品 |
|
995 |
$return_goods = array( |
|
996 |
'goods_id' => $row['goods_id'], |
|
997 |
'goods_sn' => addslashes($goods['goods_sn']), |
|
998 |
'goods_name' => addslashes($goods['goods_name']), |
|
999 |
'market_price' => $goods['market_price'], |
|
1000 |
'goods_price' => $goods['goods_price'], |
|
1001 |
'goods_number' => $row['goods_number'], |
|
1002 |
'goods_attr' => empty($row['goods_attr']) ? '' : addslashes($row['goods_attr']), |
|
1003 |
'goods_attr_id' => empty($row['goods_attr_id']) ? '' : addslashes($row['goods_attr_id']), |
|
1004 |
'is_real' => $goods['is_real'], |
|
1005 |
'extension_code'=> addslashes($goods['extension_code']), |
|
1006 |
'parent_id' => '0', |
|
1007 |
'is_gift' => '0', |
|
1008 |
'rec_type' => CART_GENERAL_GOODS |
|
1009 |
); |
|
1010 |
|
|
1011 |
// 如果是配件 |
|
1012 |
if ($row['parent_id'] > 0) |
|
1013 |
{ |
|
1014 |
// 查询基本件信息:是否删除、是否上架、能否作为普通商品销售 |
|
1015 |
$sql = "SELECT goods_id " . |
|
1016 |
"FROM " . $GLOBALS['ecs']->table('goods') . |
|
1017 |
" WHERE goods_id = '$row[parent_id]' " . |
|
1018 |
" AND is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 LIMIT 1"; |
|
1019 |
$parent = $GLOBALS['db']->getRow($sql); |
|
1020 |
if ($parent) |
|
1021 |
{ |
|
1022 |
// 如果基本件存在,查询组合关系是否存在 |
|
1023 |
$sql = "SELECT goods_price " . |
|
1024 |
"FROM " . $GLOBALS['ecs']->table('group_goods') . |
|
1025 |
" WHERE parent_id = '$row[parent_id]' " . |
|
1026 |
" AND goods_id = '$row[goods_id]' LIMIT 1"; |
|
1027 |
$fitting_price = $GLOBALS['db']->getOne($sql); |
|
1028 |
if ($fitting_price) |
|
1029 |
{ |
|
1030 |
// 如果组合关系存在,取配件价格,取基本件数量,改parent_id |
|
1031 |
$return_goods['parent_id'] = $row['parent_id']; |
|
1032 |
$return_goods['goods_price'] = $fitting_price; |
|
1033 |
$return_goods['goods_number'] = $basic_number[$row['parent_id']]; |
|
1034 |
} |
|
1035 |
} |
|
1036 |
} |
|
1037 |
else |
|
1038 |
{ |
|
1039 |
// 保存基本件数量 |
|
1040 |
$basic_number[$row['goods_id']] = $row['goods_number']; |
|
1041 |
} |
|
1042 |
|
|
1043 |
// 返回购物车:看有没有相同商品 |
|
1044 |
$sql = "SELECT goods_id " . |
|
1045 |
"FROM " . $GLOBALS['ecs']->table('cart') . |
|
1046 |
" WHERE session_id = '" . SESS_ID . "' " . |
|
1047 |
" AND goods_id = '$return_goods[goods_id]' " . |
|
1048 |
" AND goods_attr = '$return_goods[goods_attr]' " . |
|
1049 |
" AND parent_id = '$return_goods[parent_id]' " . |
|
1050 |
" AND is_gift = 0 " . |
|
1051 |
" AND rec_type = '" . CART_GENERAL_GOODS . "'"; |
|
1052 |
$cart_goods = $GLOBALS['db']->getOne($sql); |
|
1053 |
if (empty($cart_goods)) |
|
1054 |
{ |
|
1055 |
// 没有相同商品,插入 |
|
1056 |
$return_goods['session_id'] = SESS_ID; |
|
1057 |
$return_goods['user_id'] = $_SESSION['user_id']; |
|
1058 |
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('cart'), $return_goods, 'INSERT'); |
|
1059 |
} |
|
1060 |
else |
|
1061 |
{ |
|
1062 |
// 有相同商品,修改数量 |
|
1063 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET " . |
|
1064 |
"goods_number = '" . $return_goods['goods_number'] . "' " . |
|
1065 |
",goods_price = '" . $return_goods['goods_price'] . "' " . |
|
1066 |
"WHERE session_id = '" . SESS_ID . "' " . |
|
1067 |
"AND goods_id = '" . $return_goods['goods_id'] . "' " . |
|
1068 |
"AND rec_type = '" . CART_GENERAL_GOODS . "' LIMIT 1"; |
|
1069 |
$GLOBALS['db']->query($sql); |
|
1070 |
} |
|
1071 |
} |
|
1072 |
|
|
1073 |
// 清空购物车的赠品 |
|
1074 |
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . |
|
1075 |
" WHERE session_id = '" . SESS_ID . "' AND is_gift = 1"; |
|
1076 |
$GLOBALS['db']->query($sql); |
|
1077 |
|
|
1078 |
return true; |
|
1079 |
} |
|
1080 |
|
|
1081 |
/** |
|
1082 |
* 保存用户收货地址 |
|
1083 |
* |
|
1084 |
* @access public |
|
1085 |
* @param array $address array_keys(consignee string, email string, address string, zipcode string, tel string, mobile stirng, sign_building string, best_time string, order_id int) |
|
1086 |
* @param int $user_id 用户ID |
|
1087 |
* |
|
1088 |
* @return boolen $bool |
|
1089 |
*/ |
|
1090 |
function save_order_address($address, $user_id) |
|
1091 |
{ |
|
1092 |
$GLOBALS['err']->clean(); |
|
1093 |
/* 数据验证 */ |
|
1094 |
empty($address['consignee']) and $GLOBALS['err']->add($GLOBALS['_LANG']['consigness_empty']); |
|
1095 |
empty($address['address']) and $GLOBALS['err']->add($GLOBALS['_LANG']['address_empty']); |
|
1096 |
$address['order_id'] == 0 and $GLOBALS['err']->add($GLOBALS['_LANG']['order_id_empty']); |
|
1097 |
// 邮箱格式校验 |
|
1098 |
if (!empty($address['email']) && !is_email($address['email'])) |
|
1099 |
{ |
|
1100 |
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_invalid'], $address['email'])); |
|
1101 |
} |
|
1102 |
// 手机号不能为空并且校验手机号码格式 |
|
1103 |
if(empty($address['mobile'])) |
|
1104 |
{ |
|
1105 |
$GLOBALS['err']->add($GLOBALS['_LANG']['mobile_phone_empty']); |
|
1106 |
} |
|
1107 |
else if(!is_mobile_phone($address['mobile'])) |
|
1108 |
{ |
|
1109 |
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['mobile_phone_invalid'], $address['mobile'])); |
|
1110 |
} |
|
1111 |
|
|
1112 |
if ($GLOBALS['err']->error_no > 0) |
|
1113 |
{ |
|
1114 |
return false; |
|
1115 |
} |
|
1116 |
|
|
1117 |
/* 检查订单状态 */ |
|
1118 |
$sql = "SELECT user_id, order_status FROM " .$GLOBALS['ecs']->table('order_info'). " WHERE order_id = '" .$address['order_id']. "'"; |
|
1119 |
$row = $GLOBALS['db']->getRow($sql); |
|
1120 |
if ($row) |
|
1121 |
{ |
|
1122 |
if ($user_id > 0 && $user_id != $row['user_id']) |
|
1123 |
{ |
|
1124 |
$GLOBALS['err']->add($GLOBALS['_LANG']['no_priv']); |
|
1125 |
return false; |
|
1126 |
} |
|
1127 |
if ($row['order_status'] != OS_UNCONFIRMED) |
|
1128 |
{ |
|
1129 |
$GLOBALS['err']->add($GLOBALS['_LANG']['require_unconfirmed']); |
|
1130 |
return false; |
|
1131 |
} |
|
1132 |
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $address, 'UPDATE', "order_id = '$address[order_id]'"); |
|
1133 |
return true; |
|
1134 |
} |
|
1135 |
else |
|
1136 |
{ |
|
1137 |
/* 订单不存在 */ |
|
1138 |
$GLOBALS['err']->add($GLOBALS['_LANG']['order_exist']); |
|
1139 |
return false; |
|
1140 |
} |
|
1141 |
} |
|
1142 |
|
|
1143 |
/** |
|
1144 |
* |
|
1145 |
* @access public |
|
1146 |
* @param int $user_id 用户ID |
|
1147 |
* @param int $num 列表显示条数 |
|
1148 |
* @param int $start 显示起始位置 |
|
1149 |
* @param int $suppid 店铺id |
|
1150 |
* @return array $arr 红保列表 |
|
1151 |
*/ |
|
1152 |
function get_user_bouns_list($user_id, $num = 10, $start = 0, $suppid=-1) |
|
1153 |
{ |
|
1154 |
/* $sql = "SELECT u.bonus_sn,u.supplier_id, u.order_id, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date ". |
|
1155 |
" FROM " .$GLOBALS['ecs']->table('user_bonus'). " AS u ,". |
|
1156 |
$GLOBALS['ecs']->table('bonus_type'). " AS b". |
|
1157 |
" WHERE u.bonus_type_id = b.type_id AND u.user_id = '" .$user_id. "'";*/ |
|
1158 |
$sql = "SELECT u.bonus_sn,u.supplier_id, u.order_id, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date ". |
|
1159 |
" FROM " .$GLOBALS['ecs']->table('user_bonus'). " AS u ,". |
|
1160 |
$GLOBALS['ecs']->table('bonus_type'). " AS b". |
|
1161 |
" WHERE u.bonus_type_id = b.type_id AND u.user_id = '" .$user_id. "'"; |
|
1162 |
|
|
1163 |
if($suppid>-1){ |
|
1164 |
$sql .= " AND u.supplier_id=".intval($suppid); |
|
1165 |
} |
|
1166 |
|
|
1167 |
$res = $GLOBALS['db']->selectLimit($sql, $num, $start); |
|
1168 |
$arr = array(); |
|
1169 |
|
|
1170 |
$day = getdate(); |
|
1171 |
$cur_date = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']); |
|
1172 |
|
|
1173 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
1174 |
{ |
|
1175 |
/* 先判断是否被使用,然后判断是否开始或过期 */ |
|
1176 |
if (empty($row['order_id'])) |
|
1177 |
{ |
|
1178 |
/* 没有被使用 */ |
|
1179 |
if ($row['use_start_date'] > $cur_date) |
|
1180 |
{ |
|
1181 |
$row['status'] = $GLOBALS['_LANG']['not_start']; |
|
1182 |
} |
|
1183 |
else if ($row['use_end_date'] < $cur_date) |
|
1184 |
{ |
|
1185 |
$row['status'] = $GLOBALS['_LANG']['overdue']; |
|
1186 |
} |
|
1187 |
else |
|
1188 |
{ |
|
1189 |
$row['status'] = $GLOBALS['_LANG']['not_use']; |
|
1190 |
} |
|
1191 |
} |
|
1192 |
else |
|
1193 |
{ |
|
1194 |
$row['status'] = '<a href="user.php?act=order_detail&order_id=' .$row['order_id']. '" >' .$GLOBALS['_LANG']['had_use']. '</a>'; |
|
1195 |
} |
|
1196 |
|
|
1197 |
if($row['supplier_id'] == '0') |
|
1198 |
{ |
|
1199 |
$row['supplier_id'] = "自营商"; |
|
1200 |
} |
|
1201 |
else |
|
1202 |
{ |
|
1203 |
$supplierid = $row['supplier_id']; |
|
1204 |
$sql = "SELECT * FROM ".$GLOBALS['ecs']->table('supplier_shop_config')."WHERE supplier_id = '$supplierid' AND code = 'shop_name'"; |
|
1205 |
$supp = $GLOBALS['db']->getRow($sql); |
|
1206 |
$row['s_id'] = $supplierid; |
|
1207 |
$row['supplier_id'] = $supp['value']; |
|
1208 |
} |
|
1209 |
$row['use_startdate'] = local_date($GLOBALS['_CFG']['date_format'], $row['use_start_date']); |
|
1210 |
$row['use_enddate'] = local_date($GLOBALS['_CFG']['date_format'], $row['use_end_date']); |
|
1211 |
|
|
1212 |
$arr[] = $row; |
|
1213 |
} |
|
1214 |
return $arr; |
|
1215 |
|
|
1216 |
} |
|
1217 |
|
|
1218 |
/** |
|
1219 |
* 获得会员的团购活动列表 |
|
1220 |
* |
|
1221 |
* @access public |
|
1222 |
* @param int $user_id 用户ID |
|
1223 |
* @param int $num 列表显示条数 |
|
1224 |
* @param int $start 显示起始位置 |
|
1225 |
* |
|
1226 |
* @return array $arr 团购活动列表 |
|
1227 |
*/ |
|
1228 |
function get_user_group_buy($user_id, $num = 10, $start = 0) |
|
1229 |
{ |
|
1230 |
return true; |
|
1231 |
} |
|
1232 |
|
|
1233 |
/** |
|
1234 |
* 获得团购详细信息(团购订单信息) |
|
1235 |
* |
|
1236 |
* |
|
1237 |
*/ |
|
1238 |
function get_group_buy_detail($user_id, $group_buy_id) |
|
1239 |
{ |
|
1240 |
return true; |
|
1241 |
} |
|
1242 |
|
|
1243 |
/** |
|
1244 |
* 去除虚拟卡中重复数据 |
|
1245 |
* |
|
1246 |
* |
|
1247 |
*/ |
|
1248 |
function deleteRepeat($array){ |
|
1249 |
$_card_sn_record = array(); |
|
1250 |
foreach ($array as $_k => $_v){ |
|
1251 |
foreach ($_v['info'] as $__k => $__v){ |
|
1252 |
if (in_array($__v['card_sn'],$_card_sn_record)){ |
|
1253 |
unset($array[$_k]['info'][$__k]); |
|
1254 |
} else { |
|
1255 |
array_push($_card_sn_record,$__v['card_sn']); |
|
1256 |
} |
|
1257 |
} |
|
1258 |
} |
|
1259 |
return $array; |
|
1260 |
} |
|
1261 |
?> |