feat: 支持尊享包渠道

This commit is contained in:
ccnetcore
2025-12-31 00:02:25 +08:00
committed by Gsh
parent e4621d9049
commit 33d28a8cb0
28 changed files with 1666 additions and 34 deletions

View File

@@ -109,7 +109,7 @@ public class AiChatService : ApplicationService
ApiHost = null,
ApiKey = null,
Remark = x.Description,
IsPremiumPackage = PremiumPackageConst.ModeIds.Contains(x.ModelId)
IsPremiumPackage = x.IsPremium
}).ToListAsync();
return output;
}
@@ -144,13 +144,21 @@ public class AiChatService : ApplicationService
}
//如果是尊享包服务,需要校验是是否尊享包足够
if (CurrentUser.IsAuthenticated && PremiumPackageConst.ModeIds.Contains(input.Model))
if (CurrentUser.IsAuthenticated)
{
// 检查尊享token包用量
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(CurrentUser.GetId());
if (availableTokens <= 0)
var isPremium = await _aiModelRepository._DbQueryable
.Where(x => x.ModelId == input.Model)
.Select(x => x.IsPremium)
.FirstAsync();
if (isPremium)
{
throw new UserFriendlyException("尊享token包用量不足请先购买尊享token包");
// 检查尊享token包用量
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(CurrentUser.GetId());
if (availableTokens <= 0)
{
throw new UserFriendlyException("尊享token包用量不足请先购买尊享token包");
}
}
}
@@ -219,7 +227,12 @@ public class AiChatService : ApplicationService
}
//如果是尊享包服务,需要校验是是否尊享包足够
if (PremiumPackageConst.ModeIds.Contains(input.ModelId))
var isPremium = await _aiModelRepository._DbQueryable
.Where(x => x.ModelId == input.ModelId)
.Select(x => x.IsPremium)
.FirstAsync();
if (isPremium)
{
// 检查尊享token包用量
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(tokenValidation.UserId);

View File

@@ -69,6 +69,9 @@ public class AiImageService : ApplicationService
}
// 尊享包校验
// 注意: AiImageService目前没有注入AiModelEntity仓储
// 由于图片生成功能使用频率较低,且当前所有图片模型都不是尊享模型
// 暂时保留原逻辑,等待后续重构时再注入仓储
if (PremiumPackageConst.ModeIds.Contains(input.ModelId))
{
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(userId);

View File

@@ -41,8 +41,7 @@ public class ModelService : ApplicationService, IModelService
input.ModelTypes.Contains(x.ModelType))
.WhereIF(input.ModelApiTypes is not null, x =>
input.ModelApiTypes.Contains(x.ModelApiType))
.WhereIF(input.IsPremiumOnly == true, x =>
PremiumPackageConst.ModeIds.Contains(x.ModelId))
.WhereIF(input.IsPremiumOnly == true, x => x.IsPremium)
.GroupBy(x => x.ModelId)
.Select(x => x.ModelId)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total));
@@ -61,7 +60,7 @@ public class ModelService : ApplicationService, IModelService
MultiplierShow = x.First().MultiplierShow,
ProviderName = x.First().ProviderName,
IconUrl = x.First().IconUrl,
IsPremium = PremiumPackageConst.ModeIds.Contains(x.First().ModelId),
IsPremium = x.First().IsPremium,
OrderNum = x.First().OrderNum
}).ToList();

View File

@@ -52,7 +52,10 @@ public class TokenService : ApplicationService
}
// 获取尊享包模型ID列表
var premiumModelIds = PremiumPackageConst.ModeIds;
var premiumModelIds = await _aiModelRepository._DbQueryable
.Where(x => x.IsPremium)
.Select(x => x.ModelId)
.ToListAsync();
// 批量查询所有Token的尊享包已使用额度
var tokenIds = tokens.Select(t => t.Id).ToList();