Php 计算折扣和数量函数中的新价格

Php 计算折扣和数量函数中的新价格,php,mysql,Php,Mysql,我试图开发一个函数,允许计算数量折扣函数中的特定价格 示例:数据库函数中的10%=$discount\u customer[] $qty由用户添加 如果$qty5 et qty10,则$$折扣\客户[]=15%:价格为-15% $id:产品的id public function getProductsNewPriceByDiscountQuantity($id, $qty, $products_price) { $OSCOM_Db = Registry::get('Db'); $OSCO

我试图开发一个函数,允许计算数量折扣函数中的特定价格

示例:数据库函数中的10%=
$discount\u customer[]

$qty
由用户添加

如果$qty<5,则$$折扣\u客户[]=0
:价格不变

如果$qty>5 et qty<10,则$$折扣\u客户[]=10%
:价格为-10%

如果$qty>10,则$$折扣\客户[]=15%
:价格为-15%

$id
:产品的id

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');
      }
$qty
:客户插入的订单数量

$products\u 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');
      }

谢谢您

公共函数getProductsNewPriceByDiscountQuantity($id,$qty,$products\U price){
$OSCOM_Db=Registry::get('Db');
$OSCOM_Customer=Registry::get('Customer');
$QprodutsQuantityDiscount=$OSCOM\u Db->prepare('选择折扣\u数量,
顾客折扣
来源:表\产品\折扣\数量
其中products\u id=:products\u id
客户组id=:客户组id
折扣数量为0
');
$QprodutsQuantityDiscount->bindInt(“:products_id”,(int)$id);
$QprodutsQuantityDiscount->bindInt(':customers\u group\u id',$OSCOM\u Customer->GetCustomerGroupID());
$Qprodutsquantity折扣->执行();
而($QprodutsQuantityDiscount->fetch()){
$折扣\数量[]=$QprodutsQuantityDiscount->valueInt(“折扣\数量”);
$discount\u customer[]=$QprodutsQuantityDiscount->valueDecimal('discount\u customer');
}
返回$this->getprct折扣($qty,$products\u price);
}
公共函数GetPrcTprice($qty,$products\U价格)
{
$折扣=0;
如果($qty>5&$qty<10){
$折扣=10;
}其他(数量>10){
$折扣=15;
}
$newPrice=$折扣>0
?$产品价格-($产品价格*($折扣/100))
:$newPrice;
返回$newPrice;
}

所以。。。我们应该为您编写这个函数吗?或者什么…?我试过了,你可以看到一个例子,但我不知道如何管理计算之间的间隔上次的
$newPrice
如果应该是
$products\u price
 return $newprice
    }
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()) {
      $discount_quantity[] = $QprodutsQuantityDiscount->valueInt('discount_quantity');
      $discount_customer[] = $QprodutsQuantityDiscount->valueDecimal('discount_customer');
    }

    return $this->getPrctDiscount($qty, $products_price);
}

public function getPrctDiscount($qty, $products_price)
    {
          $discount = 0;
          if ($qty > 5 && $qty < 10) {
            $discount = 10;
          }elseif ($qty > 10) {
            $discount = 15;
          }

          $newPrice = $discount > 0 
            ? $products_price - ($products_price * ($discount/100))
            : $newPrice;

          return $newPrice;
    }