From 0dfdacf054c5d9539a12da3f97402b1cf45ffb77 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期一, 31 三月 2025 14:09:36 +0800
Subject: [PATCH] fix:bug修复

---
 LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs |  204 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 160 insertions(+), 44 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
index 0ad8d61..f640885 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
@@ -21,6 +21,7 @@
     {
         private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository;
         private readonly IRepository<LifePayExpensesReceipts, Guid> _lifePayExpensesReceiptsRepository;
+        private readonly IRepository<LifePayChannlesRake, Guid> _lifePayChannlesRakeRepository;
         private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository;
         private readonly IAliPayApi _aliPayApi;
         private readonly IWxPayApi _wxPayApi;
@@ -28,23 +29,26 @@
         public LifePayOrderService(
                               IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository,
                               IRepository<LifePayExpensesReceipts, Guid> lifePayExpensesReceiptsRepository,
+                              IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository,
                               IRepository<LifePayOrder, Guid> lifePayOrderRepository,
                               IAliPayApi aliPayApi,
                               IWxPayApi wxPayApi)
         {
             _lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository;
             _lifePayExpensesReceiptsRepository = lifePayExpensesReceiptsRepository;
+            _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository;
             _lifePayOrderRepository = lifePayOrderRepository;
             _aliPayApi = aliPayApi;
             _wxPayApi = wxPayApi;
         }
 
+        #region 鏌ヨ
         /// <summary>
         /// 鑾峰彇鍏呭�兼祦姘�
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
-        public async Task<LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input)
+        public async Task<PageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input)
         {
             var list = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false)
                 .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord))
@@ -62,11 +66,132 @@
                 .GetPageResult(input.PageModel);
 
             var total = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount);
-            LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput> result = new LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput>();
-            result.Data = list.Data;
-            result.TotalRechargeAmount = total;
-            return result;
+            LifePayRechargeReceiptsStatistics objectData = new LifePayRechargeReceiptsStatistics();
+            objectData.TotalRechargeAmount = total;
+            list.ObjectData = objectData;
+            return list;
         }
+
+        /// <summary>
+        /// 鑾峰彇鏀舵敮娴佹按
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<PageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input)
+        {
+            var list = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false)
+                .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.OutOrderNo.Contains(input.KeyWord))
+                .WhereIf(input.LifePayType.HasValue, x => x.LifePayType == input.LifePayType)
+                .WhereIf(input.ExpensesReceiptsType.HasValue, x => x.ExpensesReceiptsType == input.ExpensesReceiptsType)
+                .WhereIf(input.TimeBegin.HasValue, x => x.FinishTime >= input.TimeBegin)
+                .WhereIf(input.TimeEnd.HasValue, x => x.FinishTime <= input.TimeEnd)
+
+                .Select(x => new LifePayExpensesReceiptsListOutput()
+                {
+                    Id = x.Id,
+                    OrderNo = x.OrderNo,
+                    OutOrderNo = x.OutOrderNo,
+                    LifePayType = x.LifePayType,
+                    ExpensesReceiptsType = x.ExpensesReceiptsType.Value,
+                    Amount = x.Amount,
+                    FinishTime = x.FinishTime
+                })
+                .GetPageResult(input.PageModel);
+
+            var totalIncome = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false && x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses).SumAsync(x => x.Amount);
+            var totalRefund = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false && x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Receipts).SumAsync(x => x.Amount);
+
+            LifePayExpensesReceiptsStatistics objectData = new LifePayExpensesReceiptsStatistics();
+            objectData.TotalIncome = totalIncome;
+            objectData.TotalRefund = totalRefund;
+            objectData.RealIncome = totalIncome - totalRefund;
+            list.ObjectData = objectData;
+            return list;
+        }
+
+        /// <summary>
+        /// 鑾峰彇娓犻亾鍒嗕剑
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<PageOutput<LifePayChannlesRakeListOutput>> GetLifePayChannlesRakePage(LifePayChannlesRakePageInput input)
+        {
+            var list = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false)
+                .WhereIf(input.ChannelId.IsNotNullOrEmpty(), x => x.ChannelId == input.ChannelId)
+                .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin)
+                .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd)
+                .WhereIf(input.FinishTimeBegin.HasValue, x => x.FinishTime >= input.FinishTimeBegin)
+                .WhereIf(input.FinishTimeEnd.HasValue, x => x.FinishTime <= input.FinishTimeEnd)
+
+                .Select(x => new LifePayChannlesRakeListOutput()
+                {
+                    Id = x.Id,
+                    OrderNo = x.OrderNo,
+                    PayAmount = x.PayAmount,
+                    ChannlesRakeRate = x.ChannlesRakeRate,
+                    ChannlesRakePrice = x.ChannlesRakePrice,
+                    ChannelId = x.ChannelId,
+                    FinishTime = x.FinishTime,
+                    CreationTime = x.CreationTime,
+                })
+                .GetPageResult(input.PageModel);
+
+            var totalRakePrice = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.ChannlesRakePrice);
+
+            LifePayLifePayChannlesRakeStatistics objectData = new LifePayLifePayChannlesRakeStatistics();
+            objectData.TotalRakePrice = totalRakePrice;
+            list.ObjectData = objectData;
+            return list;
+        }
+
+        public async Task<List<LifePayChannlesRakeListTemplate>> GetLifePayChannlesRakePageExport(LifePayChannlesRakePageInput input)
+        {
+            //var result = await (await GetLifePayOrderListFilter(input)).Select(x => new LifePayOrderListTemplate
+            //{
+            //    DiscountAmount = x.DiscountAmount,
+            //    FinishTime = x.FinishTime,
+            //    LifePayOrderStatus = x.LifePayOrderStatus,
+            //    LifePayOrderType = x.LifePayOrderType,
+            //    LifePayType = x.LifePayType,
+            //    OrderNo = x.OrderNo,
+            //    PayAmount = x.PayAmount,
+            //    ActualRechargeAmount = x.RechargeAmount,
+            //    PhoneNumber = x.PhoneNumber,
+            //    RechargeAmount = x.RechargeAmount,
+            //    OutOrderNo = x.OutOrderNo,
+            //    PayStatus = x.PayStatus,
+            //    PayTime = x.PayTime,
+            //    ACOOLYOrderNo = x.ACOOLYOrderNo,
+            //    CreationTime = x.CreationTime,
+            //    LifePayRefundStatus = x.LifePayRefundStatus,
+            //    ACOOLYStatus = x.ACOOLYStatus,
+            //    //RefundApplyRemark = x.RefundApplyRemark,
+            //    ChannelName = x.ChannelName,
+            //    PlatformPrice = x.PlatformDeductionAmount.HasValue ? x.PlatformDeductionAmount.Value : 0.00m
+            //}).OrderByDescending(r => r.CreationTime).ToListAsync();
+            //var i = 0;
+            //result.ForEach(s =>
+            //{
+            //    s.SerialNumber = ++i;
+            //    s.LifePayOrderTypeStr = s.LifePayOrderType.GetDescription();
+            //    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.yyyyMMddHHmmss);
+            //    s.LifePayTypeStr = s.LifePayType.GetDescription();
+            //    s.PayStatusStr = s.PayStatus.GetDescription();
+            //    s.ActualRechargeAmountStr = s.ActualRechargeAmount.ToString("F2");
+            //    s.LifePayRefundStatusStr = s.LifePayRefundStatus == LifePayRefundStatusEnum.鏃犻渶閫�娆� ? "" : s.LifePayRefundStatus.GetDescription();
+            //    s.ACOOLYStatusStr = s.ACOOLYStatus.GetDescription();
+            //    s.LifePayOrderStatusStr = s.LifePayOrderStatus.GetDescription();
+            //    s.FinishTimeStr = !s.FinishTime.HasValue ? string.Empty : s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
+            //});
+            return null;
+        }
+
+        #endregion
+
+
 
 
 
@@ -104,43 +229,7 @@
             }
         }
 
-        /// <summary>
-        /// 鑾峰彇鏀舵敮娴佹按
-        /// </summary>
-        /// <param name="input"></param>
-        /// <returns></returns>
-        public async Task<LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input)
-        {
-            var list = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false)
-                .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.OutOrderNo.Contains(input.KeyWord))
-                .WhereIf(input.LifePayType.HasValue, x => x.LifePayType == input.LifePayType)
-                .WhereIf(input.ExpensesReceiptsType.HasValue, x => x.ExpensesReceiptsType == input.ExpensesReceiptsType)
-                .WhereIf(input.TimeBegin.HasValue, x => x.FinishTime >= input.TimeBegin)
-                .WhereIf(input.TimeEnd.HasValue, x => x.FinishTime <= input.TimeEnd)
-
-                .Select(x => new LifePayExpensesReceiptsListOutput()
-                {
-                    Id = x.Id,
-                    OrderNo = x.OrderNo,
-                    OutOrderNo = x.OutOrderNo,
-                    LifePayType = x.LifePayType,
-                    ExpensesReceiptsType = x.ExpensesReceiptsType.Value,
-                    Amount = x.Amount,
-                    FinishTime = x.FinishTime
-                })
-                .GetPageResult(input.PageModel);
-
-            var totalIncome = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false && x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses).SumAsync(x => x.Amount);
-            var totalRefund = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false && x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Receipts).SumAsync(x => x.Amount);
-
-            LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput> result = new LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>();
-            result.Data = list.Data;
-            result.TotalIncome = totalIncome;
-            result.TotalRefund = totalRefund;
-            result.RealIncome = totalIncome - totalRefund;
-            return result;
-        }
-
+        
         /// <summary>
         /// 鎻掑叆鏀舵敮娴佹按
         /// </summary>
@@ -256,10 +345,37 @@
                         await AddLifePayExpensesReceipts(input);
                     }
                     
-                   
                 }
             }
-           
+        }
+
+        public async Task GetAllChannlesRake()
+        {
+            var orderlist = await _lifePayOrderRepository.Where(x => x.IsDeleted == false && x.PayStatus == LifePayStatusEnum.宸叉敮浠� && x.LifePayOrderStatus == LifePayOrderStatusEnum.宸插畬鎴�).ToListAsync();
+            foreach (var item in orderlist)
+            {
+                /// 姣涘埄
+                var grossProfit = item.RechargeAmount * (item.ChannleRate - item.PlatformRate) / 100;
+                /// 娓犻亾浣i噾  锛�(鍏呭�奸潰棰� * 娓犻亾鎶樻墸姣斾緥)-(鍏呭�奸潰棰� * 骞冲彴鎶樻墸姣斾緥)锛�* 浣i噾姣斾緥
+                var channlesRakePrice = grossProfit * (item.ChannlesRakeRate) / 100;
+                if (channlesRakePrice.HasValue)
+                {
+                    LifePayChannlesRake lifePayChannlesRake = new LifePayChannlesRake()
+                    {
+                        OrderNo = item.OrderNo,
+                        PayAmount = item.PayAmount.Value,
+                        ChannlesRakeRate = item.ChannlesRakeRate.Value,
+                        ChannlesRakePrice = channlesRakePrice.Value,
+                        FinishTime = item.FinishTime.Value,
+                        ChannelId = item.ChannelId,
+                    };
+                    var repeat = _lifePayChannlesRakeRepository.Where(x => x.OrderNo == item.OrderNo).FirstOrDefaultAsync();
+                    if (repeat != null)
+                    {
+                        await _lifePayChannlesRakeRepository.InsertAsync(lifePayChannlesRake);
+                    }
+                }
+            }
         }
     }
 }

--
Gitblit v1.9.1