zhengyuxuan
2025-03-25 8dd294b46213917661aa9d580289a973eb614e67
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -358,7 +358,7 @@
    {
        var result = await (await GetLifePayRefundOrderListFilter(input)).Select(x => new LifePayRefundOrderListTemplate
        {
            FinishTime = x.FinishTime,
            FinishTime = x.RefundTime,
            RefundPrice = x.RefundPrice,
            LifePayOrderType = x.LifePayOrderType,
            LifePayType = x.LifePayType,
@@ -368,6 +368,7 @@
            ChannelName = x.ChannelName,
            CreationTime = x.CreationTime,
            ACOOLYStatus = x.ACOOLYStatus,
            RefundApplyRemark = x.RefundApplyRemark,
            RechargeAmount = x.RechargeAmount,
            ActualReceivedAmount = x.ActualReceivedAmount.ToString("F2"),
            LifePayRefundStatus = x.LifePayRefundStatus,
@@ -398,6 +399,9 @@
         CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
        var user = await _lifePayUserRepository.FirstOrDefaultAsync(x => x.Id == order.UserId);
        var channlesRakePrice = (order.PayAmount - (order.PlatformDeductionAmount == null ? 0 : order.PlatformDeductionAmount)) * channle.ChannlesRakeRate / 100;
        var orderpirce = await GetOrderPrice(order.RechargeAmount, order.PayAmount,order.PlatformRate, order.ChannleRate, order.ChannlesRakeRate,order.PremiumRate);
        var result = new LifePayOrderOutput()
                {
            UserName = user.Name,
@@ -429,12 +433,12 @@
            PlatformPrice = order.PlatformDeductionAmount,
            ElecBillUrl = order.ElecBillUrl.GetOssPath(),
            RefundElecBillUrl = order.RefundElecBillUrl.GetOssPath(),
            ChannleRate = channle.ChannlesRate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
            ChannlesRakePrice = channlesRakePrice.HasValue ? 0 : Math.Round(channlesRakePrice.Value, 2),
            ChannleRate = order.ChannleRate,
            ChannlesRakeRate = order.ChannlesRakeRate,
            ChannlesRakePrice = orderpirce.ChannlesRakePrice,
            PremiumRate = order.PremiumRate,
            PremiumPrice = Math.Round(order.PayAmount * (order.PremiumRate.HasValue ? order.PremiumRate.Value:0), 2),
            Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - Math.Round(order.PayAmount * (order.PremiumRate.HasValue ? order.PremiumRate.Value : 0), 2)
            PremiumPrice = orderpirce.PremiumPrice,
            Profit = orderpirce.Profit
        };
        return result;
@@ -526,6 +530,7 @@
                                                        CreationTime = x.CreationTime,
                                                        RefundCheckRemark = x.RefundCheckRemark,
                                                        RefundApplyRemark = x.RefundApplyRemark,
                                                        RefundApplyTime = x.RefundApplyTime,
                                                        RefundTime = x.RefundTime,
                                                        ACOOLYOrderNo = x.ACOOLYOrderNo,
                                                        LifePayRefundStatus = x.LifePayRefundStatus,
@@ -744,17 +749,17 @@
        {
            s.SerialNumber = ++i;
            s.LifePayOrderTypeStr = s.LifePayOrderType.GetDescription();
            s.CreationTimeStr = s.CreationTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm);
            s.CreationTimeStr = s.CreationTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
            s.RechargeAmountStr = s.RechargeAmount.ToString("F2");
            s.PayAmountStr = s.PayAmount.ToString("F2");
            s.PayTimeStr = !s.PayTime.HasValue ? string.Empty : s.PayTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm);
            s.PayTimeStr = !s.PayTime.HasValue ? string.Empty : s.PayTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
            s.LifePayTypeStr = s.LifePayType.GetDescription();
            s.PayStatusStr = s.PayStatus.GetDescription();
            s.ActualRechargeAmountStr = s.ActualRechargeAmount.ToString("F2");
            s.LifePayRefundStatusStr = s.LifePayRefundStatusStr.GetDescription();
            s.ACOOLYStatusStr = s.ACOOLYStatus.GetDescription();
            //s.LifePayOrderStatusStr = s.LifePayOrderStatus.GetDescription();
            s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmm);
            s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
        });
        return result;
    }
@@ -828,6 +833,8 @@
        var rate = await GetRate();
        CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣");
        var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认话费折扣).Rate);
@@ -1561,24 +1568,21 @@
        var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
        if(order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款)
        if (order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款)
        {
            return;
        }
        if (order.LifePayOrderStatus == LifePayOrderStatusEnum.待退款)
        if (order.LifePayOrderStatus == LifePayOrderStatusEnum.待退款 || order.LifePayRefundStatus == LifePayRefundStatusEnum.待退款)
        {
            if (order.ACOOLYStatus == ACOOLYStatusEnum.已完成 || order.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
            if (order.ACOOLYStatus == ACOOLYStatusEnum.已完成 || order.ACOOLYStatus == ACOOLYStatusEnum.充值成功 || order.ACOOLYStatus == ACOOLYStatusEnum.部分充值成功)
            {
                order.LifePayOrderStatus = LifePayOrderStatusEnum.已完成;
            }
            else if (order.ACOOLYStatus == ACOOLYStatusEnum.充值失败)
            {
                order.LifePayOrderStatus = LifePayOrderStatusEnum.退款失败;
            }
            order.RefundCheckRemark = input.RefundCheckRemark;
            order.RefundCheckUserId = CurrentUser.Id;
            order.LifePayRefundStatus = LifePayRefundStatusEnum.无需退款;
            await _lifePayOrderRepository.UpdateAsync(order);
@@ -2069,5 +2073,51 @@
                    });
    }
    public async Task<OrderPriceReturn> GetOrderPrice(decimal price, decimal priceAmount, decimal? platformRate,decimal? channleRate,
        decimal? channlesRakeRate,decimal? premiumRate)
    {
        /// 毛利
        var grossProfit = price * (channleRate - platformRate) / 100;
        /// 平台扣款金额  充值面额 * 平台折扣比例
        var platformPrice = price * platformRate / 100;
        /// 手续费
        var premiumPrice = priceAmount * premiumRate / 100;
        /// 渠道佣金  ((充值面额 * 渠道折扣比例)-(充值面额 * 平台折扣比例))* 佣金比例
        var channlesRakePrice = grossProfit * channlesRakeRate / 100;
        /// 利润
        var profit = grossProfit - channlesRakePrice - premiumPrice;
        return new OrderPriceReturn()
        {
            PlatformPrice = platformPrice.HasValue? platformPrice.Value :0,
            PremiumPrice = premiumPrice.HasValue ? premiumPrice.Value : 0,
            ChannlesRakePrice = channlesRakePrice.HasValue? channlesRakePrice.Value:0,
            Profit = profit.HasValue ? profit.Value : 0
        };
    }
    public async Task<decimal> GetLifePayRate(string channelId, LifePayRateTypeEnum lifePayRateType)
    {
        if (string.IsNullOrEmpty(channelId))
        {
            var rate = await GetRate();
            CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣");
            var result = rate.FirstOrDefault(x => x.RateType == lifePayRateType).Rate;
            return result;
        }
        else
        {
            //var channel = await _lifePayChannlesRep.Where(x => x.ChannlesNum == channelId);
            return 0;
        }
    }
    #endregion
}