| | |
| | | using Aop.Api.Domain; |
| | | using Furion; |
| | | using Furion.DatabaseAccessor; |
| | | using Furion.FriendlyException; |
| | | using Furion.Schedule; |
| | |
| | | [UnitOfWork(false)] |
| | | public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) |
| | | { |
| | | var entities = await rep.AsQueryable() |
| | | var env = App.GetConfig<string>("Environment"); |
| | | if (env != "Local") |
| | | { |
| | | var entities = await rep.AsQueryable() |
| | | .Include(it => it.Enterprise) |
| | | .Where(it => |
| | | it.Access == EnumEnterpriseWalletAccess.Alipay |
| | | && (it.SignStatus == EnumEnterpriseWalletSignStatus.Apply |
| | | || it.AccountBookStatus == null)) |
| | | .ToListAsync(); |
| | | foreach (var entity in entities) |
| | | { |
| | | var update = false; |
| | | if (entity.Access == EnumEnterpriseWalletAccess.Alipay) |
| | | foreach (var entity in entities) |
| | | { |
| | | if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Apply) |
| | | var update = false; |
| | | 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; |
| | | update = true; |
| | | } |
| | | |
| | | if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Normal && entity.AccountBookStatus != EnumEnterpriseWalletAccountBookStatus.Normal) |
| | | { |
| | | var response = alipayUtils.FundAccountbookCreate(new Aop.Api.Domain.AlipayFundAccountbookCreateModel |
| | | { |
| | | MerchantUserId = entity.Code, |
| | | MerchantUserType = "BUSINESS_ORGANIZATION", |
| | | SceneCode = "SATF_FUND_BOOK", |
| | | ExtInfo = new |
| | | var response = alipayUtils.UserAgreementQuery(new Aop.Api.Domain.AlipayUserAgreementQueryModel |
| | | { |
| | | agreement_no = entity.AgreementNo, |
| | | cert_no = entity.Enterprise.SocietyCreditCode |
| | | }.ToJson() |
| | | }); |
| | | 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; |
| | | update = true; |
| | | } |
| | | 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; |
| | | update = true; |
| | | } |
| | | |
| | | if (entity.AccountBookStatus == EnumEnterpriseWalletAccountBookStatus.Normal) |
| | | { |
| | | var response = alipayUtils.FundAccountbookQuery(new AlipayFundAccountbookQueryModel |
| | | if (entity.SignStatus == EnumEnterpriseWalletSignStatus.Normal && entity.AccountBookStatus != EnumEnterpriseWalletAccountBookStatus.Normal) |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | var response = 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 = entity.Enterprise.SocietyCreditCode |
| | | }.ToJson() |
| | | }); |
| | | 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; |
| | | update = true; |
| | | } |
| | | |
| | | if (update) |
| | | { |
| | | await rep.UpdateAsync(entity); |
| | | 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.UpdateAsync(entity); |
| | | } |
| | | } |
| | | } |
| | | } |