| | |
| | | public class EnterpriseWalletQueryHandler( |
| | | IRepository<EnterpriseWallet> rep, |
| | | IRepository<EnterpriseWalletTransaction> repEnterpriseWalletTransaction, |
| | | IRepository<EnterpriseWalletExpandindirectOrder> repEnterpriseWalletExpandindirectOrder, |
| | | IRepository<Enterprise> repEnterprise, |
| | | AlipayUtils alipayUtils |
| | | ) : |
| | |
| | | { |
| | | private readonly IRepository<EnterpriseWallet> rep = rep; |
| | | private readonly IRepository<EnterpriseWalletTransaction> repEnterpriseWalletTransaction = repEnterpriseWalletTransaction; |
| | | private readonly IRepository<EnterpriseWalletExpandindirectOrder> repEnterpriseWalletExpandindirectOrder = repEnterpriseWalletExpandindirectOrder; |
| | | private readonly IRepository<Enterprise> repEnterprise = repEnterprise; |
| | | private readonly AlipayUtils alipayUtils = alipayUtils; |
| | | |
| | |
| | | var entity = await rep.AsQueryable() |
| | | .Where(it => it.EnterpriseId == request.EnterpriseId && it.Access == request.Access) |
| | | .FirstOrDefaultAsync(); |
| | | if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "企业钱包"); |
| | | if (entity == null) |
| | | { |
| | | return new GetEnterpriseWalletQueryResult |
| | | { |
| | | Access = request.Access, |
| | | SignStatus = EnumEnterpriseWalletSignStatus.Wait, |
| | | ExpandindirectOrderStatus = EnumEnterpriseWalletExpandindirectOrderStatus.Wait |
| | | }; |
| | | } |
| | | var update = false; |
| | | if (entity.Access == EnumEnterpriseWalletAccess.Alipay) |
| | | { |
| | |
| | | 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 (!response.IsError) |
| | | { |
| | | 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 model = entity.Adapt<GetEnterpriseWalletQueryResult>(); |
| | | |
| | | var expandindirectOrder = await repEnterpriseWalletExpandindirectOrder.AsQueryable().AsNoTracking() |
| | | .OrderByDescending(it => it.CreatedTime) |
| | | .Where(it => it.WalletId == model.Id) |
| | | .Select(it => new |
| | | { |
| | | it.OrderStatus |
| | | }) |
| | | .FirstOrDefaultAsync(); |
| | | model.ExpandindirectOrderStatus = expandindirectOrder == null |
| | | ? EnumEnterpriseWalletExpandindirectOrderStatus.Wait |
| | | : expandindirectOrder.OrderStatus; |
| | | |
| | | return model; |
| | | } |
| | | |
| | |
| | | entity.TransDate = response.PayDate.ToDateTime(); |
| | | entity.Status = response.Status; |
| | | entity.TransactionStatus = response.Status == "SUCCESS" |
| | | ? EnumEnterpriseWalletTransactionStatus.Success |
| | | ? EnumWalletTransactionStatus.Success |
| | | : response.Status == "DEALING" |
| | | ? EnumEnterpriseWalletTransactionStatus.Dealing |
| | | ? EnumWalletTransactionStatus.Dealing |
| | | : response.Status == "REFUND" |
| | | ? EnumEnterpriseWalletTransactionStatus.Refund |
| | | ? EnumWalletTransactionStatus.Refund |
| | | : response.Status == "FAIL" |
| | | ? EnumEnterpriseWalletTransactionStatus.Fail |
| | | ? EnumWalletTransactionStatus.Fail |
| | | : throw Oops.Oh(EnumErrorCodeType.s510, $"未识别的状态:{response.Status}"); |
| | | await repEnterpriseWalletTransaction.UpdateAsync(entity); |
| | | if (entity.TransactionStatus == EnumEnterpriseWalletTransactionStatus.Success) |
| | | if (entity.TransactionStatus == EnumWalletTransactionStatus.Success) |
| | | { |
| | | await GetBalance(entity.WalletId); |
| | | } |