feat: 增加尊享包商品及折扣逻辑,完善VIP与尊享包相关接口和数据返回
- 新增尊享包商品类型,支持 5000W 和 10000W Tokens - 增加尊享包折扣计算与折扣后价格获取方法 - PayService 新增获取商品列表接口,支持尊享包折扣展示 - PayManager 支持尊享包订单金额按折扣计算,并新增获取用户累计充值金额方法 - OpenApiService Anthropic接口增加VIP与尊享包用量校验 - AiGateWayManager 增加尊享包Token扣减逻辑 - AiAccountService 返回用户VIP状态、到期时间及尊享包Token统计信息
This commit is contained in:
@@ -106,53 +106,18 @@ public enum GoodsTypeEnum
|
||||
YiXinVip8 = 8,
|
||||
|
||||
// 尊享包服务 - 需要VIP资格才能购买
|
||||
[Price(49.9, 0)]
|
||||
[DisplayName("Premium Package 5M Tokens")]
|
||||
[Price(188.9, 0)]
|
||||
[DisplayName("Premium Package 5000W Tokens")]
|
||||
[GoodsCategory(GoodsCategoryType.PremiumPackage)]
|
||||
[TokenAmount(5_000_000)]
|
||||
PremiumPackage5M = 101,
|
||||
[TokenAmount(5000)]
|
||||
PremiumPackage5000W = 101,
|
||||
|
||||
[Price(99.9, 0)]
|
||||
[DisplayName("Premium Package 10M Tokens")]
|
||||
[Price(248.9, 0)]
|
||||
[DisplayName("Premium Package 10000W Tokens")]
|
||||
[GoodsCategory(GoodsCategoryType.PremiumPackage)]
|
||||
[TokenAmount(10_000_000)]
|
||||
PremiumPackage10M = 102,
|
||||
|
||||
[Price(199.9, 0)]
|
||||
[DisplayName("Premium Package 25M Tokens")]
|
||||
[GoodsCategory(GoodsCategoryType.PremiumPackage)]
|
||||
[TokenAmount(25_000_000)]
|
||||
PremiumPackage25M = 103,
|
||||
|
||||
[Price(399.9, 0)]
|
||||
[DisplayName("Premium Package 50M Tokens")]
|
||||
[GoodsCategory(GoodsCategoryType.PremiumPackage)]
|
||||
[TokenAmount(50_000_000)]
|
||||
PremiumPackage50M = 104
|
||||
|
||||
// [Price(197.1, 9)]
|
||||
// [DisplayName("YiXinVip 9 month")]
|
||||
// YiXinVip9 = 9
|
||||
|
||||
// [Price(0.01, 1)]
|
||||
// [DisplayName("YiXinVip Test")]
|
||||
// YiXinVipTest = 0,
|
||||
//
|
||||
// [Price(0.01, 1)]
|
||||
// [DisplayName("YiXinVip 1 month")]
|
||||
// YiXinVip1 = 1,
|
||||
//
|
||||
// [Price(0.01, 3)]
|
||||
// [DisplayName("YiXinVip 3 month")]
|
||||
// YiXinVip3 = 3,
|
||||
//
|
||||
// [Price(0.01, 6)]
|
||||
// [DisplayName("YiXinVip 6 month")]
|
||||
// YiXinVip6 = 6,
|
||||
//
|
||||
// [Price(0.01, 10)]
|
||||
// [DisplayName("YiXinVip 10 month")]
|
||||
// YiXinVip10 = 10
|
||||
[TokenAmount(10000)]
|
||||
PremiumPackage10000W = 102,
|
||||
|
||||
}
|
||||
|
||||
public static class GoodsTypeEnumExtensions
|
||||
@@ -259,4 +224,42 @@ public static class GoodsTypeEnumExtensions
|
||||
var tokenAttribute = fieldInfo?.GetCustomAttribute<TokenAmountAttribute>();
|
||||
return tokenAttribute?.TokenAmount ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算折扣金额(仅用于尊享包)
|
||||
/// 规则:每累加充值10元,减少1元,最多减少20元
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <param name="totalRechargeAmount">用户累加充值金额</param>
|
||||
/// <returns>折扣金额</returns>
|
||||
public static decimal CalculateDiscount(this GoodsTypeEnum goodsType, decimal totalRechargeAmount)
|
||||
{
|
||||
// 只有尊享包才有折扣
|
||||
if (!goodsType.IsPremiumPackage())
|
||||
{
|
||||
return 0m;
|
||||
}
|
||||
|
||||
// 每10元减1元
|
||||
var discountAmount = Math.Floor(totalRechargeAmount / 10m);
|
||||
|
||||
// 最多减少20元
|
||||
return Math.Min(discountAmount, 20m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取折扣后的价格(仅用于尊享包)
|
||||
/// </summary>
|
||||
/// <param name="goodsType">商品类型</param>
|
||||
/// <param name="totalRechargeAmount">用户累加充值金额</param>
|
||||
/// <returns>折扣后的价格</returns>
|
||||
public static decimal GetDiscountedPrice(this GoodsTypeEnum goodsType, decimal totalRechargeAmount)
|
||||
{
|
||||
var originalPrice = goodsType.GetTotalAmount();
|
||||
var discount = goodsType.CalculateDiscount(totalRechargeAmount);
|
||||
var discountedPrice = originalPrice - discount;
|
||||
|
||||
// 确保价格不为负数,至少为0.01元
|
||||
return Math.Max(discountedPrice, 0.01m);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user