feat: 支付完成后自动为用户充值VIP并支持按商品类型计算有效期
This commit is contained in:
@@ -10,10 +10,12 @@ namespace Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
public class PriceAttribute : Attribute
|
||||
{
|
||||
public decimal Price { get; }
|
||||
public int ValidMonths { get; }
|
||||
|
||||
public PriceAttribute(double price)
|
||||
public PriceAttribute(double price, int validMonths)
|
||||
{
|
||||
Price = (decimal)price;
|
||||
ValidMonths = validMonths;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,23 +38,23 @@ public class DisplayNameAttribute : Attribute
|
||||
/// </summary>
|
||||
public enum GoodsTypeEnum
|
||||
{
|
||||
[Price(0.01)]
|
||||
[Price(0.01, 1)]
|
||||
[DisplayName("YiXinVip Test")]
|
||||
YiXinVipTest = 0,
|
||||
|
||||
[Price(29.9)]
|
||||
[Price(29.9, 1)]
|
||||
[DisplayName("YiXinVip 1 month")]
|
||||
YiXinVip1 = 1,
|
||||
|
||||
[Price(80.7)]
|
||||
[Price(80.7, 3)]
|
||||
[DisplayName("YiXinVip 3 month")]
|
||||
YiXinVip3 = 3,
|
||||
|
||||
[Price(143.9)]
|
||||
[Price(143.9, 6)]
|
||||
[DisplayName("YiXinVip 6 month")]
|
||||
YiXinVip6 = 6,
|
||||
|
||||
[Price(199.9)]
|
||||
[Price(199.9, 10)]
|
||||
[DisplayName("YiXinVip 10 month")]
|
||||
YiXinVip10 = 10
|
||||
}
|
||||
@@ -93,4 +95,28 @@ public static class GoodsTypeEnumExtensions
|
||||
var displayNameAttribute = fieldInfo?.GetCustomAttribute<DisplayNameAttribute>();
|
||||
return displayNameAttribute?.DisplayName ?? goodsType.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品有效月份
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <returns>有效月份</returns>
|
||||
public static int GetValidMonths(this GoodsTypeEnum goodsType)
|
||||
{
|
||||
var fieldInfo = goodsType.GetType().GetField(goodsType.ToString());
|
||||
var priceAttribute = fieldInfo?.GetCustomAttribute<PriceAttribute>();
|
||||
return priceAttribute?.ValidMonths ?? 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品月均价格
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <returns>月均价格</returns>
|
||||
public static decimal GetMonthlyPrice(this GoodsTypeEnum goodsType)
|
||||
{
|
||||
var totalPrice = goodsType.GetTotalAmount();
|
||||
var validMonths = goodsType.GetValidMonths();
|
||||
return validMonths > 0 ? totalPrice / validMonths : 0m;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user