2025-08-30 17:55:13 +08:00
|
|
|
|
using Mapster;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2025-12-25 18:01:13 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Text;
|
2025-08-30 17:55:13 +08:00
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
|
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities;
|
2025-12-25 18:01:13 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
2025-08-30 17:55:13 +08:00
|
|
|
|
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
|
|
|
|
|
using Yi.Framework.Rbac.Domain.Shared.Dtos;
|
|
|
|
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
2025-10-12 20:07:58 +08:00
|
|
|
|
using Yi.Framework.AiHub.Domain.Extensions;
|
2025-08-30 17:55:13 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.AiHub.Application.Services;
|
|
|
|
|
|
|
|
|
|
|
|
public class AiAccountService : ApplicationService
|
|
|
|
|
|
{
|
|
|
|
|
|
private IAccountService _accountService;
|
|
|
|
|
|
private ISqlSugarRepository<AiUserExtraInfoEntity> _userRepository;
|
2025-10-12 20:07:58 +08:00
|
|
|
|
private ISqlSugarRepository<AiRechargeAggregateRoot> _rechargeRepository;
|
2025-10-30 14:38:58 +08:00
|
|
|
|
private ISqlSugarRepository<PremiumPackageAggregateRoot> _premiumPackageRepository;
|
2025-12-25 18:01:13 +08:00
|
|
|
|
private ISqlSugarRepository<MessageAggregateRoot> _messageRepository;
|
2025-10-12 20:07:58 +08:00
|
|
|
|
public AiAccountService(
|
|
|
|
|
|
IAccountService accountService,
|
|
|
|
|
|
ISqlSugarRepository<AiUserExtraInfoEntity> userRepository,
|
2025-10-30 14:38:58 +08:00
|
|
|
|
ISqlSugarRepository<AiRechargeAggregateRoot> rechargeRepository,
|
2025-12-25 18:01:13 +08:00
|
|
|
|
ISqlSugarRepository<PremiumPackageAggregateRoot> premiumPackageRepository, ISqlSugarRepository<MessageAggregateRoot> messageRepository)
|
2025-08-30 17:55:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
_accountService = accountService;
|
|
|
|
|
|
_userRepository = userRepository;
|
2025-10-12 20:07:58 +08:00
|
|
|
|
_rechargeRepository = rechargeRepository;
|
2025-10-30 14:38:58 +08:00
|
|
|
|
_premiumPackageRepository = premiumPackageRepository;
|
2025-12-25 18:01:13 +08:00
|
|
|
|
_messageRepository = messageRepository;
|
2025-08-30 17:55:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取ai用户信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
[HttpGet("account/ai")]
|
|
|
|
|
|
public async Task<AiUserRoleMenuDto> GetAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var userId = CurrentUser.GetId();
|
|
|
|
|
|
var userAccount = await _accountService.GetAsync(null, null, userId: CurrentUser.GetId());
|
|
|
|
|
|
var output = userAccount.Adapt<AiUserRoleMenuDto>();
|
2025-10-12 20:07:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 是否绑定服务号
|
2025-08-30 17:55:13 +08:00
|
|
|
|
output.IsBindFuwuhao = await _userRepository.IsAnyAsync(x => userId == x.UserId);
|
2025-10-12 20:07:58 +08:00
|
|
|
|
|
|
|
|
|
|
// 是否为VIP用户
|
|
|
|
|
|
output.IsVip = CurrentUser.IsAiVip();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取VIP到期时间
|
|
|
|
|
|
if (output.IsVip)
|
|
|
|
|
|
{
|
|
|
|
|
|
var recharges = await _rechargeRepository._DbQueryable
|
|
|
|
|
|
.Where(x => x.UserId == userId)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (recharges.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果有任何一个充值记录的过期时间为null,说明是永久VIP
|
|
|
|
|
|
if (recharges.Any(x => !x.ExpireDateTime.HasValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
output.VipExpireTime = null; // 永久VIP
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 取最大的过期时间
|
|
|
|
|
|
output.VipExpireTime = recharges
|
|
|
|
|
|
.Where(x => x.ExpireDateTime.HasValue)
|
|
|
|
|
|
.Max(x => x.ExpireDateTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-30 17:55:13 +08:00
|
|
|
|
return output;
|
|
|
|
|
|
}
|
2025-10-30 14:38:58 +08:00
|
|
|
|
|
2025-12-25 18:01:13 +08:00
|
|
|
|
}
|