-
Notifications
You must be signed in to change notification settings - Fork 0
Home
SpencerChang edited this page Jul 22, 2016
·
3 revisions
22026,
'orderDfPrice' => 450,
'orderDfQty' => 3,
);
$arr1 = array(array (
'prodUid' => 22026,
'orderDfPrice' => 450,
'orderDfQty' => 3,
),array (
'prodUid' => 1,
'orderDfPrice' => 100,
'orderDfQty' => 2,
));
print_r(getOffsetBonus($arr1,200));
function getOffsetBonus($orderDetail, $ecoupon) {
if ($ecoupon > 0) {
$amount = intval(1350);
if(isset($orderDetail[0])){
foreach($orderDetail as $key => $value){
$ori_price = intval($value['orderDfQty']) * $value['orderDfPrice'];
$final_price = $amount * $ori_price / ($ecoupon+$amount);
$remainder = $final_price % intval($value['orderDfQty']);
$orderDetail[$key]['orderDfPrice'] = floor($final_price / $value['orderDfQty']);
if($remainder != 0){
$orderDetail[$key]['orderDfQty']--;
$new_order = array();
array_push($new_order,$orderDetail[$key]);
$orderDetail[$key]['orderDfPrice'] = $orderDetail[$key]['orderDfPrice']+$remainder;
$orderDetail[$key]['orderDfQty'] = 1;
array_push($new_order,$orderDetail[$key]);
$orderDetail[$key] = $new_order;
}
}
}else{
$final_price = (intval($orderDetail['orderDfQty']) * $orderDetail['orderDfPrice'] - $ecoupon);
$remainder = $final_price % intval($orderDetail['orderDfQty']);
$orderDetail['orderDfPrice'] = floor($final_price / $orderDetail['orderDfQty']);
if($remainder != 0){
$orderDetail['orderDfQty']--;
$new_order = array();
array_push($new_order,$orderDetail);
$orderDetail['orderDfPrice'] = $orderDetail['orderDfPrice']+$remainder;
$orderDetail['orderDfQty'] = 1;
array_push($new_order,$orderDetail);
$orderDetail = $new_order;
}
}
return (object) $orderDetail;
} else {
return (object) $orderDetail;
}
}