diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GetGoodsListInput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GetGoodsListInput.cs
new file mode 100644
index 00000000..d3fe354a
--- /dev/null
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GetGoodsListInput.cs
@@ -0,0 +1,16 @@
+using Yi.Framework.AiHub.Domain.Shared.Enums;
+
+namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
+
+///
+/// 获取商品列表输入DTO
+///
+public class GetGoodsListInput
+{
+ ///
+ /// 商品类别(可选)
+ /// 如果不传,则返回所有商品
+ /// 如果传了,则只返回指定类别的商品(VIP服务或尊享包)
+ ///
+ public GoodsCategoryType? GoodsCategoryType { get; set; }
+}
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs
index f6696356..7a25970f 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs
@@ -17,25 +17,32 @@ public class GoodsListOutput
///
public decimal OriginalPrice { get; set; }
+ ///
+ /// 商品参考价格
+ ///
+ public decimal ReferencePrice { get; set; }
+
///
/// 商品实际价格(折扣后的价格)
///
public decimal GoodsPrice { get; set; }
///
- /// 商品类型
+ /// 折扣金额(仅尊享包)
///
- public GoodsTypeEnum GoodsType { get; set; }
+ public decimal? DiscountAmount { get; set; }
+
+ ///
+ /// 商品类别
+ ///
+ public string GoodsCategory { get; set; }
///
/// 商品备注
///
public string Remark { get; set; }
- ///
- /// 折扣金额(仅尊享包)
- ///
- public decimal? DiscountAmount { get; set; }
+
///
/// 折扣说明(仅尊享包)
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IPayService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IPayService.cs
index 55edcacf..71ba4185 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IPayService.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/IServices/IPayService.cs
@@ -34,6 +34,7 @@ public interface IPayService : IApplicationService
///
/// 获取商品列表
///
+ /// 获取商品列表输入
/// 商品列表
- Task> GetGoodsListAsync();
+ Task> GetGoodsListAsync([FromQuery] GetGoodsListInput input);
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs
index d234b6b3..1d4f8d5b 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs
@@ -189,9 +189,10 @@ public class PayService : ApplicationService, IPayService
///
/// 获取商品列表
///
+ /// 获取商品列表输入
/// 商品列表
[HttpGet("pay/GoodsList")]
- public async Task> GetGoodsListAsync()
+ public async Task> GetGoodsListAsync([FromQuery] GetGoodsListInput input)
{
var goodsList = new List();
@@ -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;
}
-
- ///
- /// 获取商品备注信息
- ///
- /// 商品类型
- /// 商品备注
- 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 "未知商品类型";
- }
+
///
/// 获取交易状态描述
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs
index 2f3ff637..73d5f752 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs
@@ -10,12 +10,16 @@ namespace Yi.Framework.AiHub.Domain.Shared.Enums;
public class PriceAttribute : Attribute
{
public decimal Price { get; }
+
+ public decimal ReferencePrice { get; }
+
public int ValidMonths { get; }
-
- public PriceAttribute(double price, int validMonths)
+
+ public PriceAttribute(double price, int validMonths, double referencePrice)
{
Price = (decimal)price;
ValidMonths = validMonths;
+ ReferencePrice = (decimal)referencePrice;
}
}
@@ -26,10 +30,14 @@ public class PriceAttribute : Attribute
public class DisplayNameAttribute : Attribute
{
public string DisplayName { get; }
+ public string ChineseName { get; }
+ public string Remark { get; }
- public DisplayNameAttribute(string displayName)
+ public DisplayNameAttribute(string displayName, string chineseName = "", string remark = "")
{
DisplayName = displayName;
+ ChineseName = chineseName;
+ Remark = remark;
}
}
@@ -56,7 +64,7 @@ public enum GoodsCategoryType
///
/// VIP服务
///
- VipService = 1,
+ Vip = 1,
///
/// 尊享包服务
@@ -85,35 +93,35 @@ public class TokenAmountAttribute : Attribute
public enum GoodsTypeEnum
{
// VIP服务
- [Price(29.9, 1)]
- [DisplayName("YiXinVip 1 month")]
- [GoodsCategory(GoodsCategoryType.VipService)]
+ [Price(29.9, 1,29.9)]
+ [DisplayName("YiXinVip 1 month", "1个月", "灵活选择")]
+ [GoodsCategory(GoodsCategoryType.Vip)]
YiXinVip1 = 1,
- [Price(83.7, 3)]
- [DisplayName("YiXinVip 3 month")]
- [GoodsCategory(GoodsCategoryType.VipService)]
+ [Price(83.7, 3,27.9)]
+ [DisplayName("YiXinVip 3 month", "3个月", "短期体验")]
+ [GoodsCategory(GoodsCategoryType.Vip)]
YiXinVip3 = 3,
- [Price(155.4, 6)]
- [DisplayName("YiXinVip 6 month")]
- [GoodsCategory(GoodsCategoryType.VipService)]
+ [Price(155.4, 6,25.9)]
+ [DisplayName("YiXinVip 6 month", "6个月", "年度热销")]
+ [GoodsCategory(GoodsCategoryType.Vip)]
YiXinVip6 = 6,
- [Price(183.2, 8)]
- [DisplayName("YiXinVip 8 month")]
- [GoodsCategory(GoodsCategoryType.VipService)]
+ [Price(183.2, 8,22.9)]
+ [DisplayName("YiXinVip 8 month", "8个月(推荐)", "限时活动,超高性价比")]
+ [GoodsCategory(GoodsCategoryType.Vip)]
YiXinVip8 = 8,
// 尊享包服务 - 需要VIP资格才能购买
- [Price(188.9, 0)]
- [DisplayName("Premium Package 5000W Tokens")]
+ [Price(188.9, 0,1750)]
+ [DisplayName("YiXinPremiumPackage 5000W Tokens", "5000万Tokens", "简单尝试")]
[GoodsCategory(GoodsCategoryType.PremiumPackage)]
[TokenAmount(5000)]
PremiumPackage5000W = 101,
- [Price(248.9, 0)]
- [DisplayName("Premium Package 10000W Tokens")]
+ [Price(248.9, 0,3500)]
+ [DisplayName("YiXinPremiumPackage 10000W Tokens", "1亿Tokens(推荐)", "极致性价比")]
[GoodsCategory(GoodsCategoryType.PremiumPackage)]
[TokenAmount(10000)]
PremiumPackage10000W = 102,
@@ -181,6 +189,18 @@ public static class GoodsTypeEnumExtensions
return validMonths > 0 ? totalPrice / validMonths : 0m;
}
+ ///
+ /// 获取商品参考价格
+ ///
+ /// 商品类型
+ /// 参考价格
+ public static decimal GetReferencePrice(this GoodsTypeEnum goodsType)
+ {
+ var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
+ var priceAttribute = fieldInfo?.GetCustomAttribute();
+ return priceAttribute?.ReferencePrice ?? 0m;
+ }
+
///
/// 获取商品类别
///
@@ -190,7 +210,7 @@ public static class GoodsTypeEnumExtensions
{
var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
var categoryAttribute = fieldInfo?.GetCustomAttribute();
- return categoryAttribute?.Category ?? GoodsCategoryType.VipService;
+ return categoryAttribute?.Category ?? GoodsCategoryType.Vip;
}
///
@@ -210,7 +230,7 @@ public static class GoodsTypeEnumExtensions
/// 是否为VIP服务
public static bool IsVipService(this GoodsTypeEnum goodsType)
{
- return goodsType.GetGoodsCategory() == GoodsCategoryType.VipService;
+ return goodsType.GetGoodsCategory() == GoodsCategoryType.Vip;
}
///
@@ -225,6 +245,30 @@ public static class GoodsTypeEnumExtensions
return tokenAttribute?.TokenAmount ?? 0;
}
+ ///
+ /// 获取商品中文名称
+ ///
+ /// 商品类型
+ /// 中文名称
+ public static string GetChineseName(this GoodsTypeEnum goodsType)
+ {
+ var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
+ var displayNameAttribute = fieldInfo?.GetCustomAttribute();
+ return displayNameAttribute?.ChineseName ?? goodsType.ToString();
+ }
+
+ ///
+ /// 获取商品备注
+ ///
+ /// 商品类型
+ /// 备注信息
+ public static string GetRemark(this GoodsTypeEnum goodsType)
+ {
+ var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
+ var displayNameAttribute = fieldInfo?.GetCustomAttribute();
+ return displayNameAttribute?.Remark ?? string.Empty;
+ }
+
///
/// 计算折扣金额(仅用于尊享包)
/// 规则:每累加充值10元,减少2.5元,最多减少50元