sunpengfei
9 天以前 11e0c46d96a9de0c77cbc7509d34f470823bbc65
FlexJobApi.UserServer.Application/EnterpriseWallets/Queries/EnterpriseWalletQueryHandler.cs
@@ -17,11 +17,13 @@
    /// </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>
@@ -30,13 +32,24 @@
        /// <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.Access == EnumEnterpriseWalletAccess.Alipay)
            {
            if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Apply)
            {
                var response = alipayUtils.UserAgreementQuery(new Aop.Api.Domain.AlipayUserAgreementQueryModel
@@ -64,8 +77,37 @@
                entity.PrincipalOpenId = response.PrincipalOpenId;
                entity.ZmOpenId = response.ZmOpenId;
                entity.CreditAuthMode = response.CreditAuthMode;
                await rep.UpdateAsync(entity);
                    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;
        }