feat: 商品枚举与支付服务优化,支持中文名称、参考价格及类别筛选
This commit is contained in:
@@ -189,9 +189,10 @@ public class PayService : ApplicationService, IPayService
|
||||
/// <summary>
|
||||
/// 获取商品列表
|
||||
/// </summary>
|
||||
/// <param name="input">获取商品列表输入</param>
|
||||
/// <returns>商品列表</returns>
|
||||
[HttpGet("pay/GoodsList")]
|
||||
public async Task<List<GoodsListOutput>> GetGoodsListAsync()
|
||||
public async Task<List<GoodsListOutput>> GetGoodsListAsync([FromQuery] GetGoodsListInput input)
|
||||
{
|
||||
var goodsList = new List<GoodsListOutput>();
|
||||
|
||||
@@ -205,34 +206,46 @@ public class PayService : ApplicationService, IPayService
|
||||
// 遍历所有商品枚举
|
||||
foreach (GoodsTypeEnum goodsType in Enum.GetValues(typeof(GoodsTypeEnum)))
|
||||
{
|
||||
// 如果指定了商品类别,则过滤
|
||||
if (input.GoodsCategoryType.HasValue)
|
||||
{
|
||||
var goodsCategory = goodsType.GetGoodsCategory();
|
||||
if (goodsCategory != input.GoodsCategoryType.Value)
|
||||
{
|
||||
continue; // 跳过不匹配的商品
|
||||
}
|
||||
}
|
||||
|
||||
var originalPrice = goodsType.GetTotalAmount();
|
||||
decimal actualPrice = originalPrice;
|
||||
decimal? discountAmount = null;
|
||||
string? discountDescription = null;
|
||||
|
||||
// 如果是尊享包商品,计算折扣
|
||||
if (goodsType.IsPremiumPackage() && CurrentUser.IsAuthenticated)
|
||||
if (goodsType.IsPremiumPackage())
|
||||
{
|
||||
discountAmount = goodsType.CalculateDiscount(totalRechargeAmount);
|
||||
actualPrice = goodsType.GetDiscountedPrice(totalRechargeAmount);
|
||||
discountDescription = "累计充值每10元可减2.5元,最多减50元";
|
||||
if ( CurrentUser.IsAuthenticated)
|
||||
{
|
||||
discountAmount = goodsType.CalculateDiscount(totalRechargeAmount);
|
||||
actualPrice = goodsType.GetDiscountedPrice(totalRechargeAmount);
|
||||
|
||||
if (discountAmount > 0)
|
||||
{
|
||||
discountDescription = $"已优惠 ¥{discountAmount:F2}(累计充值每10元减2.5元,最多减50元)";
|
||||
}
|
||||
else
|
||||
{
|
||||
discountDescription = "累计充值每10元可减2.5元,最多减50元";
|
||||
if (discountAmount > 0)
|
||||
{
|
||||
discountDescription = $"根据累积充值已优惠 ¥{discountAmount:F2}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var goodsItem = new GoodsListOutput
|
||||
{
|
||||
GoodsName = goodsType.GetDisplayName(),
|
||||
GoodsName = goodsType.GetChineseName(),
|
||||
OriginalPrice = originalPrice,
|
||||
ReferencePrice = goodsType.GetReferencePrice(),
|
||||
GoodsPrice = actualPrice,
|
||||
GoodsType = goodsType,
|
||||
Remark = GetGoodsRemark(goodsType),
|
||||
GoodsCategory = goodsType.GetGoodsCategory().ToString(),
|
||||
Remark = goodsType.GetRemark(),
|
||||
DiscountAmount = discountAmount,
|
||||
DiscountDescription = discountDescription
|
||||
};
|
||||
@@ -242,28 +255,7 @@ public class PayService : ApplicationService, IPayService
|
||||
|
||||
return goodsList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品备注信息
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <returns>商品备注</returns>
|
||||
private string GetGoodsRemark(GoodsTypeEnum goodsType)
|
||||
{
|
||||
if (goodsType.IsPremiumPackage())
|
||||
{
|
||||
var tokenAmount = goodsType.GetTokenAmount();
|
||||
return $"尊享包服务,提供 {tokenAmount:N0} Tokens(需要VIP资格)";
|
||||
}
|
||||
else if (goodsType.IsVipService())
|
||||
{
|
||||
var validMonths = goodsType.GetValidMonths();
|
||||
var monthlyPrice = goodsType.GetMonthlyPrice();
|
||||
return $"VIP服务,有效期 {validMonths} 个月,月均价 ¥{monthlyPrice:F2}";
|
||||
}
|
||||
|
||||
return "未知商品类型";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取交易状态描述
|
||||
|
||||
Reference in New Issue
Block a user