嗨,Friends>,我想要如果数量是6,12,18或24,所以产品的价格将为每种产品10%的折扣。
例如,如果数量是8,那么6个数量的价格将是10%的折扣,剩下的2个数量将不打折。与总共8 quantity=8 6数量* 10%的产品价格一样,2批量*全产品价格total为8 quantity=(6 qty quantity= 10%折扣)+2 qty (全价)。
我想在PHP中看到这个。请帮帮我
发布于 2015-12-06 04:53:02
你所需要的就是魔法。
$magicPriceFunction = function ($pricePerItem, $itemCount) {
$magicNumber = 6;
$discount = 0.1;
$unhappyItemCount = $itemCount % $magicNumber;
$total = 0;
$total += $pricePerItem * $unhappyItemCount;
$total += ($itemCount - $unhappyItemCount) * (1 - $discount) * $pricePerItem;
return $total;
};
var_dump($magicPriceFunction(100, 6));发布于 2015-12-06 04:35:11
我想这是你能做到的一种方法
$quantity = 8;
$remainder = $quantity % 6 ? $quantity % 6 : 0;
$discountItems = $quantity - $remainder;
echo "10% off " . $discountItems . " items and full price on " . $remainder;
// 10% off 6 items and full price on 2https://stackoverflow.com/questions/34113933
复制相似问题