@qq286531097
2017-02-24T08:05:58.000000Z
字数 3155
阅读 216
未分类
item_id | price |
---|---|
200055 | 699 |
200708 | 498 |
活动: 全品类 -> 满100减10
$itemsInfo =
Array
(
[0] => 200055
[1] => 200708
)
$priceCount = 1197
$cutPrice = 10
$apiData =
Array
(
[itemPrice] => Array
(
[200055] => Array
(
[priceInitial] => 699
[priceCount] => 699
[priceInfo] => Array
(
[0] => 699.000
)
[pointInfo] => Array
(
[0] => 2.44
)
[pointCount] => 2.44
[price] => 699.000|0
[integration] => 699.000|0
[num] => 1
)
[200708] => Array
(
[priceInitial] => 996
[priceCount] => 996
[priceInfo] => Array
(
[0] => 498.000
[1] => 498.000
)
[pointInfo] => Array
(
[0] => 1.74
[1] => 1.74
)
[pointCount] => 3.48
[price] => 498.000|0,498.000|0
[integration] => 498.000|0,498.000|0
[num] => 2
)
)
[items] => Array
(
[0] => Array
(
[promotions_id] => 3
[active_id] => 3
[tag] => fullminus
[price] => 1695
[item_ids] => 200055,200708
[cutPrice] => 10
[whisper] =>
[condition_value] => 100|10
[total_price] => 1685
[sort_order] => 1
[exclusive] => 0
[promotion_name] => 满100减10元
[promotion_tag] => 满减
[extraDiscount] => 0
[activeOrCoupon] => 2
[subpayment] =>
[address] =>
[itemPrice] => Array
(
[200055] => Array
(
[priceInitial] => 699
[priceCount] => 699
[pointCount] => 2.44
[price] => 699.000|0
[point] => 2.44|0
[integration] => 699.000|0
[order] => 0
[num] => 1
[orderPrice] => Array
(
[0] => 699.000
)
[orderPoint] => Array
(
[0] => 2.44
)
)
[200708] => Array
(
[priceInitial] => 996
[priceCount] => 996
[pointCount] => 3.48
[price] => 498.000|0,498.000|0
[point] => 1.74|0,1.74|0
[integration] => 498.000|0,498.000|0
[order] => 0,1
[num] => 2
[orderPrice] => Array
(
[0] => 498.000
[1] => 498.000
)
[orderPoint] => Array
(
[0] => 1.74
[1] => 1.74
)
)
)
[check] => 1
)
)
[price] => Array
(
[price] => 1695
)
)
实现代码核心
public function itemMinPrice($itemsInfo,$priceCount,$cutPrice,&$apiData,$acticeId){
//不是折上折的满减数据[itemInfo]{商品集合} [总价] [cutprice] [apidata] [活动ID]
//算出各自占的比例
$count = count($itemsInfo);
//重置输出变量
$arr = array();
foreach ($itemsInfo as $k => $v) {
if ($k != $count - 1) {
//总共此商品要减去的钱数
$itemCutPrice = intval(round(((($apiData['items'][$acticeId]['itemPrice'][$v]['priceInitial']/$priceCount)*100))*$cutPrice)/100);
//获得活动内该itemId下价格下所有的数量
$itemCount = count(explode( ',', $apiData['items'][$acticeId]['itemPrice'][$v]['price']));
//循环出该商品的所有的价格,然后根据该价格重新拼成字符串
foreach (explode( ',', $apiData['items'][$acticeId]['itemPrice'][$v]['price']) as $m => $n) {
if ($m != $itemCount - 1) {
//小数位四舍五入
$arr[$v][$m] = substr($n,0,strpos($n,'|')).'|'.intval(round((((substr($n,0,strpos($n,'|'))-substr($n,(strpos($n,'|')+1)))/$apiData['items'][$acticeId]['itemPrice'][$v]['priceInitial'])*100*$itemCutPrice)/100));
$arrPrice += substr($arr[$v][$m],(strpos($arr[$v][$m],'|')+1));
}else{
//算出剩余的数据
$arr[$v][$m] = substr($n,0,strpos($n,'|')).'|'.(($itemCutPrice - $arrPrice));
}
}
$pctPrice += $itemCutPrice;
}else{
//获得最后一个剩余的钱数
$lastPrice = $cutPrice - $pctPrice;
//获得活动内该itemId下价格下所有的数量
$itemcount = count(explode( ',', $apiData['items'][$acticeId]['itemPrice'][$v]['price']));
//循环出该商品的所有的价格,然后根据该价格重新拼成字符串
foreach (explode( ',', $apiData['items'][$acticeId]['itemPrice'][$v]['price']) as $m => $n) {
if ($m != $itemcount - 1) {
$arr[$v][$m] = substr($n,0,strpos($n,'|')).'|'.intval(floor((((substr($n,0,strpos($n,'|'))-substr($n,(strpos($n,'|')+1)))/$apiData['items'][$acticeId]['itemPrice'][$v]['priceInitial'])*100*$lastPrice)/100));
$arr_price += substr($arr[$v][$m],(strpos($arr[$v][$m],'|')+1));
}else{
//最后一个数据,减去前面的数据
$arr[$v][$m] = substr($n,0,strpos($n,'|')).'|'.(($lastPrice - $arr_price));
}
}
}
}
//[应减去的金额] [原数组] [活动的序号]
$this->group($arr,$apiData,$acticeId);
}