commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 批发前台文件 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
|
|
9 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
10 |
|
|
11 |
/* 如果没登录,提示登录 */ |
|
12 |
if ($_SESSION['user_rank'] <= 0) |
|
13 |
{ |
|
14 |
show_message($_LANG['ws_user_rank'], $_LANG['ws_return_home'], 'index.php'); |
|
15 |
} |
|
16 |
|
|
17 |
/*------------------------------------------------------ */ |
|
18 |
//-- act 操作项的初始化 |
|
19 |
/*------------------------------------------------------ */ |
|
20 |
if (empty($_REQUEST['act'])) |
|
21 |
{ |
|
22 |
$_REQUEST['act'] = 'list'; |
|
23 |
} |
|
24 |
|
|
25 |
/*------------------------------------------------------ */ |
|
26 |
//-- 批发活动列表 |
|
27 |
/*------------------------------------------------------ */ |
|
28 |
if ($_REQUEST['act'] == 'list') |
|
29 |
{ |
|
30 |
$search_category = empty($_REQUEST['search_category']) ? 0 : intval($_REQUEST['search_category']); |
|
31 |
$search_keywords = isset($_REQUEST['search_keywords']) ? trim($_REQUEST['search_keywords']) : ''; |
|
32 |
$param = array(); // 翻页链接所带参数列表 |
|
33 |
|
|
34 |
/* 查询条件:当前用户的会员等级(搜索关键字) */ |
|
35 |
$where = " WHERE g.goods_id = w.goods_id |
|
36 |
AND w.enabled = 1 |
|
37 |
AND CONCAT(',', w.rank_ids, ',') LIKE '" . '%,' . $_SESSION['user_rank'] . ',%' . "' "; |
|
38 |
|
|
39 |
/* 搜索 */ |
|
40 |
/* 搜索类别 */ |
|
41 |
if ($search_category) |
|
42 |
{ |
|
43 |
$where .= " AND g.cat_id = '$search_category' "; |
|
44 |
$param['search_category'] = $search_category; |
|
45 |
$smarty->assign('search_category', $search_category); |
|
46 |
} |
|
47 |
/* 搜索商品名称和关键字 */ |
|
48 |
if ($search_keywords) |
|
49 |
{ |
|
50 |
$where .= " AND (g.keywords LIKE '%$search_keywords%' |
|
51 |
OR g.goods_name LIKE '%$search_keywords%') "; |
|
52 |
$param['search_keywords'] = $search_keywords; |
|
53 |
$smarty->assign('search_keywords', $search_keywords); |
|
54 |
} |
|
55 |
|
|
56 |
/* 取得批发商品总数 */ |
|
57 |
$sql = "SELECT COUNT(*) FROM " . $ecs->table('wholesale') . " AS w, " . $ecs->table('goods') . " AS g " . $where; |
|
58 |
$count = $db->getOne($sql); |
|
59 |
|
|
60 |
if ($count > 0) |
|
61 |
{ |
|
62 |
$default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : 'text'; |
|
63 |
$display = (isset($_REQUEST['display']) && in_array(trim(strtolower($_REQUEST['display'])), array('list', 'text'))) ? trim($_REQUEST['display']) : (isset($_COOKIE['ECS']['display']) ? $_COOKIE['ECS']['display'] : $default_display_type); |
|
64 |
$display = in_array($display, array('list', 'text')) ? $display : 'text'; |
|
65 |
setcookie('ECS[display]', $display, gmtime() + 86400 * 7); |
|
66 |
|
|
67 |
/* 取得每页记录数 */ |
|
68 |
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10; |
|
69 |
|
|
70 |
/* 计算总页数 */ |
|
71 |
$page_count = ceil($count / $size); |
|
72 |
|
|
73 |
/* 取得当前页 */ |
|
74 |
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1; |
|
75 |
$page = $page > $page_count ? $page_count : $page; |
|
76 |
|
|
77 |
/* 取得当前页的批发商品 */ |
|
78 |
$wholesale_list = wholesale_list($size, $page, $where); |
|
79 |
$smarty->assign('wholesale_list', $wholesale_list); |
|
80 |
|
|
81 |
$param['act'] = 'list'; |
|
82 |
$pager = get_pager('wholesale.php', array_reverse ($param, TRUE), $count, $page, $size); |
|
83 |
$pager['display'] = $display; |
|
84 |
$smarty->assign('pager', $pager); |
|
85 |
|
|
86 |
/* 批发商品购物车 */ |
|
87 |
$smarty->assign('cart_goods', isset($_SESSION['wholesale_goods']) ? $_SESSION['wholesale_goods'] : array()); |
|
88 |
} |
|
89 |
|
|
90 |
/* 模板赋值 */ |
|
91 |
assign_template(); |
|
92 |
$position = assign_ur_here(); |
|
93 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
94 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
95 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
96 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
97 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
98 |
|
|
99 |
assign_dynamic('wholesale'); |
|
100 |
|
|
101 |
/* 显示模板 */ |
|
102 |
$smarty->display('wholesale_list.dwt'); |
|
103 |
} |
|
104 |
|
|
105 |
/*------------------------------------------------------ */ |
|
106 |
//-- 下载价格单 |
|
107 |
/*------------------------------------------------------ */ |
|
108 |
elseif ($_REQUEST['act'] == 'price_list') |
|
109 |
{ |
|
110 |
$data = $_LANG['goods_name'] . "\t" . $_LANG['goods_attr'] . "\t" . $_LANG['number'] . "\t" . $_LANG['ws_price'] . "\t\n"; |
|
111 |
$sql = "SELECT * FROM " . $ecs->table('wholesale') . |
|
112 |
"WHERE enabled = 1 AND CONCAT(',', rank_ids, ',') LIKE '" . '%,' . $_SESSION['user_rank'] . ',%' . "'"; |
|
113 |
$res = $db->query($sql); |
|
114 |
while ($row = $db->fetchRow($res)) |
|
115 |
{ |
|
116 |
$price_list = unserialize($row['prices']); |
|
117 |
foreach ($price_list as $attr_price) |
|
118 |
{ |
|
119 |
if ($attr_price['attr']) |
|
120 |
{ |
|
121 |
$sql = "SELECT attr_value FROM " . $ecs->table('goods_attr') . |
|
122 |
" WHERE goods_attr_id " . db_create_in($attr_price['attr']); |
|
123 |
$goods_attr = join(',', $db->getCol($sql)); |
|
124 |
} |
|
125 |
else |
|
126 |
{ |
|
127 |
$goods_attr = ''; |
|
128 |
} |
|
129 |
foreach ($attr_price['qp_list'] as $qp) |
|
130 |
{ |
|
131 |
$data .= $row['goods_name'] . "\t" . $goods_attr . "\t" . $qp['quantity'] . "\t" . $qp['price'] . "\t\n"; |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
header("Content-type: application/vnd.ms-excel; charset=utf-8"); |
|
137 |
header("Content-Disposition: attachment; filename=price_list.xls"); |
|
138 |
if (EC_CHARSET == 'utf-8') |
|
139 |
{ |
|
140 |
echo ecs_iconv('UTF8', 'GB2312', $data); |
|
141 |
} |
|
142 |
else |
|
143 |
{ |
|
144 |
echo $data; |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
/*------------------------------------------------------ */ |
|
149 |
//-- 加入购物车 |
|
150 |
/*------------------------------------------------------ */ |
|
151 |
elseif ($_REQUEST['act'] == 'add_to_cart') |
|
152 |
{ |
|
153 |
/* 取得参数 */ |
|
154 |
$act_id = intval($_POST['act_id']); |
|
155 |
$goods_number = $_POST['goods_number'][$act_id]; |
|
156 |
$attr_id = isset($_POST['attr_id']) ? $_POST['attr_id'] : array(); |
|
157 |
if(isset($attr_id[$act_id])) |
|
158 |
{ |
|
159 |
$goods_attr = $attr_id[$act_id]; |
|
160 |
} |
|
161 |
|
|
162 |
/* 用户提交必须全部通过检查,才能视为完成操作 */ |
|
163 |
|
|
164 |
/* 检查数量 */ |
|
165 |
if (empty($goods_number) || (is_array($goods_number) && array_sum($goods_number) <= 0)) |
|
166 |
{ |
|
167 |
show_message($_LANG['ws_invalid_goods_number']); |
|
168 |
} |
|
169 |
|
|
170 |
/* 确定购买商品列表 */ |
|
171 |
$goods_list = array(); |
|
172 |
if (is_array($goods_number)) |
|
173 |
{ |
|
174 |
foreach ($goods_number as $key => $value) |
|
175 |
{ |
|
176 |
if (!$value) |
|
177 |
{ |
|
178 |
unset($goods_number[$key], $goods_attr[$key]); |
|
179 |
continue; |
|
180 |
} |
|
181 |
|
|
182 |
$goods_list[] = array('number' => $goods_number[$key], 'goods_attr' => $goods_attr[$key]); |
|
183 |
} |
|
184 |
} |
|
185 |
else |
|
186 |
{ |
|
187 |
$goods_list[0] = array('number' => $goods_number, 'goods_attr' => ''); |
|
188 |
} |
|
189 |
|
|
190 |
/* 取批发相关数据 */ |
|
191 |
$wholesale = wholesale_info($act_id); |
|
192 |
|
|
193 |
/* 检查session中该商品,该属性是否存在 */ |
|
194 |
if (isset($_SESSION['wholesale_goods'])) |
|
195 |
{ |
|
196 |
foreach ($_SESSION['wholesale_goods'] as $goods) |
|
197 |
{ |
|
198 |
if ($goods['goods_id'] == $wholesale['goods_id']) |
|
199 |
{ |
|
200 |
if (empty($goods_attr)) |
|
201 |
{ |
|
202 |
show_message($_LANG['ws_goods_attr_exists']); |
|
203 |
} |
|
204 |
elseif (in_array($goods['goods_attr_id'], $goods_attr)) |
|
205 |
{ |
|
206 |
show_message($_LANG['ws_goods_attr_exists']); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
/* 获取购买商品的批发方案的价格阶梯 (一个方案多个属性组合、一个属性组合、一个属性、无属性) */ |
|
213 |
$attr_matching = false; |
|
214 |
foreach ($wholesale['price_list'] as $attr_price) |
|
215 |
{ |
|
216 |
// 没有属性 |
|
217 |
if (empty($attr_price['attr'])) |
|
218 |
{ |
|
219 |
$attr_matching = true; |
|
220 |
$goods_list[0]['qp_list'] = $attr_price['qp_list']; |
|
221 |
break; |
|
222 |
} |
|
223 |
// 有属性 |
|
224 |
elseif (($key = is_attr_matching($goods_list, $attr_price['attr'])) !== false) |
|
225 |
{ |
|
226 |
$attr_matching = true; |
|
227 |
$goods_list[$key]['qp_list'] = $attr_price['qp_list']; |
|
228 |
} |
|
229 |
} |
|
230 |
if (!$attr_matching) |
|
231 |
{ |
|
232 |
show_message($_LANG['ws_attr_not_matching']); |
|
233 |
} |
|
234 |
|
|
235 |
/* 检查数量是否达到最低要求 */ |
|
236 |
foreach ($goods_list as $goods_key => $goods) |
|
237 |
{ |
|
238 |
if ($goods['number'] < $goods['qp_list'][0]['quantity']) |
|
239 |
{ |
|
240 |
show_message($_LANG['ws_goods_number_not_enough']); |
|
241 |
} |
|
242 |
else |
|
243 |
{ |
|
244 |
$goods_price = 0; |
|
245 |
foreach ($goods['qp_list'] as $qp) |
|
246 |
{ |
|
247 |
if ($goods['number'] >= $qp['quantity']) |
|
248 |
{ |
|
249 |
$goods_list[$goods_key]['goods_price'] = $qp['price']; |
|
250 |
} |
|
251 |
else |
|
252 |
{ |
|
253 |
break; |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
/* 写入session */ |
|
260 |
foreach ($goods_list as $goods_key => $goods) |
|
261 |
{ |
|
262 |
// 属性名称 |
|
263 |
$goods_attr_name = ''; |
|
264 |
if (!empty($goods['goods_attr'])) |
|
265 |
{ |
|
266 |
foreach ($goods['goods_attr'] as $attr) |
|
267 |
{ |
|
268 |
$goods_attr_name .= $attr['attr_name'] . ':' . $attr['attr_val'] . ' '; |
|
269 |
} |
|
270 |
} |
|
271 |
|
|
272 |
// 总价 |
|
273 |
$total = $goods['number'] * $goods['goods_price']; |
|
274 |
|
|
275 |
$_SESSION['wholesale_goods'][] = array( |
|
276 |
'goods_id' => $wholesale['goods_id'], |
|
277 |
'goods_name' => $wholesale['goods_name'], |
|
278 |
'goods_attr_id' => $goods['goods_attr'], |
|
279 |
'goods_attr' => $goods_attr_name, |
|
280 |
'goods_number' => $goods['number'], |
|
281 |
'goods_price' => $goods['goods_price'], |
|
282 |
'subtotal' => $total, |
|
283 |
'formated_goods_price' => price_format($goods['goods_price'], false), |
|
284 |
'formated_subtotal' => price_format($total, false), |
|
285 |
'goods_url' => build_uri('goods', array('gid' => $wholesale['goods_id']), $wholesale['goods_name']), |
|
286 |
); |
|
287 |
} |
|
288 |
|
|
289 |
unset($goods_attr, $attr_id, $goods_list, $wholesale, $goods_attr_name); |
|
290 |
|
|
291 |
/* 刷新页面 */ |
|
292 |
ecs_header("Location: ./wholesale.php\n"); |
|
293 |
exit; |
|
294 |
} |
|
295 |
|
|
296 |
/*------------------------------------------------------ */ |
|
297 |
//-- 从购物车删除 |
|
298 |
/*------------------------------------------------------ */ |
|
299 |
elseif ($_REQUEST['act'] == 'drop_goods') |
|
300 |
{ |
|
301 |
$key = intval($_REQUEST['key']); |
|
302 |
if (isset($_SESSION['wholesale_goods'][$key])) |
|
303 |
{ |
|
304 |
unset($_SESSION['wholesale_goods'][$key]); |
|
305 |
} |
|
306 |
|
|
307 |
/* 刷新页面 */ |
|
308 |
ecs_header("Location: ./wholesale.php\n"); |
|
309 |
exit; |
|
310 |
} |
|
311 |
|
|
312 |
/*------------------------------------------------------ */ |
|
313 |
//-- 提交订单 |
|
314 |
/*------------------------------------------------------ */ |
|
315 |
elseif ($_REQUEST['act'] == 'submit_order') |
|
316 |
{ |
|
317 |
include_once(ROOT_PATH . 'includes/lib_order.php'); |
|
318 |
|
|
319 |
/* 检查购物车中是否有商品 */ |
|
320 |
if (count($_SESSION['wholesale_goods']) == 0) |
|
321 |
{ |
|
322 |
show_message($_LANG['no_goods_in_cart']); |
|
323 |
} |
|
324 |
|
|
325 |
/* 检查备注信息 */ |
|
326 |
if (empty($_POST['remark'])) |
|
327 |
{ |
|
328 |
show_message($_LANG['ws_remark']); |
|
329 |
} |
|
330 |
|
|
331 |
/* 计算商品总额 */ |
|
332 |
$goods_amount = 0; |
|
333 |
foreach ($_SESSION['wholesale_goods'] as $goods) |
|
334 |
{ |
|
335 |
$goods_amount += $goods['subtotal']; |
|
336 |
} |
|
337 |
|
|
338 |
$order = array( |
|
339 |
'postscript' => htmlspecialchars($_POST['remark']), |
|
340 |
'user_id' => $_SESSION['user_id'], |
|
341 |
'add_time' => gmtime(), |
|
342 |
'order_status' => OS_UNCONFIRMED, |
|
343 |
'shipping_status' => SS_UNSHIPPED, |
|
344 |
'pay_status' => PS_UNPAYED, |
|
345 |
'goods_amount' => $goods_amount, |
|
346 |
'order_amount' => $goods_amount, |
|
347 |
); |
|
348 |
|
|
349 |
/* 插入订单表 */ |
|
350 |
$error_no = 0; |
|
351 |
do |
|
352 |
{ |
|
353 |
$order['order_sn'] = get_order_sn(); //获取新订单号 |
|
354 |
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT'); |
|
355 |
|
|
356 |
$error_no = $GLOBALS['db']->errno(); |
|
357 |
|
|
358 |
if ($error_no > 0 && $error_no != 1062) |
|
359 |
{ |
|
360 |
die($GLOBALS['db']->errorMsg()); |
|
361 |
} |
|
362 |
} |
|
363 |
while ($error_no == 1062); //如果是订单号重复则重新提交数据 |
|
364 |
|
|
365 |
$new_order_id = $db->insert_id(); |
|
366 |
$order['order_id'] = $new_order_id; |
|
367 |
|
|
368 |
/* 插入订单商品 */ |
|
369 |
foreach ($_SESSION['wholesale_goods'] as $goods) |
|
370 |
{ |
|
371 |
//如果存在货品 |
|
372 |
$product_id = 0; |
|
373 |
if (!empty($goods['goods_attr_id'])) |
|
374 |
{ |
|
375 |
$goods_attr_id = array(); |
|
376 |
foreach ($goods['goods_attr_id'] as $value) |
|
377 |
{ |
|
378 |
$goods_attr_id[$value['attr_id']] = $value['attr_val_id']; |
|
379 |
} |
|
380 |
|
|
381 |
ksort($goods_attr_id); |
|
382 |
$goods_attr = implode('|', $goods_attr_id); |
|
383 |
|
|
384 |
$sql = "SELECT product_id FROM " . $ecs->table('products') . " WHERE goods_attr = '$goods_attr' AND goods_id = '" . $goods['goods_id'] . "'"; |
|
385 |
$product_id = $db->getOne($sql); |
|
386 |
} |
|
387 |
|
|
388 |
$sql = "INSERT INTO " . $ecs->table('order_goods') . "( " . |
|
389 |
"order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ". |
|
390 |
"goods_price, goods_attr, is_real, extension_code, parent_id, is_gift) ". |
|
391 |
" SELECT '$new_order_id', goods_id, goods_name, goods_sn, '$product_id','$goods[goods_number]', market_price, ". |
|
392 |
"'$goods[goods_price]', '$goods[goods_attr]', is_real, extension_code, 0, 0 ". |
|
393 |
" FROM " .$ecs->table('goods') . |
|
394 |
" WHERE goods_id = '$goods[goods_id]'"; |
|
395 |
$db->query($sql); |
|
396 |
} |
|
397 |
|
|
398 |
/* 给商家发邮件 */ |
|
399 |
if ($_CFG['service_email'] != '') |
|
400 |
{ |
|
401 |
$tpl = get_mail_template('remind_of_new_order'); |
|
402 |
$smarty->assign('order', $order); |
|
403 |
$smarty->assign('shop_name', $_CFG['shop_name']); |
|
404 |
$smarty->assign('send_date', date($_CFG['time_format'])); |
|
405 |
$content = $smarty->fetch('str:' . $tpl['template_content']); |
|
406 |
send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl['template_subject'], $content, $tpl['is_html']); |
|
407 |
} |
|
408 |
|
|
409 |
/* 如果需要,发短信 */ |
|
410 |
if ($_CFG['sms_order_placed'] == '1' && $_CFG['sms_shop_mobile'] != '') |
|
411 |
{ |
|
412 |
include_once('includes/cls_sms.php'); |
|
413 |
$sms = new sms(); |
|
414 |
$msg = $_LANG['order_placed_sms']; |
|
415 |
$sms->send($_CFG['sms_shop_mobile'], sprintf($msg, $order['consignee'], $order['tel']),'', 13,1); |
|
416 |
} |
|
417 |
|
|
418 |
/* 清空购物车 */ |
|
419 |
unset($_SESSION['wholesale_goods']); |
|
420 |
|
|
421 |
/* 提示 */ |
|
422 |
show_message(sprintf($_LANG['ws_order_submitted'], $order['order_sn']), $_LANG['ws_return_home'], 'index.php'); |
|
423 |
} |
|
424 |
|
|
425 |
/** |
|
426 |
* 取得某页的批发商品 |
|
427 |
* @param int $size 每页记录数 |
|
428 |
* @param int $page 当前页 |
|
429 |
* @param string $where 查询条件 |
|
430 |
* @return array |
|
431 |
*/ |
|
432 |
function wholesale_list($size, $page, $where) |
|
433 |
{ |
|
434 |
$list = array(); |
|
435 |
$sql = "SELECT w.*, g.goods_thumb, g.goods_name as goods_name " . |
|
436 |
"FROM " . $GLOBALS['ecs']->table('wholesale') . " AS w, " . |
|
437 |
$GLOBALS['ecs']->table('goods') . " AS g " . $where . |
|
438 |
" AND w.goods_id = g.goods_id "; |
|
439 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); |
|
440 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
441 |
{ |
|
442 |
if (empty($row['goods_thumb'])) |
|
443 |
{ |
|
444 |
$row['goods_thumb'] = $GLOBALS['_CFG']['no_picture']; |
|
445 |
} |
|
446 |
$row['goods_url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); |
|
447 |
|
|
448 |
$properties = get_goods_properties($row['goods_id']); |
|
449 |
$row['goods_attr'] = $properties['pro']; |
|
450 |
|
|
451 |
$price_ladder = get_price_ladder($row['goods_id']); |
|
452 |
$row['price_ladder'] = $price_ladder; |
|
453 |
|
|
454 |
$list[] = $row; |
|
455 |
} |
|
456 |
|
|
457 |
return $list; |
|
458 |
} |
|
459 |
|
|
460 |
/** |
|
461 |
* 商品价格阶梯 |
|
462 |
* @param int $goods_id 商品ID |
|
463 |
* @return array |
|
464 |
*/ |
|
465 |
function get_price_ladder($goods_id) |
|
466 |
{ |
|
467 |
/* 显示商品规格 */ |
|
468 |
$goods_attr_list = array_values(get_goods_attr($goods_id)); |
|
469 |
$sql = "SELECT prices FROM " . $GLOBALS['ecs']->table('wholesale') . |
|
470 |
"WHERE goods_id = " . $goods_id; |
|
471 |
$row = $GLOBALS['db']->getRow($sql); |
|
472 |
|
|
473 |
$arr = array(); |
|
474 |
$_arr = unserialize($row['prices']); |
|
475 |
if (is_array($_arr)) |
|
476 |
{ |
|
477 |
foreach(unserialize($row['prices']) as $key => $val) |
|
478 |
{ |
|
479 |
// 显示属性 |
|
480 |
if (!empty($val['attr'])) |
|
481 |
{ |
|
482 |
foreach ($val['attr'] as $attr_key => $attr_val) |
|
483 |
{ |
|
484 |
// 获取当前属性 $attr_key 的信息 |
|
485 |
$goods_attr = array(); |
|
486 |
foreach ($goods_attr_list as $goods_attr_val) |
|
487 |
{ |
|
488 |
if ($goods_attr_val['attr_id'] == $attr_key) |
|
489 |
{ |
|
490 |
$goods_attr = $goods_attr_val; |
|
491 |
break; |
|
492 |
} |
|
493 |
} |
|
494 |
|
|
495 |
// 重写商品规格的价格阶梯信息 |
|
496 |
if (!empty($goods_attr)) |
|
497 |
{ |
|
498 |
$arr[$key]['attr'][] = array( |
|
499 |
'attr_id' => $goods_attr['attr_id'], |
|
500 |
'attr_name' => $goods_attr['attr_name'], |
|
501 |
'attr_val' => (isset($goods_attr['goods_attr_list'][$attr_val]) ? $goods_attr['goods_attr_list'][$attr_val] : ''), |
|
502 |
'attr_val_id' => $attr_val |
|
503 |
); |
|
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
|
|
508 |
// 显示数量与价格 |
|
509 |
foreach($val['qp_list'] as $index => $qp) |
|
510 |
{ |
|
511 |
$arr[$key]['qp_list'][$qp['quantity']] = price_format($qp['price']); |
|
512 |
} |
|
513 |
} |
|
514 |
} |
|
515 |
|
|
516 |
return $arr; |
|
517 |
} |
|
518 |
|
|
519 |
/** |
|
520 |
* 商品属性是否匹配 |
|
521 |
* @param array $goods_list 用户选择的商品 |
|
522 |
* @param array $reference 参照的商品属性 |
|
523 |
* @return bool |
|
524 |
*/ |
|
525 |
function is_attr_matching(&$goods_list, $reference) |
|
526 |
{ |
|
527 |
foreach ($goods_list as $key => $goods) |
|
528 |
{ |
|
529 |
// 需要相同的元素个数 |
|
530 |
if (count($goods['goods_attr']) != count($reference)) |
|
531 |
{ |
|
532 |
break; |
|
533 |
} |
|
534 |
|
|
535 |
// 判断用户提交与批发属性是否相同 |
|
536 |
$is_check = true; |
|
537 |
if (is_array($goods['goods_attr'])) |
|
538 |
{ |
|
539 |
foreach ($goods['goods_attr'] as $attr) |
|
540 |
{ |
|
541 |
if (!(array_key_exists($attr['attr_id'], $reference) && $attr['attr_val_id'] == $reference[$attr['attr_id']])) |
|
542 |
{ |
|
543 |
$is_check = false; |
|
544 |
break; |
|
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
if ($is_check) |
|
549 |
{ |
|
550 |
return $key; |
|
551 |
break; |
|
552 |
} |
|
553 |
} |
|
554 |
|
|
555 |
|
|
556 |
// foreach ($goods_attr as $attr_id => $goods_attr_id) |
|
557 |
// { |
|
558 |
// if (isset($reference[$attr_id]) && $reference[$attr_id] != 0 && $reference[$attr_id] != $goods_attr_id) |
|
559 |
// { |
|
560 |
// return false; |
|
561 |
// } |
|
562 |
// } |
|
563 |
|
|
564 |
return false; |
|
565 |
} |
|
566 |
|
|
567 |
///** |
|
568 |
// * 购物车中的商品属性与当前购买的商品属性是否匹配 |
|
569 |
// * @param array $goods_attr 用户选择的商品属性 |
|
570 |
// * @param array $reference 参照的商品属性 |
|
571 |
// * @return bool |
|
572 |
// */ |
|
573 |
//function is_attr_same($goods_attr, $reference) |
|
574 |
//{ |
|
575 |
// /* 比较元素个数是否相同 */ |
|
576 |
// if (count($goods_attr) == count($reference)) { |
|
577 |
// } |
|
578 |
// |
|
579 |
// return true; |
|
580 |
//} |
|
581 |
?> |