zhengyuxuan
2025-03-28 d6ffbd97603decf4d3922a697414f4f7cec30434
LifePayment/LifePayment.Application/User/AccountService.cs
@@ -5,6 +5,7 @@
using LifePayment.Domain.Shared;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -16,6 +17,7 @@
using Volo.Abp.Identity;
using Volo.Abp.Identity.Application.Contracts.Account;
using Volo.Abp.IdentityModel;
using Volo.Abp.Threading;
using ZeroD.Util;
using ZeroD.Util.Fadd;
using static LifePayment.Domain.Shared.LifePaymentConstant;
@@ -27,6 +29,7 @@
    {
        private readonly IWxManager _wxManager;
        private readonly IRepository<LifePayUser, Guid> _lifePayUserRepository;
        private readonly IRepository<LifePayChannles, Guid> _lifePayChannlesRepository;
        private readonly IConfiguration _configuration;
        private readonly IIdentityModelAuthenticationService _authenticator;
        private readonly IRepository<User, Guid> _userRepository;
@@ -42,6 +45,7 @@
               IRepository<User, Guid> userRepository,
               IIdentityUserAppService identityUserService,
               IRepository<LifePayUser, Guid> lifePayUserRepository,
               IRepository<LifePayChannles, Guid> lifePayChannlesRepository,
               IRepository<UserChannle, Guid> userChannleRep,
               IDistributedCache<string> distributedCache)
        {
@@ -49,6 +53,7 @@
            _wxManager = wxManager;
            _identityUserService = identityUserService;
            _lifePayUserRepository = lifePayUserRepository;
            _lifePayChannlesRepository = lifePayChannlesRepository;
            _authenticator = authenticator;
            _userRepository = userRepository;
            _userChannleRep = userChannleRep;
@@ -78,7 +83,7 @@
                {
                    await _distributedCache.SetAsync(code, res.OpenId, options: new Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions()
                    {
                        AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
                        AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(24)
                    });
                }
@@ -103,17 +108,8 @@
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="UserFriendlyException"></exception>
        public async Task<Guid> LifePayPhoneMesssageCodeLogin(LifePayPhoneMesssageCodeLoginInput input)
        public async Task<LifePayPhoneMesssageCodeLoginOutput> LifePayPhoneMesssageCodeLogin(LifePayPhoneMesssageCodeLoginInput input)
        {
            //var vcodeType = VerificationCodeBusinessTypeEnum.LifePayPhoneMesssageCodeLogin;
            //var checkResult = await _verificationCodeManager.CheckVerificationCodeByBusinessType(vcodeType,
            //                                                                                     input.PhoneNumber,
            //                                                                                     input.Code,
            //                                                                                     true);
            //CheckExtensions.IfTrueThrowUserFriendlyException(!checkResult,
            //                                                 CustomeErrorMessage.SometingWrongOrSometing, "验证码", "已失效");
            var lifeUser = await _lifePayUserRepository.Where(x => x.PhoneNumber == input.PhoneNumber).FirstOrDefaultAsync();
            if (lifeUser == null)
            {
@@ -134,7 +130,56 @@
                await _lifePayUserRepository.UpdateAsync(lifeUser);
            }
            return lifeUser.Id;
            List<ChannelOutput> channlesNum = new List<ChannelOutput>();
            var backClientUser = await _userRepository.Where(x => x.ClientId == Constant.ClientType.Back
            && x.PhoneNumber == input.PhoneNumber).FirstOrDefaultAsync();
            if (backClientUser != null)
            {
                channlesNum = await _userChannleRep.Where(x => x.UserId == backClientUser.Id)
                     .Select(s => new ChannelOutput()
                     {
                         Name = _lifePayChannlesRepository.Where(x => x.ChannlesNum == s.ChannleId).Select(r => r.ChannlesName).FirstOrDefault(),
                         ChannlesNum = s.ChannleId
                     }).ToListAsync();
            }
            var result = await LifePayUserMesssageByPhone(lifeUser.PhoneNumber);
            result.UserId = lifeUser.Id;
            return result;
        }
        public async Task<LifePayPhoneMesssageCodeLoginOutput> LifePayUserMesssageByIduser(Guid id)
        {
            var lifeUser = await _lifePayUserRepository.Where(x => x.Id == id).FirstOrDefaultAsync();
            CheckExtensions.IfTrueThrowUserFriendlyException(lifeUser == null,
                                                             "用户不存在");
            var result = await LifePayUserMesssageByPhone(lifeUser.PhoneNumber);
            result.UserId = id;
            return result;
        }
        public async Task<LifePayPhoneMesssageCodeLoginOutput> LifePayUserMesssageByPhone(string phoneNumber)
        {
            List<ChannelOutput> channlesNum = new List<ChannelOutput>();
            var backClientUser = await _userRepository.Where(x => x.ClientId == Constant.ClientType.Back
             && x.PhoneNumber == phoneNumber).FirstOrDefaultAsync();
            if (backClientUser != null)
            {
                channlesNum = await _userChannleRep.Where(x => x.UserId == backClientUser.Id)
                    .Select(s => new ChannelOutput()
                    {
                        Name = _lifePayChannlesRepository.Where(x => x.ChannlesNum == s.ChannleId).Select(r => r.ChannlesName).FirstOrDefault(),
                        ChannlesNum = s.ChannleId
                    }).ToListAsync();
            }
            LifePayPhoneMesssageCodeLoginOutput result = new LifePayPhoneMesssageCodeLoginOutput()
            {
                IsBackClientUser = backClientUser == null ? false : true,
                ChannlesNum = channlesNum
            };
            return result;
        }
        public async Task<IdentityModelTokenCacheItem> GetTokenForWeb(AccessRequestDto accessRequestDto, string webClientIp)
@@ -160,11 +205,11 @@
        public async Task<Guid> CreateAccount(CreateAccountInput input, bool isSend, bool isAdminCreate = false)
        {
            if (input.ClientId == LifePaymentConstant.ClientId.Back)
            {
                CheckExtensions.IfTrueThrowUserFriendlyException(!input.CompanyOrgId.HasValue || !input.DepartmentOrgId.HasValue,
                                                                 "所属公司和部门不能为空");
            }
            //if (input.ClientId == LifePaymentConstant.ClientId.Back)
            //{
            //    CheckExtensions.IfTrueThrowUserFriendlyException(!input.CompanyOrgId.HasValue || !input.DepartmentOrgId.HasValue,
            //                                                     "所属公司和部门不能为空");
            //}
            var any = await _userRepository.Where(x => x.PhoneNumber == input.PhoneNumber && x.ClientId == input.ClientId).AnyAsync();
            CheckExtensions.IfTrueThrowUserFriendlyException(any,