using Aop.Api.Domain; using Furion.DatabaseAccessor; using Furion.DependencyInjection; using Furion.FriendlyException; using Microsoft.EntityFrameworkCore; using pingan.openbank.api.sdk.enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ApiTools.Core { /// /// 渠道钱包服务 /// /// /// public class ChannelWalletService( ChannelWalletRepository channelWalletRepository, ChannelPingAnPayWalletService channelPingAnPayWalletService ) : ITransient { private readonly ChannelWalletRepository channelWalletRepository = channelWalletRepository; private readonly ChannelPingAnPayWalletService channelPingAnPayWalletService = channelPingAnPayWalletService; public IChannelWalletService GetService(EnumWalletAccess access) { switch (access) { //case EnumWalletAccess.Alipay: // return enterpriseAliPayWalletService; case EnumWalletAccess.PingAnPay: return channelPingAnPayWalletService; //case EnumWalletAccess.WeChatPay: // return enterpriseWeChatPayWalletService; default: throw Oops.Oh(EnumErrorCodeType.s400, "支付通道不支持"); } } /// /// 查询企业钱包余额 /// /// /// public async Task GetEnterpriseWallet(string outWalletId) { var logier = JwtUtils.GetCurrentLogier(); var wallet = await channelWalletRepository.GetQueryable(false) .Where(it => it.ChannelId == logier.ChannelId && it.OutWalletId == outWalletId) .FirstOrDefaultAsync(); return await GetService(wallet.Access).GetEnterpriseWalletBalance(wallet); } /// /// 查询企业钱包余额 /// /// /// public async Task GetEnterpriseWalletBalance(ChannelWallet wallet) { return await GetService(wallet.Access).GetEnterpriseWalletBalance(wallet); } /// /// 转账 /// /// /// /// public async Task Transfer(ChannelWallet wallet, ChannelWalletTransaction transaction) { await GetService(wallet.Access).Transfer(wallet, transaction); } /// /// 查询交易记录 /// /// /// /// public async Task GetTransactionDetail(ChannelWallet wallet, ChannelWalletTransaction transaction) { await GetService(wallet.Access).GetTransactionDetail(wallet, transaction); } /// /// 下载电子收据 /// /// /// /// public async Task DownloadEreceiptUrl(ChannelWallet wallet, ChannelWalletTransaction transaction) { if (transaction.TransactionStatus == EnumWalletTransactionStatus.Success) { await GetService(wallet.Access).DownloadEreceiptUrl(wallet, transaction); } } public string GetLockKey(Guid channelId, string outWalletId) { return $"EnterpriseWallet:{channelId}:{outWalletId}"; } } }