【发布时间】:2016-09-28 14:20:22
【问题描述】:
我试图开发一个函数,允许在函数中计算特定价格的数量折扣
示例:10% = $discount_customer[] 在数据库功能中
$qty 是用户添加的
if $qty < 5 then $$discount_customer[] = 0:价格不变
if $qty > 5 et qty < 10 then $$discount_customer[] = 10%:价格为-10%
...
if $qty > 10 then $$discount_customer[] = 15%:价格为-15%
$id : 产品ID
$qty:客户插入的订单数量
$products_price : 产品价格
public function getProductsNewPriceByDiscountQuantity($id, $qty, $products_price) {
$OSCOM_Db = Registry::get('Db');
$OSCOM_Customer = Registry::get('Customer');
$QprodutsQuantityDiscount= $OSCOM_Db->prepare('select discount_quantity,
discount_customer
from :table_products_discount_quantity
where products_id = :products_id
and customers_group_id = :customers_group_id
and discount_quantity <> 0
');
$QprodutsQuantityDiscount->bindInt(':products_id', (int)$id );
$QprodutsQuantityDiscount->bindInt(':customers_group_id', $OSCOM_Customer->getCustomersGroupID());
$QprodutsQuantityDiscount->execute();
while ($QprodutsQuantityDiscount->fetch()) {
// quantity discount
$discount_quantity[] = $QprodutsQuantityDiscount->valueInt('discount_quantity');
// Customer discount
$discount_customer[] = $QprodutsQuantityDiscount->valueDecimal('discount_customer');
}
我想创建一个 foreach 但如何?
Thie 元素不采用 between 条件。
foreach ($discount_quantity as $k => $quantity) {
print_r('<pre>');
var_dump($quantity );
print_r('</pre>');
foreach ($discount_customer as $c => $discount) {
if ($qty > $quantity) {
$news_price = $products_price -(($products_price * $discount) /100);
}
print_r('<pre>');
print_r($news_price);
print_r('</pre>');
}
return $newprice
}
谢谢
【问题讨论】:
-
那么……我们应该为你编写这个函数吗?或者什么...?
-
我试过了,你可以看到一个示例 aboce,但我不知道如何管理计算之间的关系