zhengyuxuan
2025-03-20 fbd573b5d2d05cac61d2184064bb5dd18d0fe61f
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -271,15 +271,21 @@
    {
        var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync();
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        var channleRate = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.ChannlesNum == order.ChannelId);
        var premiumRate = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync();
        var channle = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.ChannlesNum == order.ChannelId);
        var premium = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
        var channlesRakePrice = (order.PayAmount - (order.PlatformDeductionAmount == null ? 0 : order.PlatformDeductionAmount)) * channleRate.ChannlesRakeRate / 100;
        var user = await _lifePayUserRepository.FirstOrDefaultAsync(x => x.Id == order.UserId);
        var channlesRakePrice = (order.PayAmount - (order.PlatformDeductionAmount == null ? 0 : order.PlatformDeductionAmount)) * channle.ChannlesRakeRate / 100;
        var result = new LifePayOrderOutput()
                {
            UserName = user.Name,
            UserPhoneNumber = user.PhoneNumber,
            DiscountAmount = order.DiscountAmount,
            FinishTime = order.FinishTime,
            Id = order.Id,
            OutOrderNo = order.OutOrderNo,
            LifePayChannle = channle.ChannlesName,
            LifePayOrderStatus = order.LifePayOrderStatus,
            LifePayOrderType = order.LifePayOrderType,
            LifePayType = order.LifePayType,
@@ -300,12 +306,53 @@
            RefundPrice = order.RefundPrice,
            PlatformRate = platformRate.Rate,
            PlatformPrice = order.PlatformDeductionAmount,
            ChannleRate = channleRate.ChannlesRate,
            ChannlesRakeRate = channleRate.ChannlesRakeRate,
            ChannleRate = channle.ChannlesRate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
            ChannlesRakePrice = channlesRakePrice.HasValue ? 0 : Math.Round(channlesRakePrice.Value, 2),
            PremiumRate = premiumRate == null ? 0 : premiumRate.Rate,
            PremiumPrice = premiumRate == null ? 0 : Math.Round(order.PayAmount * premiumRate.Rate, 2),
            Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channleRate.ChannlesRakeRate / 100) - (premiumRate == null ? 0 : Math.Round(order.PayAmount * premiumRate.Rate, 2))
            PremiumRate = premium == null ? 0 : premium.Rate,
            PremiumPrice = premium == null ? 0 : Math.Round(order.PayAmount * premium.Rate, 2),
            Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - (premium == null ? 0 : Math.Round(order.PayAmount * premium.Rate, 2))
        };
        return result;
    }
    public async Task<LifePayRefundOrderOutput> GetLifePayRefundOrderDetail(string orderNo)
    {
        var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync();
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        var channle = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.ChannlesNum == order.ChannelId);
        var premium = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync();
        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 result = new LifePayRefundOrderOutput()
        {
            UserName = user.Name,
            UserPhoneNumber = user.PhoneNumber,
            DiscountAmount = order.DiscountAmount,
            FinishTime = order.FinishTime,
            Id = order.Id,
            OutOrderNo = order.OutOrderNo,
            LifePayChannle = channle.ChannlesName,
            LifePayOrderStatus = order.LifePayOrderStatus,
            LifePayOrderType = order.LifePayOrderType,
            LifePayType = order.LifePayType,
            OrderNo = order.OrderNo,
            PayAmount = order.PayAmount,
            RechargeAmount = order.RechargeAmount,
            PayStatus = order.PayStatus,
            PayTime = order.PayTime,
            RefundCredentialsImgUrl = order.RefundCredentialsImgUrl.GetOssPath(),
            CreationTime = order.CreationTime,
            RefundCheckRemark = order.RefundCheckRemark,
            RefundApplyRemark = order.RefundApplyRemark,
            RefundTime = order.RefundTime,
            ACOOLYOrderNo = order.ACOOLYOrderNo,
            LifePayRefundStatus = order.LifePayRefundStatus,
            ActualRechargeAmount = order.ActualRechargeAmount,
            RefundPrice = order.RefundPrice,
        };
        return result;
@@ -1046,6 +1093,7 @@
            order.PayStatus = LifePayStatusEnum.待退款;
        }
        await _lifePayOrderRepository.UpdateAsync(order);
    }
@@ -1070,10 +1118,12 @@
            throw new UserFriendlyException("当前订单状态无法退款");
        }
        var outRefundNo = order.ChannelId + CreateRefundOrderNo();
        order.RefundOrderNo = outRefundNo;
        switch (order.LifePayType)
        {
            case LifePayTypeEnum.WxPay:
                var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, order.RefundApplyRemark, Convert.ToInt32(order.PayAmount * 100), Convert.ToInt32(order.PayAmount * 100));
                var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(order.PayAmount * 100), Convert.ToInt32(order.PayAmount * 100));
                if (wxRefundResult.Status == "SUCCESS")
                {
                    order.PayStatus = LifePayStatusEnum.已退款;
@@ -1161,12 +1211,12 @@
    /// <param name="total"></param>
    /// <param name="currency"></param>
    /// <returns></returns>
    public async Task<WxPayDomesticRefundsReponse> WxPayDomesticRefunds(string outTradeNo, string reason, int refund, int total, string currency = "CNY")
    public async Task<WxPayDomesticRefundsReponse> WxPayDomesticRefunds(string outTradeNo,string outRefundNo, string reason, int refund, int total, string currency = "CNY")
    {
        WxPayDomesticRefundsRequest req = new WxPayDomesticRefundsRequest
        {
            OutTradeNo = outTradeNo,
            OutRefundNo = CreateRefundOrderNo(),
            OutRefundNo = outRefundNo,
            Reason = reason,
            Amount = new Model_WxPayDomesticRefunds_Amount
            {