commit | author | age
|
e2b48d
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 购物车更新商品价格 |
|
5 |
*/ |
|
6 |
define('IN_ECS', true); |
|
7 |
require('../includes/init.php'); |
|
8 |
//require('../includes/lib_goods.php'); |
|
9 |
|
|
10 |
$goods_id_arr = isset($_REQUEST['goods_id_arr']) ? trim($_REQUEST['goods_id_arr']) : 0; |
|
11 |
$user_id = isset($_REQUEST['user_id']) ? intval($_REQUEST['user_id']) : 0; |
|
12 |
|
|
13 |
$sql="SELECT g.goods_id,g.shop_price,g.is_promote,g.promote_price,g.promote_start_date,g.promote_end_date FROM ".$GLOBALS['ecs']->table('goods')." AS g WHERE is_delete = '0' AND is_on_sale = '1' and g.goods_number >0 AND g.goods_id IN ($goods_id_arr)"; |
|
14 |
|
|
15 |
$row = $GLOBALS['db'] -> getAll($sql); |
|
16 |
|
|
17 |
$user_rank_name=get_rank_info($user_id); |
|
18 |
$time=time(); |
|
19 |
foreach ($row as $k=>$value) { |
|
20 |
$user_rank_prices=get_user_rank_prices($value['goods_id'],$value['shop_price'],$user_id); |
|
21 |
foreach ($user_rank_prices as $rank_prices_value) { |
|
22 |
if($user_rank_name['rank_name']==$rank_prices_value['rank_name']){ |
|
23 |
if($value['is_promote']==1){ |
|
24 |
|
|
25 |
//if($value['promote_price']<$rank_prices_value['price']&&$value['promote_start_date']<=$time&&$value['promote_end_date']>$time){ |
|
26 |
//$row[$k]['shop_price']=str_replace('¥','',$value['promote_price']); |
|
27 |
//}else{ |
|
28 |
$row[$k]['shop_price']=str_replace('¥','',$rank_prices_value['price']); |
|
29 |
//} |
|
30 |
|
|
31 |
}else{ |
|
32 |
$row[$k]['shop_price']=str_replace('¥','',$rank_prices_value['price']); |
|
33 |
} |
|
34 |
|
|
35 |
} |
|
36 |
} |
|
37 |
|
|
38 |
} |
|
39 |
print_r(json_encode($row)); |
|
40 |
|
|
41 |
/*=====================================的一些函数方法======================================*/ |
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* 获得指定商品的各会员等级对应的价格 |
|
48 |
* |
|
49 |
* @access public |
|
50 |
* @param integer $goods_id |
|
51 |
* @return array |
|
52 |
*/ |
|
53 |
function get_user_rank_prices($goods_id, $shop_price,$user_id) |
|
54 |
{ |
|
55 |
|
|
56 |
$user_rank = $GLOBALS['db']->getOne("SELECT user_rank FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"); |
|
57 |
$sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price / 100) AS price, r.rank_name, r.discount " . |
|
58 |
'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' . |
|
59 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ". |
|
60 |
"ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " . |
|
61 |
"WHERE r.show_price = 1 OR r.rank_id = '$user_rank'"; |
|
62 |
$res = $GLOBALS['db']->query($sql); |
|
63 |
|
|
64 |
$arr = array(); |
|
65 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
66 |
{ |
|
67 |
|
|
68 |
$arr[] = array( |
|
69 |
'rank_name' => htmlspecialchars($row['rank_name']), |
|
70 |
'price' => price_format($row['price'])); |
|
71 |
} |
|
72 |
|
|
73 |
return $arr; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* 获得会员等级 |
|
78 |
* |
|
79 |
* @access public |
|
80 |
* @param integer $goods_id |
|
81 |
* @return array |
|
82 |
*/ |
|
83 |
function get_rank_info($user_id) |
|
84 |
{ |
|
85 |
$user_rank = $GLOBALS['db']->getOne("SELECT user_rank FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'"); |
|
86 |
|
|
87 |
$sql = "SELECT rank_name FROM " . $GLOBALS['ecs']->table('user_rank') . " WHERE rank_id = '$user_rank'"; |
|
88 |
$row = $GLOBALS['db']->getRow($sql); |
|
89 |
$rank_name=$row['rank_name']; |
|
90 |
|
|
91 |
return array('rank_name'=>$rank_name); |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
?> |
|
102 |
|