lingling
2025-03-21 ff7920ed1f3b0ff3f4fccd97c4b31b80fb63b142
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -26,6 +26,7 @@
using Volo.Abp.Domain.Entities;
using Volo.Abp.ObjectMapping;
using NPOI.SS.Formula.Functions;
using StackExchange.Redis;
namespace LifePayment.Application;
@@ -102,6 +103,7 @@
            var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.PayAmount);
            var receiptsYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).SumAsync(x => x.PayAmount);
            var accumulatedOrders = await _lifePayOrderRepository.Where(x => x.CreationTime < today).CountAsync();
            var accumulatedIncome = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.ActualRechargeAmount);
            var ordersNumYesterday = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today).CountAsync();
            var yesterdaySuccess = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.已完成).CountAsync();
            var yesterdayFail = await _lifePayOrderRepository.Where(x => x.CreationTime >= today.AddDays(-1) && x.CreationTime < today && x.LifePayOrderStatus == LifePayOrderStatusEnum.已失败).CountAsync();
@@ -111,23 +113,44 @@
            {
                Id = GuidGenerator.Create(),
                CreationTime = DateTime.Now,
                Amount = "0",
                AccumulatedReceipts = accumulatedReceipts.ToString(),
                ReceiptsYesterday = receiptsYesterday.ToString(),
                AccumulatedOrders = accumulatedOrders.ToString(),
                OrdersNumYesterday = ordersNumYesterday.ToString(),
                YesterdaySuccess = yesterdaySuccess.ToString(),
                YesterdayFail = yesterdayFail.ToString(),
                AccumulatedUsers = accumulatedUsers.ToString(),
                Amount = 0,
                AccumulatedReceipts = accumulatedReceipts,
                ReceiptsYesterday = receiptsYesterday,
                AccumulatedOrders = accumulatedOrders,
                OrdersNumYesterday = ordersNumYesterday,
                YesterdaySuccess = yesterdaySuccess,
                YesterdayFail = yesterdayFail,
                AccumulatedUsers = accumulatedUsers,
            };
            await _dallyStatisticsRepository.InsertAsync(entity);
            var result = ObjectMapper.Map<DallyStatistics, TopStatisticsOutput>(entity);
            return result;
            TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput()
            {
                Amount = entity.Amount,
                AccumulatedReceipts = entity.AccumulatedReceipts,
                ReceiptsYesterday = entity.ReceiptsYesterday,
                AccumulatedOrders = entity.AccumulatedOrders,
                OrdersNumYesterday = entity.OrdersNumYesterday,
                YesterdaySuccess = entity.YesterdaySuccess,
                YesterdayFail = entity.YesterdayFail,
                AccumulatedUsers = entity.AccumulatedUsers,
            };
            return topStatisticsOutput;
        }
        else
        {
            var result = ObjectMapper.Map<DallyStatistics, TopStatisticsOutput>(statistics);
            return result;
            TopStatisticsOutput topStatisticsOutput = new TopStatisticsOutput()
            {
                Amount = statistics.Amount,
                AccumulatedReceipts = statistics.AccumulatedReceipts,
                ReceiptsYesterday = statistics.ReceiptsYesterday,
                AccumulatedOrders = statistics.AccumulatedOrders,
                OrdersNumYesterday = statistics.OrdersNumYesterday,
                YesterdaySuccess = statistics.YesterdaySuccess,
                YesterdayFail = statistics.YesterdayFail,
                AccumulatedUsers = statistics.AccumulatedUsers,
            };
            return topStatisticsOutput;
        }
    }
@@ -304,6 +327,7 @@
                                PayTime = a.PayTime,
                                ACOOLYOrderNo = a.ACOOLYOrderNo,
                                RefundCredentialsImgUrl = a.RefundCredentialsImgUrl.GetOssPath(),
                                RefundPrice = a.RefundPrice,
                                CreationTime = a.CreationTime,
                                RefundCheckRemark = a.RefundCheckRemark,
                                RefundApplyRemark = a.RefundApplyRemark,
@@ -318,6 +342,11 @@
        return result;
    }
    /// <summary>
    /// 退款订单分页
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<PageOutput<LifePayOrderListOutput>> GetLifePayRefundOrderPage(QueryLifePayRefundOrderListInput input)
    {
@@ -360,6 +389,7 @@
                                RefundApplyRemark = a.RefundApplyRemark,
                                RefundApplyTime = a.RefundApplyTime,
                                RefundTime = a.RefundTime,
                                RefundPrice = a.RefundPrice,
                                ChannelName = b.ChannlesName,
                                ActualRechargeAmount = a.ActualRechargeAmount,
                                PlatformDeductionAmount = a.PlatformDeductionAmount,
@@ -373,10 +403,8 @@
    public async Task<LifePayOrderOutput> GetLifePayOrderDetail(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, "订单不存在");
         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;
@@ -407,15 +435,16 @@
            LifePayRefundStatus = order.LifePayRefundStatus,
            ActualRechargeAmount = order.ActualRechargeAmount,
            RefundPrice = order.RefundPrice,
            PlatformRate = platformRate.Rate,
            PlatformRate = order.PlatformRate,
            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),
            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))
            PremiumRate = order.PremiumRate,
            PremiumPrice = Math.Round(order.PayAmount * order.PremiumRate, 2),
            Profit = (order.PayAmount - order.PlatformDeductionAmount) * (1.00m - channle.ChannlesRakeRate / 100) - Math.Round(order.PayAmount * order.PremiumRate, 2)
        };
        return result;
@@ -458,8 +487,10 @@
            ACOOLYOrderNo = order.ACOOLYOrderNo,
            LifePayRefundStatus = order.LifePayRefundStatus,
            ActualRechargeAmount = order.ActualRechargeAmount,
            ActualReceivedAmount = order.ActualReceivedAmount,
            RefundPrice = order.RefundPrice,
            ElecBillUrl = order.ElecBillUrl.GetOssPath(),
            RefundElecBillUrl = order.RefundElecBillUrl.GetOssPath(),
        };
        return result;
@@ -801,6 +832,9 @@
        var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认话费折扣).Rate);
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        var orderInput = new CreateLifePayOrderInput
        {
            OrderNo = channle.ChannlesNum + CreateOrderNo(),
@@ -814,7 +848,10 @@
            PayAmount = amount.PayAmont,
            DiscountAmount = amount.DiscountAmount,
            RechargeAmount = amount.RechargeAmount,
            ChannelId = channle.ChannlesNum
            ChannelId = channle.ChannlesNum,
            PlatformRate = platformRate.Rate,
            ChannleRate = channle.ChannlesRate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
        };
        await CreateLifePayOrder(orderInput);
@@ -845,6 +882,8 @@
        var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认电费折扣).Rate);
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        var orderInput = new CreateLifePayOrderInput
        {
            OrderNo = channle.ChannlesNum + CreateOrderNo(),
@@ -858,7 +897,10 @@
            PayAmount = amount.PayAmont,
            DiscountAmount = amount.DiscountAmount,
            RechargeAmount = amount.RechargeAmount,
            ChannelId = channle.ChannlesNum
            ChannelId = channle.ChannlesNum,
            PlatformRate = platformRate.Rate,
            ChannleRate = channle.ChannlesRate,
            ChannlesRakeRate = channle.ChannlesRakeRate,
        };
        await CreateLifePayOrder(orderInput);
@@ -888,6 +930,8 @@
        CheckExtensions.IfTrueThrowUserFriendlyException(rate.IsNullOrEmpty(), "未配置折扣");
        var amount = CalculateAmount(input.ProductData.ParValue, rate.FirstOrDefault(x => x.RateType == LifePayRateTypeEnum.默认燃气折扣).Rate);
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        var orderInput = new CreateLifePayOrderInput
        {
@@ -927,7 +971,8 @@
        CheckExtensions.IfTrueThrowUserFriendlyException(order.LifePayType.HasValue, "当前订单已选择支付类型");
        order.LifePayType = input.LifePayType;
        var premium = await _lifePayPremiumRepository.Where(x => x.IsDeleted == false && x.PremiumType == order.LifePayType).FirstOrDefaultAsync();
        order.PremiumRate = premium == null ? 0 : premium.Rate;
        await _lifePayOrderRepository.UpdateAsync(order);
        var desc = "生活缴费-";
@@ -1235,8 +1280,6 @@
            return;
        }
        order.LifePayOrderStatus = status;
        order.ACOOLYStatus = acoolyStatus;
        order.PlatformDeductionAmount = payAmount;
        if (acoolyOrderNo.IsNotNullOrEmpty())
        {
@@ -1253,6 +1296,8 @@
            order.PayStatus = LifePayStatusEnum.待退款;
        }
        order.LifePayOrderStatus = status;
        order.ACOOLYStatus = acoolyStatus;
        await _lifePayOrderRepository.UpdateAsync(order);
    }
@@ -1273,6 +1318,16 @@
            return;
        }
        if (input.RefundPrice > order.PayAmount)
        {
            throw new UserFriendlyException("退款的金额不能大于实付金额");
        }
        if (input.LifePayRefundType == LifePayRefundTypeEnum.全额退款)
        {
            input.RefundPrice = order.PayAmount;
        }
        if (order.LifePayOrderStatus != LifePayOrderStatusEnum.已失败 && order.PayStatus != LifePayStatusEnum.待退款 && order.LifePayOrderStatus != LifePayOrderStatusEnum.退款待审核)
        {
            throw new UserFriendlyException("当前订单状态无法退款");
@@ -1283,7 +1338,7 @@
        switch (order.LifePayType)
        {
            case LifePayTypeEnum.WxPay:
                var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(order.PayAmount * 100), Convert.ToInt32(order.PayAmount * 100));
                var wxRefundResult = await WxPayDomesticRefunds(order.OrderNo, outRefundNo,order.RefundApplyRemark, Convert.ToInt32(input.RefundPrice * 100), Convert.ToInt32(order.PayAmount * 100));
                if (wxRefundResult.Status == "SUCCESS")
                {
                    order.PayStatus = LifePayStatusEnum.已退款;
@@ -1305,7 +1360,7 @@
                break;
            case LifePayTypeEnum.AliPay:
                var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = order.PayAmount.ToString() });
                var aliRefundResult = await AliTradeRefund(new AlipayTradeRefundRequest() { OutTradeNo = order.OrderNo, RefundAmount = Convert.ToInt32(input.RefundPrice * 100).ToString() });
                if (aliRefundResult.Code != AlipayResultCode.Success)
                {
                    throw new UserFriendlyException("退款失败");
@@ -1321,7 +1376,7 @@
        order.RefundCheckRemark = input.RefundCheckRemark;
        order.RefundTime = DateTime.Now;
        order.RefundCheckUserId = CurrentUser.Id;
        order.RefundPrice = order.PayAmount;
        order.RefundPrice = input.RefundPrice;
        await _lifePayOrderRepository.UpdateAsync(order);