zhengyiming
昨天 f7bb0825bc06b8cea32caa44d2326dde51990e77
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -1,5 +1,6 @@
using Alipay.EasySDK.Payment.Common.Models;
using LifePayment.Application.Contracts;
using LifePayment.Application.LifePay;
using LifePayment.Domain;
using LifePayment.Domain.LifePay;
using LifePayment.Domain.Models;
@@ -50,6 +51,7 @@
    private readonly IAliPayApi _aliPayApi;
    private readonly IAlipayInterfaceManager _alipayInterfaceManager;
    private readonly IWxPayApi _wxPayApi;
    private readonly ILifePayRateService _lifePayRateService;
    private readonly WxPayOption _wxPayOptions;
    private readonly InitSetting _initSettingOptions;
@@ -77,6 +79,7 @@
                          IRepository<LifePayAccount, Guid> lifePayAccount,
                          IDataFilter dataFilter,
                          IChannelFilter channelFilter,
                          ILifePayRateService lifePayRateService,
                          IAbpDistributedLock distributedLock)
    {
        _logger = logger;
@@ -101,6 +104,7 @@
        _channelFilter = channelFilter;
        this.distributedLock = distributedLock;
        _operateHistory = operateHistory;
        _lifePayRateService = lifePayRateService;
    }
    #region 查询
@@ -1086,11 +1090,14 @@
        && x.OrderParamDetailJsonStr.Contains(input.ProductData.Phone)).AnyAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder, "您有同户号订单正在充值中,请勿重复充值");
        var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认话费折扣);
        var rateChannel = await GetLifePayRate(channle,input.ProductData.IspCode);
        //平台折扣
        var rate = rateChannel.Rate;
        var amount = CalculateAmount(input.ProductData.ParValue, rate);
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        //供应商折扣价
        var platformRate = rateChannel.SupplierRate;
        var orderInput = new CreateLifePayOrderInput
        {
@@ -1106,8 +1113,8 @@
            DiscountAmount = amount.DiscountAmount,
            RechargeAmount = amount.RechargeAmount,
            ChannelId = channle.ChannlesNum,
            PlatformRate = platformRate.Rate,
            PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100,
            PlatformRate = platformRate,
            PlatformDeductionAmount = amount.RechargeAmount * platformRate / 100,
            ChannleRate = rate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
        };
@@ -1140,16 +1147,13 @@
         && x.OrderParamDetailJsonStr.Contains(input.ProductData.ElectricAccount)).AnyAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder, "您有同户号订单正在充值中,请勿重复充值");
        var rateChannel = await GetLifePayRate(channle, input.ProductData.ElectricType);
        //平台折扣
        var rate = rateChannel.Rate;
        var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认电费折扣);
        var amount = CalculateAmount(input.ProductData.ParValue, rate);
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        //TODO 相关单项折扣调节功能未上线 目前针对情况临时写死
        if (input.ProductData.ElectricType == "guowang")
        {
            platformRate.Rate = 95;
        }
        //供应商折扣价
        var platformRate = rateChannel.SupplierRate;
        var orderInput = new CreateLifePayOrderInput
        {
@@ -1164,8 +1168,8 @@
            DiscountAmount = amount.DiscountAmount,
            RechargeAmount = amount.RechargeAmount,
            ChannelId = channle.ChannlesNum,
            PlatformRate = platformRate.Rate,
            PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100,
            PlatformRate = platformRate,
            PlatformDeductionAmount = amount.RechargeAmount * platformRate / 100,
            ChannleRate = rate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
        };
@@ -1198,12 +1202,14 @@
        && x.OrderParamDetailJsonStr.Contains(input.ProductData.GasAccount)).AnyAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(repeatOrder, "您有同户号订单正在充值中,请勿重复充值");
        var rate = await GetLifePayRate(channle, LifePayRateTypeEnum.默认燃气折扣);
        var rateChannel = await GetLifePayRate(channle, input.ProductData.GasOrgType);
        //平台折扣
        var rate = rateChannel.Rate;
        var amount = CalculateAmount(input.ProductData.ParValue, rate);
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        //供应商折扣价
        var platformRate = rateChannel.SupplierRate;
        var orderInput = new CreateLifePayOrderInput
        {
@@ -1219,8 +1225,8 @@
            DiscountAmount = amount.DiscountAmount,
            RechargeAmount = amount.RechargeAmount,
            ChannelId = channle.ChannlesNum,
            PlatformRate = platformRate.Rate,
            PlatformDeductionAmount = amount.RechargeAmount * platformRate.Rate / 100,
            PlatformRate = platformRate,
            PlatformDeductionAmount = amount.RechargeAmount * platformRate / 100,
            ChannleRate = rate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
        };
@@ -1923,6 +1929,7 @@
                dto.PromoterId = promoter.Id;
            }
            //TODO 后续需要修改 现在的供应商折扣价根据运营商不同 配置不同 不是统一配置了
            var rate = await _lifePayRateRepository.FirstOrDefaultAsync(it => it.RateType == LifePayRateTypeEnum.供应商折扣价);
            CheckExtensions.IfTrueThrowUserFriendlyException(rate != null && input.ChannlesRate < rate.Rate, "渠道折扣无法低于供应商折扣");
@@ -2455,18 +2462,24 @@
        };
    }
    public async Task<decimal> GetLifePayRate(CreateEditPayChannelsInput channel, LifePayRateTypeEnum lifePayRateType)
    public async Task<GetLifePayRateOutput> GetLifePayRate(CreateEditPayChannelsInput channel, string code)
    {
        var rateChannel = await _lifePayRateService.GetRateChannelByCode(code);
            CheckExtensions.IfTrueThrowUserFriendlyException(rateChannel.Id.IsEmpty(), "未配置折扣");
        if (channel == null)
        {
            var rate = await GetRate();
            CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣");
            var result = rate.FirstOrDefault(x => x.RateType == lifePayRateType).Rate;
            return result;
            return new GetLifePayRateOutput
            {
                Rate = rateChannel.PlatformRate,
                SupplierRate = rateChannel.SupplierRate
            };
        }
        else
        {
            return channel.ChannlesRate;
            return new GetLifePayRateOutput {
                Rate= channel.ChannlesRate,
                SupplierRate = rateChannel.SupplierRate
            };
        }
    }