From 877a696655516acaa1ee19ecbc8d050394c26c2b Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期四, 27 三月 2025 17:31:52 +0800
Subject: [PATCH] fix:新增接口

---
 LifePayment/LifePayment.Application/User/AccountService.cs |  131 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 104 insertions(+), 27 deletions(-)

diff --git a/LifePayment/LifePayment.Application/User/AccountService.cs b/LifePayment/LifePayment.Application/User/AccountService.cs
index 96b3ae8..ac9b944 100644
--- a/LifePayment/LifePayment.Application/User/AccountService.cs
+++ b/LifePayment/LifePayment.Application/User/AccountService.cs
@@ -6,15 +6,19 @@
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using Volo.Abp;
 using Volo.Abp.Application.Services;
+using Volo.Abp.Caching;
 using Volo.Abp.Domain.Repositories;
 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,7 +31,10 @@
         private readonly IConfiguration _configuration;
         private readonly IIdentityModelAuthenticationService _authenticator;
         private readonly IRepository<User, Guid> _userRepository;
+        private readonly IRepository<UserChannle, Guid> _userChannleRep;
         private readonly IIdentityUserAppService _identityUserService;
+        private readonly IDistributedCache<string> _distributedCache;
+
 
         public AccountService(
                IWxManager wxManager,
@@ -35,7 +42,9 @@
                IIdentityModelAuthenticationService authenticator,
                IRepository<User, Guid> userRepository,
                IIdentityUserAppService identityUserService,
-               IRepository<LifePayUser, Guid> lifePayUserRepository)
+               IRepository<LifePayUser, Guid> lifePayUserRepository,
+               IRepository<UserChannle, Guid> userChannleRep,
+               IDistributedCache<string> distributedCache)
         {
             _configuration = configuration;
             _wxManager = wxManager;
@@ -43,19 +52,39 @@
             _lifePayUserRepository = lifePayUserRepository;
             _authenticator = authenticator;
             _userRepository = userRepository;
+            _userChannleRep = userChannleRep;
+            _distributedCache = distributedCache;
         }
 
         #region 鏌ヨ
 
         public async Task<WxMiniAppIndentityInfo> GetLifePayWxIndentity(string code)
         {
-            var res = await _wxManager.GetWxOauth2AccessToken(code);
-            var result = new WxMiniAppIndentityInfo
+            var cacheData = await _distributedCache.GetAsync(code);
+            var result = new WxMiniAppIndentityInfo();
+            if (cacheData != null)
             {
-                SessionKey = res.SessionKey,
-                OpenId = res.OpenId,
-                UnionId = res.UnionId
-            };
+                result.OpenId = cacheData;
+            }
+            else
+            {
+                var res = await _wxManager.GetWxOauth2AccessToken(code);
+                result = new WxMiniAppIndentityInfo
+                {
+                    SessionKey = res.SessionKey,
+                    OpenId = res.OpenId,
+                    UnionId = res.UnionId
+                };
+                if (!string.IsNullOrEmpty(res.OpenId))
+                {
+                    await _distributedCache.SetAsync(code, res.OpenId, options: new Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions()
+                    {
+                        AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(24)
+                    });
+                }
+
+            }
+
 
             return result;
         }
@@ -75,23 +104,16 @@
         /// <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, "楠岃瘉鐮�", "宸插け鏁�");
-
+            string[] channlesNum = new string[0];
             var lifeUser = await _lifePayUserRepository.Where(x => x.PhoneNumber == input.PhoneNumber).FirstOrDefaultAsync();
             if (lifeUser == null)
             {
                 lifeUser = new LifePayUser()
                 {
                     Id = GuidGenerator.Create(),
+                    CreationChannleNum = input.CheckChannelId,
                     PhoneNumber = input.PhoneNumber,
                     LastLoginTime = DateTime.Now
                 };
@@ -100,12 +122,52 @@
             }
             else
             {
+                lifeUser.LastLoginChannleNum = input.CheckChannelId;
                 lifeUser.LastLoginTime = DateTime.Now;
                 await _lifePayUserRepository.UpdateAsync(lifeUser);
             }
+            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 => s.ChannleId).ToArrayAsync();
+            }
 
-            return lifeUser.Id;
+            LifePayPhoneMesssageCodeLoginOutput result = new LifePayPhoneMesssageCodeLoginOutput()
+            {
+                UserId = lifeUser.Id,
+                IsBackClientUser = backClientUser == null ? false : true,
+                ChannlesNum = channlesNum
+            };
+
+
+            return result;
         }
+
+        public async Task<LifePayPhoneMesssageCodeLoginOutput> LifePayUserMesssageByIduser(Guid id)
+        {
+            string[] channlesNum = new string[0];
+            var lifeUser = await _lifePayUserRepository.Where(x => x.Id == id).FirstOrDefaultAsync();
+            CheckExtensions.IfTrueThrowUserFriendlyException(lifeUser == null,
+                                                             "鐢ㄦ埛涓嶅瓨鍦�");
+            var backClientUser = await _userRepository.Where(x => x.ClientId == Constant.ClientType.Back
+             && x.PhoneNumber == lifeUser.PhoneNumber).FirstOrDefaultAsync();
+            if (backClientUser != null)
+            {
+                channlesNum = await _userChannleRep.Where(x => x.UserId == backClientUser.Id).Select(s => s.ChannleId).ToArrayAsync();
+            }
+
+            LifePayPhoneMesssageCodeLoginOutput result = new LifePayPhoneMesssageCodeLoginOutput()
+            {
+                UserId = id,
+                IsBackClientUser = backClientUser == null ? false : true,
+                ChannlesNum = channlesNum
+            };
+
+
+            return result; 
+        }
+
 
         public async Task<IdentityModelTokenCacheItem> GetTokenForWeb(AccessRequestDto accessRequestDto, string webClientIp)
         {
@@ -123,25 +185,27 @@
             var user = await _userRepository.Where(r => r.UserName == accessRequestDto.UserName && !r.IsDeleted).FirstOrDefaultAsync();
 
             // 璁板綍鏃ュ織
-           // await PublishUserOperateHistoryEvent(LogsSpecies.Login, LogsSpecies.Login, user.Id, user.Id, creatorName: user.Name);
+            // await PublishUserOperateHistoryEvent(LogsSpecies.Login, LogsSpecies.Login, user.Id, user.Id, creatorName: user.Name);
 
             return result;
         }
 
-        public async Task<Guid> CreateAccount(CreateAccountInput input, bool isSend, bool isAdminCreate = false, string password = null)
+        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,
                                                              CustomeErrorMessage.PhoneNumberRepeatSaveFail);
 
-            password ??= GlobalRandom.GetRandomPassword();
+            /// input.Password ??= GlobalRandom.GetRandomPassword();
 
+            CheckExtensions.IfTrueThrowUserFriendlyException(string.IsNullOrEmpty(input.Password),
+                                                             "璇疯緭鍏ュ瘑鐮�");
             var res = await _identityUserService.CreateAsync(new IdentityUserCreateDto
             {
                 Name = input.Name,
@@ -149,7 +213,7 @@
                 UserName = input.UserName,
                 RoleNames = input.RoleNames,
                 ClientId = input.ClientId,
-                Password = password,
+                Password = input.Password,
             });
             var user = await _userRepository.InsertAsync(new User
             {
@@ -168,6 +232,19 @@
                 DepartmentOrgId = input.ClientId == LifePaymentConstant.ClientId.Back ? input.DepartmentOrgId : null,
                 CompanyOrgId = input.ClientId == LifePaymentConstant.ClientId.Back ? input.CompanyOrgId : null
             });
+
+            List<UserChannle> userChannles = new List<UserChannle>();
+            foreach (var item in input.ChannlesId)
+            {
+                userChannles.Add(new UserChannle()
+                {
+                    Id = Guid.NewGuid(),
+                    ChannleId = item,
+                    UserId = user.Id
+                });
+            }
+
+            await _userChannleRep.InsertManyAsync(userChannles);
             //if (input.ClientId == Constant.ClientType.Back)
             //{
             //    await _distributedEventBus.PublishAsync(new SendPhoneMessageInput

--
Gitblit v1.9.1