feat: 商品枚举与支付服务优化,支持中文名称、参考价格及类别筛选
This commit is contained in:
@@ -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
|
||||
/// <summary>
|
||||
/// VIP服务
|
||||
/// </summary>
|
||||
VipService = 1,
|
||||
Vip = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 尊享包服务
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品参考价格
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <returns>参考价格</returns>
|
||||
public static decimal GetReferencePrice(this GoodsTypeEnum goodsType)
|
||||
{
|
||||
var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
|
||||
var priceAttribute = fieldInfo?.GetCustomAttribute<PriceAttribute>();
|
||||
return priceAttribute?.ReferencePrice ?? 0m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品类别
|
||||
/// </summary>
|
||||
@@ -190,7 +210,7 @@ public static class GoodsTypeEnumExtensions
|
||||
{
|
||||
var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
|
||||
var categoryAttribute = fieldInfo?.GetCustomAttribute<GoodsCategoryAttribute>();
|
||||
return categoryAttribute?.Category ?? GoodsCategoryType.VipService;
|
||||
return categoryAttribute?.Category ?? GoodsCategoryType.Vip;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -210,7 +230,7 @@ public static class GoodsTypeEnumExtensions
|
||||
/// <returns>是否为VIP服务</returns>
|
||||
public static bool IsVipService(this GoodsTypeEnum goodsType)
|
||||
{
|
||||
return goodsType.GetGoodsCategory() == GoodsCategoryType.VipService;
|
||||
return goodsType.GetGoodsCategory() == GoodsCategoryType.Vip;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -225,6 +245,30 @@ public static class GoodsTypeEnumExtensions
|
||||
return tokenAttribute?.TokenAmount ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品中文名称
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <returns>中文名称</returns>
|
||||
public static string GetChineseName(this GoodsTypeEnum goodsType)
|
||||
{
|
||||
var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
|
||||
var displayNameAttribute = fieldInfo?.GetCustomAttribute<DisplayNameAttribute>();
|
||||
return displayNameAttribute?.ChineseName ?? goodsType.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品备注
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <returns>备注信息</returns>
|
||||
public static string GetRemark(this GoodsTypeEnum goodsType)
|
||||
{
|
||||
var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
|
||||
var displayNameAttribute = fieldInfo?.GetCustomAttribute<DisplayNameAttribute>();
|
||||
return displayNameAttribute?.Remark ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算折扣金额(仅用于尊享包)
|
||||
/// 规则:每累加充值10元,减少2.5元,最多减少50元
|
||||
|
||||
Reference in New Issue
Block a user