zhengyuxuan
2025-03-21 7b1de9565e68debff4b77906f453acbcbf358a55
fix:提交
3个文件已修改
2个文件已添加
193 ■■■■■ 已修改文件
LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application.Contracts/LifePay/IStatisticsService.cs 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application/LifePay/LifePayService.cs 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application/LifePay/StatisticsService.cs 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs
@@ -10,7 +10,6 @@
public interface ILifePayService : IApplicationService
{
    Task<TopStatisticsOutput> GetTopStatistics();
    /// <summary>
    /// 获取电费面值
LifePayment/LifePayment.Application.Contracts/LifePay/IStatisticsService.cs
New file
@@ -0,0 +1,15 @@
using LifePayment.Domain.Shared;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using ZeroD.Util;
namespace LifePayment.Application.Contracts;
public interface IStatisticsService : IApplicationService
{
    Task<TopStatisticsOutput> GetTopStatistics();
}
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -61,7 +61,6 @@
                          IRepository<LifePayUser, Guid> lifePayUserRepository,
                          IRepository<LifePayPremium, Guid> lifePayPremiumRepository,
                          IRepository<LifePayIntroInfo, Guid> lifePayIntroInfoRepository,
                          IRepository<DallyStatistics, Guid> dallyStatisticsRepository,
                          IRepository<OperateHistory, Guid> operateHistory,
                          IAliPayApi aliPayApi,
                          IAlipayInterfaceManager aliPayInterfaceManager,
@@ -79,7 +78,6 @@
        _lifePayUserRepository = lifePayUserRepository;
        _lifePayPremiumRepository = lifePayPremiumRepository;
        _lifePayIntroInfoRepository = lifePayIntroInfoRepository;
        _dallyStatisticsRepository = dallyStatisticsRepository;
        _aliPayApi = aliPayApi;
        _alipayInterfaceManager = aliPayInterfaceManager;
        _wxPayApi = wxPayApi;
@@ -94,65 +92,6 @@
    #region 查询
    public async Task<TopStatisticsOutput> GetTopStatistics()
    {
        var today = DateTime.Now.Date;
        var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync();
        if (statistics == null)
        {
            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();
            var accumulatedUsers = await _lifePayUserRepository.CountAsync();
            var entity = new DallyStatistics()
            {
                Id = GuidGenerator.Create(),
                CreationTime = DateTime.Now,
                Amount = 0,
                AccumulatedReceipts = accumulatedReceipts,
                ReceiptsYesterday = receiptsYesterday,
                AccumulatedOrders = accumulatedOrders,
                OrdersNumYesterday = ordersNumYesterday,
                YesterdaySuccess = yesterdaySuccess,
                YesterdayFail = yesterdayFail,
                AccumulatedUsers = accumulatedUsers,
            };
            await _dallyStatisticsRepository.InsertAsync(entity);
            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
        {
            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;
        }
    }
    /// <summary>
    /// 获取电费面值
@@ -1293,7 +1232,7 @@
        if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已失败 && order.PayStatus != LifePayStatusEnum.已退款)
        {
            order.PayStatus = LifePayStatusEnum.待退款;
            order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款;
        }
        order.LifePayOrderStatus = status;
@@ -1313,7 +1252,7 @@
        var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
        if (order.PayStatus == LifePayStatusEnum.已退款)
        if (order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款)
        {
            return;
        }
@@ -1341,19 +1280,16 @@
                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.已退款;
                    order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款;
                    order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款;
                }
                else if (wxRefundResult.Status == "PROCESSING")
                {
                    order.PayStatus = LifePayStatusEnum.退款中;
                    order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中;
                    order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中;
                }
                else
                {
                    order.PayStatus = LifePayStatusEnum.待退款;
                    order.LifePayOrderStatus = LifePayOrderStatusEnum.退款失败;
                    order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款;
                }
@@ -1365,8 +1301,6 @@
                {
                    throw new UserFriendlyException("退款失败");
                }
                order.PayStatus = LifePayStatusEnum.已退款;
                order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款;
                break;
            default: throw new UserFriendlyException("退款失败");
@@ -1403,7 +1337,7 @@
            throw new UserFriendlyException("非用户本人退款");
        }
        if (order.PayStatus == LifePayStatusEnum.已退款)
        if (order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款)
        {
            return;
        }
@@ -1537,7 +1471,7 @@
        var order = await _lifePayOrderRepository.FirstOrDefaultAsync(x => x.Id == input.Id);
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
        if (order.PayStatus == LifePayStatusEnum.已退款)
        if(order.LifePayRefundStatus == LifePayRefundStatusEnum.已退款)
        {
            return;
        }
LifePayment/LifePayment.Application/LifePay/StatisticsService.cs
New file
@@ -0,0 +1,98 @@
using LifePayment.Application.Contracts;
using LifePayment.Domain.LifePay;
using LifePayment.Domain.Models;
using LifePayment.Domain.Shared;
using LifePayment.Domain;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus.Distributed;
using static Nest.FileSystemStats;
using Microsoft.EntityFrameworkCore;
namespace LifePayment.Application.LifePay
{
    public class StatisticsService : ApplicationService, IStatisticsService
    {
        private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository;
        private readonly IRepository<LifePayUser, Guid> _lifePayUserRepository;
        private readonly IRepository<DallyStatistics, Guid> _dallyStatisticsRepository;
        public StatisticsService(
                              IRepository<LifePayOrder, Guid> lifePayOrderRepository,
                              IRepository<LifePayUser, Guid> lifePayUserRepository,
                            IRepository<DallyStatistics, Guid> dallyStatisticsRepository)
        {
            _lifePayOrderRepository = lifePayOrderRepository;
            _lifePayUserRepository = lifePayUserRepository;
            _dallyStatisticsRepository = dallyStatisticsRepository;
        }
        public async Task<TopStatisticsOutput> GetTopStatistics()
        {
            var today = DateTime.Now.Date;
            var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.Date == today).FirstOrDefaultAsync();
            if (statistics == null)
            {
                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();
                var accumulatedUsers = await _lifePayUserRepository.CountAsync();
                var entity = new DallyStatistics()
                {
                    Id = GuidGenerator.Create(),
                    CreationTime = DateTime.Now,
                    Amount = 0,
                    AccumulatedReceipts = accumulatedReceipts,
                    ReceiptsYesterday = receiptsYesterday,
                    AccumulatedOrders = accumulatedOrders,
                    OrdersNumYesterday = ordersNumYesterday,
                    YesterdaySuccess = yesterdaySuccess,
                    YesterdayFail = yesterdayFail,
                    AccumulatedUsers = accumulatedUsers,
                };
                await _dallyStatisticsRepository.InsertAsync(entity);
                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
            {
                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;
            }
        }
    }
}
LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs
@@ -20,15 +20,18 @@
    public class LifePayController : AbpController
    {
        private readonly ILifePayService _lifePayService;
        private readonly IStatisticsService _statisticsService;
        private readonly IWebClientInfoProvider _webClientInfoProvider;
        private readonly ILogger<LifePayController> _logger;
        public LifePayController(
              ILifePayService lifePayService,
              IStatisticsService statisticsService,
              IWebClientInfoProvider webClientInfoProvider
            , ILogger<LifePayController> logger
              )
        {
            _lifePayService = lifePayService;
            _statisticsService = statisticsService;
            _webClientInfoProvider = webClientInfoProvider;
            _logger = logger;
        }
@@ -43,7 +46,7 @@
        [AllowAnonymous]
        public async Task<TopStatisticsOutput> GetTopStatistics()
        {
            return await _lifePayService.GetTopStatistics();
            return await _statisticsService.GetTopStatistics();
        }
        /// <summary>