【发布时间】:2021-08-29 12:56:38
【问题描述】:
我正在开发一个 B2B 订购应用程序,该应用程序具有基于客户的特价商品价格表。对于某些库存商品,价目表可以有一个固定价格 (UnitPrice) 或一个折扣百分比 (DiscountPercentage),但不能两者兼有。每个产品还有一个标准价格 (SellingPrice),如果没有折扣,则应使用该价格。
在控制器中,我创建了一个包含产品代码、正常售价、折扣百分比和单价的集合,例如。
{
id: "6",
StockItemName: "FIRELIGHTERS 24X12 PCS",
StockCode: "000000000019",
SellingPrice: "386.600",
DiscountPercentage: "5.000",
UnitPrice: "0.00"
},
{
id: "7",
StockItemName: "BRIQUETTES 1X4KG",
StockCode: "000000000020",
SellingPrice: "39.500",
DiscountPercentage: "0.000",
UnitPrice: "35.400",
}
{
id: "8",
StockItemName: "BRIQUETTES 1X10KG",
StockCode: "000000000021",
SellingPrice: "45.000",
DiscountPercentage: "0.000",
UnitPrice: "0.000",
}
在刀片视图中,我有一个下拉选项来选择您要订购的商品,并且应该显示适用的价格。因此,此列表可以包含具有百分比折扣的产品、折扣价格 (UnitPrice) 的产品和标准价格 (SellingPrice) 的产品的任意组合:
@foreach ($products as $product)
<option value="{{ $product->id }}" {{ $oldProduct == $product->id ? ' selected' : '' }}>
{{ $product->StockCode }} - {{ $product->StockItemName }} -
{{ empty($product->DiscountPercentage) ?
( !empty($product->UnitPrice) ? number_format($product->UnitPrice, 2)
: number_format($product->SellingPrice, 2) )
: number_format($product->SellingPrice - (($product->DiscountPercentage / 100)
* $product->SellingPrice), 2)
}}
</option>
@endforeach
这适用于 DiscountPercentages,但如果 DiscountPercentage 为空而 UnitPrice 不是,它会显示 SellingPrice 而不是 UnitPrice。
任何意见将不胜感激
【问题讨论】: