From 86d7078a77afb507e377ff4f02c14d1dd2defb6e Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期二, 01 四月 2025 16:41:38 +0800
Subject: [PATCH] Merge branch 'dev-lifepay-v1.3' of http://120.26.58.240:8888/r/LifePaymentApi into dev-lifepay-v1.3
---
LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs | 296 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 244 insertions(+), 52 deletions(-)
diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
index 0ad8d61..fca55d3 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
@@ -14,6 +14,8 @@
using LifePayment.Domain;
using static LifePayment.Domain.Shared.LifePaymentConstant;
using Newtonsoft.Json;
+using LifePayment.Domain.Common;
+using Spire.Pdf.Exporting.XPS.Schema;
namespace LifePayment.Application.LifePay
{
@@ -21,6 +23,8 @@
{
private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository;
private readonly IRepository<LifePayExpensesReceipts, Guid> _lifePayExpensesReceiptsRepository;
+ private readonly IRepository<LifePayConsumption, Guid> _lifePayConsumption;
+ private readonly IRepository<LifePayChannlesRake, Guid> _lifePayChannlesRakeRepository;
private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository;
private readonly IAliPayApi _aliPayApi;
private readonly IWxPayApi _wxPayApi;
@@ -28,15 +32,56 @@
public LifePayOrderService(
IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository,
IRepository<LifePayExpensesReceipts, Guid> lifePayExpensesReceiptsRepository,
+ IRepository<LifePayConsumption, Guid> lifePayConsumptionRepository,
+ IRepository<LifePayChannlesRake, Guid> lifePayChannlesRakeRepository,
IRepository<LifePayOrder, Guid> lifePayOrderRepository,
IAliPayApi aliPayApi,
IWxPayApi wxPayApi)
{
_lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository;
_lifePayExpensesReceiptsRepository = lifePayExpensesReceiptsRepository;
+ _lifePayConsumption = lifePayConsumptionRepository;
+ _lifePayChannlesRakeRepository = lifePayChannlesRakeRepository;
_lifePayOrderRepository = lifePayOrderRepository;
_aliPayApi = aliPayApi;
_wxPayApi = wxPayApi;
+ }
+
+ #region 鏌ヨ
+
+ /// <summary>
+ /// 鑾峰彇娑堣垂娴佹按
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public async Task<PageOutput<LifePayConsumptionListOutput>> GetLifePayConsumptionPage(LifePayConsumptionPageInput input)
+ {
+ var list = await _lifePayConsumption.Where(x => x.IsDeleted == false)
+ .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.OutOrderNo.Contains(input.KeyWord) || x.ChannelId.Contains(input.KeyWord))
+ .WhereIf(input.Flow.HasValue, x => x.Flow == input.Flow)
+ .WhereIf(input.TimeBegin.HasValue, x => x.FinishTime >= input.TimeBegin)
+ .WhereIf(input.TimeEnd.HasValue, x => x.FinishTime <= input.TimeEnd)
+ .Select(x => new LifePayConsumptionListOutput()
+ {
+ Id = x.Id,
+ OrderNo = x.OrderNo,
+ OutOrderNo = x.OutOrderNo,
+ Amount = x.Amount,
+ FinishTime = x.FinishTime,
+ FrozenStatus = x.FrozenStatus,
+ Flow = x.Flow,
+ DeductionAmount = x.DeductionAmount,
+ FrozenAmount = x.FrozenAmount.Value
+ })
+ .GetPageResult(input.PageModel);
+
+ var totalDeductionAmount = await _lifePayConsumption.Where(x => x.IsDeleted == false).SumAsync(x => x.DeductionAmount);
+ var totalFrozenAmount = await _lifePayConsumption.Where(x => x.IsDeleted == false).SumAsync(x => x.FrozenAmount);
+ LifePayConsumptionStatistics objectData = new LifePayConsumptionStatistics();
+ objectData.TotalDeductionAmount = totalDeductionAmount;
+ objectData.TotalFrozenAmount = totalFrozenAmount.Value;
+ list.ObjectData = objectData;
+ return list;
}
/// <summary>
@@ -44,7 +89,7 @@
/// </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,13 +107,111 @@
.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;
+ 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 GetLifePayChannlesRakeListFilter(input)).Select(x => new LifePayChannlesRakeListTemplate
+ {
+ CreationTime = x.CreationTime,
+ FinishTime = x.FinishTime,
+ OrderNo = x.OrderNo,
+ PayAmount = x.PayAmount,
+ ChannlesRakeRate = x.ChannlesRakeRate,
+ ChannlesRakePrice = x.ChannlesRakePrice
+ }).OrderByDescending(r => r.CreationTime).ToListAsync();
+ var i = 0;
+ result.ForEach(s =>
+ {
+ s.SerialNumber = ++i;
+ s.CreationTimeStr = s.CreationTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
+ s.PayAmountStr = s.PayAmount.ToString("F2");
+ s.ChannlesRakeRateStr = s.ChannlesRakeRate.ToString("F0") + "%";
+ s.ChannlesRakePriceStr = s.ChannlesRakePrice.ToString("F2");
+ s.FinishTimeStr = s.FinishTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss);
+ });
return result;
}
+ #endregion
+ #region 鎿嶄綔
/// <summary>
/// 缂栬緫鍏呭�兼祦姘�
@@ -105,43 +248,6 @@
}
/// <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>
/// <param name="input"></param>
@@ -155,11 +261,9 @@
var data = new LifePayExpensesReceipts()
{
Id = Guid.NewGuid(),
- OrderNo = input.OrderNo,
OutOrderNo = input.OutOrderNo,
LifePayType = input.LifePayType,
ExpensesReceiptsType = input.ExpensesReceiptsType,
- Amount = input.Amount,
};
switch (input.LifePayType)
@@ -171,18 +275,22 @@
if (query.Code == AlipayResultCode.Success && (query.TradeStatus == AlipayStatus.TRADESUCCESS
|| query.TradeStatus == AlipayStatus.TRADECLOSED))
{
+ data.OrderNo = input.OrderNo;
data.ExtraProperties = JsonConvert.SerializeObject(query);
data.FinishTime = Convert.ToDateTime(query.SendPayDate);
+ data.Amount = Convert.ToDecimal(query.TotalAmount);
await _lifePayExpensesReceiptsRepository.InsertAsync(data);
}
}
else
{
- var query = await _aliPayApi.QueryAlipayTradeRefund(new OrderInQuiryInput() { OutTradeNo = input.OrderNo });
+ var query = await _aliPayApi.QueryAlipayTradeRefund(new OrderInQuiryInput() { OutTradeNo = input.OrderNo, OutRefundNo = input.OutRefundNo });
if (query.Code == AlipayResultCode.Success && query.RefundStatus == AlipayRefundStatus.Success)
{
+ data.OrderNo = input.OutRefundNo;
data.ExtraProperties = JsonConvert.SerializeObject(query);
data.FinishTime = Convert.ToDateTime(query.GmtRefundPay);
+ data.Amount = Convert.ToDecimal(query.RefundAmount);
await _lifePayExpensesReceiptsRepository.InsertAsync(data);
}
}
@@ -193,6 +301,7 @@
var query = await _wxPayApi.WxPayTradeQuery(input.OrderNo);
if (query.TradeState == WxPayStatus.鏀粯鎴愬姛 || query.TradeState == WxPayStatus.杞叆閫�娆�)
{
+ data.OrderNo = input.OrderNo;
data.ExtraProperties = JsonConvert.SerializeObject(query);
data.FinishTime = Convert.ToDateTime(query.SuccessTime);
await _lifePayExpensesReceiptsRepository.InsertAsync(data);
@@ -200,9 +309,10 @@
}
else
{
- var query = await _wxPayApi.WxPayDomesticRefundsQuery(input.OrderNo);
+ var query = await _wxPayApi.WxPayDomesticRefundsQuery(input.OutRefundNo);
if (query.Status == WxPayRefundStatus.閫�娆炬垚鍔�)
{
+ data.OrderNo = input.OutRefundNo;
data.ExtraProperties = JsonConvert.SerializeObject(query);
data.FinishTime = Convert.ToDateTime(query.SuccessTime);
await _lifePayExpensesReceiptsRepository.InsertAsync(data);
@@ -211,6 +321,33 @@
break;
default: break;
}
+ }
+ }
+
+ /// <summary>
+ /// 缁熻鎵�鏈夋秷璐规祦姘�
+ /// </summary>
+ /// <returns></returns>
+ public async Task GetAllLifePayConsumption()
+ {
+ var orderList = await _lifePayOrderRepository.Where(x => x.PayStatus == LifePayStatusEnum.宸叉敮浠�).ToListAsync();
+
+ foreach (var item in orderList)
+ {
+ LifePayConsumption lifePayConsumption = new LifePayConsumption()
+ {
+ OrderNo = item.OrderNo,
+ OutOrderNo = item.OutOrderNo,
+ //Amount = item.PayAmount,
+
+ };
+ //switch (item.ACOOLYStatus)
+ //{
+ // case ACOOLYStatusEnum.鍏呭�间腑:
+
+ // break;
+ // default:break;
+ //}
}
}
@@ -247,19 +384,74 @@
/// 鍑鸿处
if (item.RefundOrderNo.IsNotNullOrEmpty())
{
- if (input.LifePayType == LifePayTypeEnum.WxPay)
- {
- input.OrderNo = item.RefundOrderNo;
- }
+ input.OutRefundNo = item.OrderNo;
+ input.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts;
+ await AddLifePayExpensesReceipts(input);
+ input.OutRefundNo = item.RefundOrderNo;
input.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts;
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);
+ }
+ }
+ }
+ }
+ #endregion
+
+ #region 绉佹湁
+ private async Task<IQueryable<LifePayChannlesRakeListOutput>> GetLifePayChannlesRakeListFilter(LifePayChannlesRakePageInput input)
+ {
+ var list = _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,
+ });
+
+
+ return list;
+ }
+ #endregion
+
}
}
--
Gitblit v1.9.1