| | |
| | | /// </summary> |
| | | public class EnterpriseWalletQueryHandler( |
| | | IRepository<EnterpriseWallet> rep, |
| | | IRepository<Enterprise> repEnterprise, |
| | | AlipayUtils alipayUtils |
| | | ) : |
| | | IRequestHandler<GetEnterpriseWalletQuery, GetEnterpriseWalletQueryResult> |
| | | { |
| | | private readonly IRepository<EnterpriseWallet> rep = rep; |
| | | private readonly IRepository<Enterprise> repEnterprise = repEnterprise; |
| | | private readonly AlipayUtils alipayUtils = alipayUtils; |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | [UnitOfWork(false)] |
| | | public async Task<GetEnterpriseWalletQueryResult> Handle(GetEnterpriseWalletQuery request, CancellationToken cancellationToken) |
| | | { |
| | | var logier = JwtUtils.GetCurrentLogier(); |
| | | if (request.EnterpriseId == null || logier.Type == EnumUserType.Enterprise) |
| | | { |
| | | request.EnterpriseId = logier.EnterpriseId; |
| | | } |
| | | var enterprise = repEnterprise.AsQueryable().AsNoTracking() |
| | | .Where(it => it.Id == request.EnterpriseId) |
| | | .FirstOrDefault(); |
| | | if (enterprise == null) throw Oops.Oh(EnumErrorCodeType.s404, "企业"); |
| | | var entity = await rep.AsQueryable() |
| | | .Where(it => it.EnterpriseId == logier.EnterpriseId && it.Access == request.Access) |
| | | .Where(it => it.EnterpriseId == request.EnterpriseId && it.Access == request.Access) |
| | | .FirstOrDefaultAsync(); |
| | | if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "企业钱包"); |
| | | if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Apply) |
| | | if (entity.Access == EnumEnterpriseWalletAccess.Alipay) |
| | | { |
| | | var response = alipayUtils.UserAgreementQuery(new Aop.Api.Domain.AlipayUserAgreementQueryModel |
| | | if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Apply) |
| | | { |
| | | PersonalProductCode = entity.PersonalProductCode, |
| | | SignScene = entity.SignScene, |
| | | ExternalAgreementNo = entity.Code, |
| | | ThirdPartyType = entity.ThirdPartyType, |
| | | }); |
| | | if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.SubMsg ?? response.Msg); |
| | | entity.AgreementNo = response.AgreementNo; |
| | | entity.SignTime = response.SignTime.ToDateTime(); |
| | | entity.ValidTime = response.ValidTime.ToDateTime(); |
| | | entity.InvalidTime = response.InvalidTime.ToDateTime(); |
| | | entity.SignStatus = response.Status == "TEMP" |
| | | ? EnumEnterpriseWalletSignStatus.Apply |
| | | : response.Status == "NORMAL" |
| | | ? EnumEnterpriseWalletSignStatus.Normal |
| | | : response.Status == "STOP" |
| | | ? EnumEnterpriseWalletSignStatus.Stop |
| | | : throw Oops.Oh(EnumErrorCodeType.s510, "状态异常"); |
| | | entity.PricipalType = response.PricipalType; |
| | | entity.AlipayLogonId = response.AlipayLogonId; |
| | | entity.PrincipalId = response.PrincipalId; |
| | | entity.PrincipalOpenId = response.PrincipalOpenId; |
| | | entity.ZmOpenId = response.ZmOpenId; |
| | | entity.CreditAuthMode = response.CreditAuthMode; |
| | | await rep.UpdateAsync(entity); |
| | | var response = alipayUtils.UserAgreementQuery(new Aop.Api.Domain.AlipayUserAgreementQueryModel |
| | | { |
| | | PersonalProductCode = entity.PersonalProductCode, |
| | | SignScene = entity.SignScene, |
| | | ExternalAgreementNo = entity.Code, |
| | | ThirdPartyType = entity.ThirdPartyType, |
| | | }); |
| | | if (response.IsError) throw Oops.Oh(EnumErrorCodeType.s510, response.SubMsg ?? response.Msg); |
| | | entity.AgreementNo = response.AgreementNo; |
| | | entity.SignTime = response.SignTime.ToDateTime(); |
| | | entity.ValidTime = response.ValidTime.ToDateTime(); |
| | | entity.InvalidTime = response.InvalidTime.ToDateTime(); |
| | | entity.SignStatus = response.Status == "TEMP" |
| | | ? EnumEnterpriseWalletSignStatus.Apply |
| | | : response.Status == "NORMAL" |
| | | ? EnumEnterpriseWalletSignStatus.Normal |
| | | : response.Status == "STOP" |
| | | ? EnumEnterpriseWalletSignStatus.Stop |
| | | : throw Oops.Oh(EnumErrorCodeType.s510, "状态异常"); |
| | | entity.PricipalType = response.PricipalType; |
| | | entity.AlipayLogonId = response.AlipayLogonId; |
| | | entity.PrincipalId = response.PrincipalId; |
| | | entity.PrincipalOpenId = response.PrincipalOpenId; |
| | | entity.ZmOpenId = response.ZmOpenId; |
| | | entity.CreditAuthMode = response.CreditAuthMode; |
| | | await rep.UpdateNowAsync(entity); |
| | | } |
| | | |
| | | if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Normal && entity.AccountBookStatus != EnumEnterpriseWalletAccountBookStatus.Normal) |
| | | { |
| | | var accountBookResponse = alipayUtils.FundAccountbookCreate(new Aop.Api.Domain.AlipayFundAccountbookCreateModel |
| | | { |
| | | MerchantUserId = entity.Code, |
| | | MerchantUserType = "BUSINESS_ORGANIZATION", |
| | | SceneCode = "SATF_FUND_BOOK", |
| | | ExtInfo = new |
| | | { |
| | | agreement_no = entity.AgreementNo, |
| | | 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" |
| | | ? EnumEnterpriseWalletAccountBookStatus.Normal |
| | | : EnumEnterpriseWalletAccountBookStatus.Exception; |
| | | await rep.UpdateNowAsync(entity); |
| | | } |
| | | } |
| | | |
| | | var model = entity.Adapt<GetEnterpriseWalletQueryResult>(); |
| | | return model; |
| | | } |