Files
KJD/Store.Product/Models/PublishParameters/Price/SectionPrice.cs
T
2026-09-11 19:11:12 +08:00

73 lines
2.0 KiB
C#

using Store.Product.Models.Product.Sku;
using System.Collections.Generic;
using System.Linq;
namespace Store.Product.Models.PublishParameters.Price
{
/// <summary>
/// 区间价格配置
/// </summary>
public class SectionPrice : PriceConfigBase
{
public override PriceStrategyType PriceType => PriceStrategyType.分段价格;
/// <summary>
/// 区间列表
/// </summary>
public List<SectionItemPrice> SectionList { get; set; } = new List<SectionItemPrice>();
/// <summary>
/// 计算价格
/// </summary>
/// <param name="oldPrice"></param>
/// <returns></returns>
public override decimal ComputedPrice(decimal oldPrice)
{
var newPrice = oldPrice;
if (SectionList != null && SectionList.Count > 0)
{
foreach (var item in SectionList)
{
if (item.BeginPrice < newPrice && newPrice < item.EndPrice)
{
newPrice = item.ComputedPrice(newPrice);
}
}
if (newPrice == oldPrice)
{
newPrice = SectionList.Last().ComputedPrice(newPrice);
}
}
return newPrice;
}
public override SkuMaps ComputedPrice(SkuMaps skuMaps)
{
foreach (var item in skuMaps)
{
item.Price = ComputedPrice(item.Price);
}
return skuMaps;
}
/// <summary>
/// 指定区间价格
/// </summary>
public class SectionItemPrice : MultiplesPrice
{
/// <summary>
/// 开始价格
/// </summary>
public decimal BeginPrice { get; set; } = 0;
/// <summary>
/// 结束价格
/// </summary>
public decimal EndPrice { get; set; } = 10000000;
}
}
}