From e2d2994059dc80b71f0a216c5a959032ea73a439 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期四, 04 九月 2025 13:13:35 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.UserServer.Application/EnterpriseWallets/Queries/EnterpriseWalletQueryHandler.cs | 123 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 109 insertions(+), 14 deletions(-) diff --git a/FlexJobApi.UserServer.Application/EnterpriseWallets/Queries/EnterpriseWalletQueryHandler.cs b/FlexJobApi.UserServer.Application/EnterpriseWallets/Queries/EnterpriseWalletQueryHandler.cs index 5289323..aacd13c 100644 --- a/FlexJobApi.UserServer.Application/EnterpriseWallets/Queries/EnterpriseWalletQueryHandler.cs +++ b/FlexJobApi.UserServer.Application/EnterpriseWallets/Queries/EnterpriseWalletQueryHandler.cs @@ -1,9 +1,12 @@ -锘縰sing FlexJobApi.Core; +锘縰sing Aop.Api.Domain; +using Azure; +using FlexJobApi.Core; using Furion.DatabaseAccessor; using Furion.FriendlyException; using Mapster; using MediatR; using Microsoft.EntityFrameworkCore; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; @@ -17,12 +20,15 @@ /// </summary> public class EnterpriseWalletQueryHandler( IRepository<EnterpriseWallet> rep, + IRepository<EnterpriseWalletTransaction> repEnterpriseWalletTransaction, IRepository<Enterprise> repEnterprise, AlipayUtils alipayUtils ) : - IRequestHandler<GetEnterpriseWalletQuery, GetEnterpriseWalletQueryResult> + IRequestHandler<GetEnterpriseWalletQuery, GetEnterpriseWalletQueryResult>, + IRequestHandler<GetEnterpriseWalletTransactionQuery, GetEnterpriseWalletTransactionQueryResult> { private readonly IRepository<EnterpriseWallet> rep = rep; + private readonly IRepository<EnterpriseWalletTransaction> repEnterpriseWalletTransaction = repEnterpriseWalletTransaction; private readonly IRepository<Enterprise> repEnterprise = repEnterprise; private readonly AlipayUtils alipayUtils = alipayUtils; @@ -48,6 +54,7 @@ .Where(it => it.EnterpriseId == request.EnterpriseId && it.Access == request.Access) .FirstOrDefaultAsync(); if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "浼佷笟閽卞寘"); + var update = false; if (entity.Access == EnumEnterpriseWalletAccess.Alipay) { if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Apply) @@ -77,12 +84,12 @@ entity.PrincipalOpenId = response.PrincipalOpenId; entity.ZmOpenId = response.ZmOpenId; entity.CreditAuthMode = response.CreditAuthMode; - await rep.UpdateNowAsync(entity); + update = true; } if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Normal && entity.AccountBookStatus != EnumEnterpriseWalletAccountBookStatus.Normal) { - var accountBookResponse = alipayUtils.FundAccountbookCreate(new Aop.Api.Domain.AlipayFundAccountbookCreateModel + var response = alipayUtils.FundAccountbookCreate(new Aop.Api.Domain.AlipayFundAccountbookCreateModel { MerchantUserId = entity.Code, MerchantUserType = "BUSINESS_ORGANIZATION", @@ -93,23 +100,111 @@ cert_no = enterprise.SocietyCreditCode }.ToJson() }); - if (accountBookResponse.IsError) throw Oops.Oh(EnumErrorCodeType.s510, accountBookResponse.SubMsg ?? accountBookResponse.Msg); - entity.AccountBookId = accountBookResponse.AccountBookId; - entity.BankAccName = accountBookResponse.ExtCardInfo.BankAccName; - entity.CardBank = accountBookResponse.ExtCardInfo.CardBank; - entity.CardBranch = accountBookResponse.ExtCardInfo.CardBranch; - entity.CardDeposit = accountBookResponse.ExtCardInfo.CardDeposit; - entity.CardLocation = accountBookResponse.ExtCardInfo.CardLocation; - entity.CardNo = accountBookResponse.ExtCardInfo.CardNo; - entity.AccountBookStatus = accountBookResponse.ExtCardInfo.Status == "A" + if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.SubMsg ?? response.Msg); + entity.AccountBookId = response.AccountBookId; + entity.BankAccName = response.ExtCardInfo.BankAccName; + entity.CardBank = response.ExtCardInfo.CardBank; + entity.CardBranch = response.ExtCardInfo.CardBranch; + entity.CardDeposit = response.ExtCardInfo.CardDeposit; + entity.CardLocation = response.ExtCardInfo.CardLocation; + entity.CardNo = response.ExtCardInfo.CardNo; + entity.AccountBookStatus = response.ExtCardInfo.Status == "A" ? EnumEnterpriseWalletAccountBookStatus.Normal : EnumEnterpriseWalletAccountBookStatus.Exception; - await rep.UpdateNowAsync(entity); + update = true; } + + if (entity.AccountBookStatus == EnumEnterpriseWalletAccountBookStatus.Normal) + { + var response = alipayUtils.FundAccountbookQuery(new AlipayFundAccountbookQueryModel + { + AccountBookId = entity.AccountBookId, + SceneCode = "SATF_FUND_BOOK", + MerchantUserId = entity.Code, + }); + if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.SubMsg ?? response.Msg); + entity.Balance = response.AvailableAmount.ToDecimal() ?? 0; + update = true; + } + } + + if (update) + { + await rep.UpdateNowAsync(entity); } var model = entity.Adapt<GetEnterpriseWalletQueryResult>(); return model; } + + /// <summary> + /// 鏌ヨ浼佷笟閽卞寘浜ゆ槗璇︽儏 + /// </summary> + /// <param name="request"></param> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public async Task<GetEnterpriseWalletTransactionQueryResult> Handle(GetEnterpriseWalletTransactionQuery request, CancellationToken cancellationToken) + { + var entity = await repEnterpriseWalletTransaction.AsQueryable() + .Where(it => it.Id == request.Id) + .FirstOrDefaultAsync(); + if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "浜ゆ槗"); + var response = alipayUtils.FundTransCommonQuery(new Aop.Api.Domain.AlipayFundTransCommonQueryModel + { + ProductCode = entity.ProductCode, + BizScene = entity.BizScene, + OutBizNo = entity.Code + }); + if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.SubMsg ?? response.Msg); + entity.OrderId = response.OrderId; + entity.InflowSettleSerialNo = response.InflowSettleSerialNo; + entity.SettleSerialNo = response.SettleSerialNo; + entity.ReceiverOpenId = response.ReceiverOpenId; + entity.ReceiverUserId = response.ReceiverUserId; + entity.PayFundOrderId = response.PayFundOrderId; + entity.ArrivalTimeEnd = response.ArrivalTimeEnd.ToDateTime(); + entity.OrderFee = response.OrderFee.ToDecimal(); + entity.ErrorCode = response.ErrorCode; + entity.FailReason = response.FailReason; + entity.FailInstReason = response.FailInstReason; + entity.FailInstName = response.FailInstName; + entity.FailInstErrorCode = response.FailInstErrorCode; + entity.SubStatus = response.SubStatus; + entity.TransDate = response.PayDate.ToDateTime(); + entity.Status = response.Status; + entity.TransactionStatus = response.Status == "SUCCESS" + ? EnumEnterpriseWalletTransactionStatus.Success + : response.Status == "DEALING" + ? EnumEnterpriseWalletTransactionStatus.Dealing + : response.Status == "REFUND" + ? EnumEnterpriseWalletTransactionStatus.Refund + : response.Status == "FAIL" + ? EnumEnterpriseWalletTransactionStatus.Fail + : throw Oops.Oh(EnumErrorCodeType.s510, $"鏈瘑鍒殑鐘舵�侊細{response.Status}"); + await repEnterpriseWalletTransaction.UpdateAsync(entity); + if (entity.TransactionStatus == EnumEnterpriseWalletTransactionStatus.Success) + { + await GetBalance(entity.WalletId); + } + return entity.Adapt<GetEnterpriseWalletTransactionQueryResult>(); + } + + private async Task GetBalance(Guid id) + { + var entity = await rep.AsQueryable() + .Where(it => it.Id == id) + .FirstOrDefaultAsync(); + if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "浼佷笟閽卞寘"); + var response = alipayUtils.FundAccountbookQuery(new AlipayFundAccountbookQueryModel + { + AccountBookId = entity.AccountBookId, + SceneCode = "SATF_FUND_BOOK", + MerchantUserId = entity.Code, + }); + if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.SubMsg ?? response.Msg); + entity.Balance = response.AvailableAmount.ToDecimal() ?? 0; + await rep.UpdateNowAsync(entity); + } + } } -- Gitblit v1.9.1