gpt4 book ai didi

PHP - 无法在结账页面获得适当的佣金金额

转载 作者:行者123 更新时间:2023-11-29 12:28:09 24 4
gpt4 key购买 nike

正如标题所示,我无法在结账页面设置适当的佣金金额。

情况如下:

佣金是针对 2 个人 - K 和 J 收取的,基于产品的总金额,而不是购物车的总金额。

我收到了佣金金额,但无法正确设置。

例如:

我有购物车

 Name        Quantity       Rate            Total        Commission
A 3 50.00 150.00 7.50
B 3 80.00 240.00 14.40
C 2 10.00 20.00 1.60

Total 410.00
Taxes 100.00
Shipping 250.00

Net Payable 760.00

根据产品 A 总计、产品 B 总计和产品 C 总计,我必须计算佣金。三种产品的佣金率分别为5%、6%、8%。

现在,产品A和产品C属于人K。产品B属于人J。也就是说,产品A和产品C的佣金应该转移到人K的账户,产品B的佣金应该转移到人J的账户.

我已经在 while 循环中计算了佣金,该循环正确显示了该人的佣金,并将佣金金额存储在 $_SESSION 变量中。

现在,当我将 $_SESSION 代码移出 while 循环时,它会采用最后一个值,这意味着它会覆盖第一个值。

所以我的问题是,如何将佣金金额分成两部分并将其转移到相应的个人账户?

非常感谢任何帮助。谢谢。

编辑 1:

我尝试过的代码位于 while 循环内

$_SESSION['ProductCommission']['PersonK'] = ($productTotal * $row['ProductPersonKCommission'] / 100);
$_SESSION['ProductCommission']['PersonJ'] = ($productTotal * $row['ProductPersonJCommission'] / 100);

编辑 2:

完整代码(实际):

if ( isset( $_SESSION['cart'] ) && $_SESSION['cart'] != "" ) {
$total = 0;
$subTotal = 0; $sbTotal = 0;
$taxAmount = $tax = $totalTaxAmount = $taxAmt = 0;
$cartWeightPerProduct = $totalCartWeight = $amtWeight = 0;
$affiliateCommission = $affComm = 0;
$affiCode = "";

$sql = "SELECT p.*, c.*, ws.*, m.*, a.* FROM products p, categories c, weight_shipping ws, moderators m, affiliates a WHERE ProdCode IN (";
foreach ( $_SESSION['cart'] as $id => $value ) {
$sql .= '"'.$id.'",';
}
$sql = substr( $sql, 0, -1 ) . ") AND p.CatId = c.CatId AND ws.ProdId = p.ProdId AND m.ModCode = p.ModCode AND a.AffiCode = p.AffiCode";

if ($validate->Query($sql) == TRUE) {
if ($validate->NumRows() >= 1) {
while ( $row = $validate->FetchAllDatas() ) {
echo '<td><img src="images/Products/'.$row['ProdCode'].'.jpg" alt="'.$row['ProdCode'].'"><a href="product.php?code='.$row['ProdCode'].'" >'.$row['ProdName'].'</a></td>';
echo '<td>'.$row['ProdCode'].'</td>';
echo '<td><p>Rs. '.$row['ProdRate'].'</p></td>';
echo '<td>'.$_SESSION['cart'][$row['ProdCode']]['quantity'].'</td>';

$sbTotal = $row['ProdRate'] * $_SESSION['cart'][$row['ProdCode']]['quantity'];
$subTotal = $sbTotal;
echo '<td><p>'.number_format($sbTotal, 2).'</p></td>';
$total += $subTotal;
$_SESSION['cartTotalAmount'] = $total;
$tax = $row['CatTaxPercent'];
$taxAmt = (($sbTotal * $tax ) / 100);
$taxAmount += $taxAmt;
$amt = 0;
$cartWeightPerProduct = ($row['weight'] * $_SESSION['cart'][$row['ProdCode']]['quantity']);
echo '</tr>';
$totalCartWeight += $cartWeightPerProduct;

$affComm = $row['ProdAffCommision'];
$affiCode = $row['AffiCode'];

$_SESSION['ProductCommission']['Moderator'] = ($sbTotal * $row['ProdModCommission'] / 100);
$_SESSION['ProductCommission']['Affiliate'] = ($sbTotal * $affComm / 100);
}
$totalTaxAmount += $taxAmount;

$_SESSION['cartWeight'] = $totalCartWeight;

if ( isset( $_SESSION['credits'] ) && $_SESSION['credits'] != "" ) {
$cred = number_format( $_SESSION['credits'], 2 );
} else {
$cred = number_format( 0, 2 );
}

$sessAmnt = ($total + $totalTaxAmount);
$totalPayableAmnt = $sessAmnt + $_SESSION['TotalWeight'];

$_SESSION['sessionTotalPayable'] = ( $totalPayableAmnt - $cred );
$_SESSION['Presentation']['TotalPayableAmount'] = ( $totalPayableAmnt - $cred );
if ( isset( $_SESSION['sessionTotalPayable'] ) ) {
$amt = $totalPayableAmnt;
} else {
$amt = "Rs. 0";
}

echo '<tr><td><p>Cart Total:</p></td><td><p>'.number_format($total, 2).'</p></td></tr>';

echo '<tr><td><p>Taxes:</p></td><td><p>(+) '. number_format($totalTaxAmount, 2) .'</p></td></tr>';

echo '<tr><td><p>Shipping:</p></td><td><p id="shippingAmount">(+) '.number_format($_SESSION['TotalWeight'], 2).'</p></td></tr>';

echo '<tr><t><p><b>Gross Payable:</b></p></td><td><p><b>'.number_format( $totalPayableAmnt ,2 ).'</b></p></td></tr>';

echo '<tr><td><p>Applied Store Credits:</p></td><td><p >(-) '.$cred.'</p></td></tr>';

echo '<tr><td><p>Total Payable Amount:</p></td><td><p >'.number_format( ($amt - $cred ), 2).'</p></td></tr>';

if ( isset( $_SESSION['PaymentMethod']['NetBanking'] ) && $_SESSION['PaymentMethod']['NetBanking'] != "" ) {
echo '<tr><td></td><td><button class="f_right tr_delay_hover r_corners button_type_16 f_size_medium bg_scheme_color color_light m_xs_bottom_5">Proceed</button></td></tr>';
} elseif ( isset( $_SESSION['PaymentMethod']['COD'] ) && $_SESSION['PaymentMethod']['COD'] != "" ) {
echo '<tr><td></td><td><button id="btnCODPayment" class="f_right tr_delay_hover r_corners button_type_16 f_size_medium bg_scheme_color color_light m_xs_bottom_5">Done</button></td></tr>';
}

}
}
} else {
echo 'Your Cart Is Empty';
}

最佳答案

您可以按下面的模式设置 session 数组,然后佣金不会覆盖

<?php 
while($basketCount>0)
{
$_SESSION['COMMSSION'][$agentID] += $calculatedCommisiion;
$basketCount--;
}
?>

关于PHP - 无法在结账页面获得适当的佣金金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27996339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com