From 65e7b312659c358970262b027901bb55d764f0f9 Mon Sep 17 00:00:00 2001 From: zhengyuxuan <zhengyuxuan1995> Date: 星期日, 30 三月 2025 07:32:35 +0800 Subject: [PATCH] fix:拉取收支流水 --- LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml | 45 +++++++++ LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs | 41 +++++-- LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs | 43 ++++++++ LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayOrderService.cs | 2 LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs | 18 ++ LifePayment/LifePayment.Domain/WeChat/WxPayApi.cs | 14 ++ LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs | 55 +++++++++++ LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs | 19 +++ LifePayment/LifePayment.Domain/WeChat/IWxPayApi.cs | 2 LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs | 2 LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml | 14 ++ LifePayment/LifePayment.Application/LifePay/LifePayService.cs | 5 LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs | 2 13 files changed, 233 insertions(+), 29 deletions(-) diff --git a/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayOrderService.cs b/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayOrderService.cs index 788c88e..b902588 100644 --- a/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayOrderService.cs +++ b/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayOrderService.cs @@ -14,5 +14,7 @@ Task AddUpdatePayRechargeReceipts(AddUpdatePayRechargeReceiptsInput input); + Task<LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input); + Task AddLifePayExpensesReceipts(AddLifePayExpensesReceiptsInput input); } \ No newline at end of file diff --git a/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs b/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs index 17f30cc..005fcfe 100644 --- a/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs +++ b/LifePayment/LifePayment.Application.Contracts/LifePay/ILifePayService.cs @@ -298,7 +298,7 @@ /// </summary> /// <param name="outTradeNo"></param> /// <returns></returns> - Task WxPayTradeQuery(string outTradeNo); + Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo); /// <summary> /// 璁剧疆鐢熸椿缂磋垂鏀粯绫诲瀷 diff --git a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs index 30d9f45..26f29d0 100644 --- a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs +++ b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayInput.cs @@ -683,12 +683,22 @@ public string? KeyWord { get; set; } /// <summary> - /// 璁拌处寮�濮嬫椂闂� + /// 鏀粯娓犻亾 /// </summary> - public DateTime? CreationTimeBegin { get; set; } + public LifePayTypeEnum? LifePayType { get; set; } /// <summary> - /// 璁拌处缁撴潫鏃堕棿 + /// 鏀舵敮绫诲瀷 /// </summary> - public DateTime? CreationTimeEnd { get; set; } + public ExpensesReceiptsTypeEnum? ExpensesReceiptsType { get; set; } + + /// <summary> + /// 浜ゆ槗寮�濮嬫椂闂� + /// </summary> + public DateTime? TimeBegin { get; set; } + + /// <summary> + /// 浜ゆ槗缁撴潫鏃堕棿 + /// </summary> + public DateTime? TimeEnd { get; set; } } \ No newline at end of file diff --git a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs index 1828a28..a0614f0 100644 --- a/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs +++ b/LifePayment/LifePayment.Application.Contracts/LifePay/LifePayOutput.cs @@ -1182,6 +1182,11 @@ public class LifePayExpensesReceiptsListOutput { /// <summary> + /// 缂栧彿 + /// </summary> + public Guid Id { get; set; } + + /// <summary> /// 骞冲彴璁㈠崟鍙� /// </summary> public string OrderNo { get; set; } @@ -1217,7 +1222,17 @@ public List<T> Data { get; set; } = new List<T>(); /// <summary> - /// 绱鍏呭�� + /// 绱鏀跺叆 /// </summary> - public decimal TotalRechargeAmount { get; set; } + public decimal TotalIncome { get; set; } + + /// <summary> + /// 绱閫�娆� + /// </summary> + public decimal TotalRefund { get; set; } + + /// <summary> + /// 瀹為檯鏀跺叆 + /// </summary> + public decimal RealIncome { get; set; } } \ No newline at end of file diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs index ce4d0c2..f199443 100644 --- a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs +++ b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs @@ -101,28 +101,40 @@ } } - + /// <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)) - .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin) - .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd) - .Select(x => new LifePayRechargeReceiptsListOutput() + .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, - //RechargeAmount = x.RechargeAmount, - //Remark = x.Remark, - //Voucher = x.Voucher.GetOssPath(), - CreationTime = x.CreationTime, + OutOrderNo = x.OutOrderNo, + LifePayType = x.LifePayType, + ExpensesReceiptsType = x.ExpensesReceiptsType, + Amount = x.Amount, + FinishTime = x.FinishTime }) .GetPageResult(input.PageModel); - var total = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount); + 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.TotalRechargeAmount = total; + result.Data = list.Data; + result.TotalIncome = totalIncome; + result.TotalRefund = totalRefund; + result.RealIncome = totalIncome - totalRefund; return result; } @@ -153,7 +165,8 @@ if (input.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses) { var query = await _aliPayApi.OrderInQuiry(new OrderInQuiryInput() { OutTradeNo = input.OrderNo }); - if (query.Code == AlipayResultCode.Success && query.TradeStatus == AlipayStatus.TRADESUCCESS) + if (query.Code == AlipayResultCode.Success && (query.TradeStatus == AlipayStatus.TRADESUCCESS + || query.TradeStatus == AlipayStatus.TRADECLOSED)) { data.ExtraProperties = JsonConvert.SerializeObject(query); data.FinishTime = Convert.ToDateTime(query.SendPayDate); @@ -175,7 +188,7 @@ if (input.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses) { var query = await _wxPayApi.WxPayTradeQuery(input.OrderNo); - if (query.Code == AlipayResultCode.Success && query.Status == WxPayStatus.鏀粯鎴愬姛) + if (query.TradeState == WxPayStatus.鏀粯鎴愬姛 || query.TradeState == WxPayStatus.杞叆閫�娆�) { data.ExtraProperties = JsonConvert.SerializeObject(query); data.FinishTime = Convert.ToDateTime(query.SuccessTime); diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs index 8403c87..4d09890 100644 --- a/LifePayment/LifePayment.Application/LifePay/LifePayService.cs +++ b/LifePayment/LifePayment.Application/LifePay/LifePayService.cs @@ -829,6 +829,7 @@ public async Task<AlipayTradeQueryResponse> QueryAlipayTrade(OrderInQuiryInput input) { var result = await _aliPayApi.OrderInQuiry(input); + return result; } @@ -858,9 +859,9 @@ /// </summary> /// <param name="outTradeNo"></param> /// <returns></returns> - public async Task WxPayTradeQuery(string outTradeNo) + public async Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo) { - await _wxPayApi.WxPayTradeQuery(outTradeNo); + return await _wxPayApi.WxPayTradeQuery(outTradeNo); } #endregion diff --git a/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs b/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs index d6e27cb..aa7070d 100644 --- a/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs +++ b/LifePayment/LifePayment.Domain.Shared/LifePaymentConstant.cs @@ -53,7 +53,7 @@ public const string PayTransactionsH5 = "/v3/pay/transactions/h5"; - public const string WxPayTradeQyery = "/v3/pay/transactions/out-trade-no/{0}"; + public const string WxPayTradeQyery = "/v3/pay/transactions/out-trade-no/{0}?mchid={1}"; public const string WxPayDomesticRefunds = "/v3/refund/domestic/refunds"; diff --git a/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs b/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs index 9c8ac08..c1266ee 100644 --- a/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs +++ b/LifePayment/LifePayment.Domain.Shared/WeChat/WxPayPostBaseModel.cs @@ -882,4 +882,59 @@ public Model_WxPayDomesticRefunds_Amount Amount { get; set; } } + public class WxPayTradeQueryReponse + { + /// <summary> + /// 杩斿洖缁撴灉 + /// </summary> + [JsonProperty("code")] + public string Code { get; set; } + + /// <summary> + /// 杩斿洖淇℃伅 + /// </summary> + [JsonProperty("message")] + public string Message { get; set; } + + /// <summary> + /// 鍟嗘埛璁㈠崟鍙� + /// </summary> + [JsonProperty("out_trade_no")] + public string OutTradeNo { get; set; } + + /// <summary> + /// 寰俊鏀粯璁㈠崟鍙� + /// </summary> + [JsonProperty("transaction_id")] + public string TransactionId { get; set; } + + /// <summary> + /// 浜ゆ槗绫诲瀷 + /// </summary> + [JsonProperty("trade_type")] + public string TradeType { get; set; } + + + /// <summary> + /// 浜ゆ槗鐘舵�� + /// </summary> + [JsonProperty("trade_state")] + public string TradeState { get; set; } + + /// <summary> + /// 浜ゆ槗鐘舵�佹弿杩� + /// </summary> + [JsonProperty("trade_state_desc")] + public string TradeStateDesc { get; set; } + + + [JsonProperty("success_time ")] + public string SuccessTime { get; set; } + + // <summary> + /// 閲戦淇℃伅 + /// </summary> + [JsonProperty("amount")] + public Model_WxPayDomesticRefunds_Amount Amount { get; set; } + } } \ No newline at end of file diff --git a/LifePayment/LifePayment.Domain/WeChat/IWxPayApi.cs b/LifePayment/LifePayment.Domain/WeChat/IWxPayApi.cs index def0a92..c865b61 100644 --- a/LifePayment/LifePayment.Domain/WeChat/IWxPayApi.cs +++ b/LifePayment/LifePayment.Domain/WeChat/IWxPayApi.cs @@ -26,7 +26,7 @@ Task<WxPayDomesticRefundsQueryReponse> WxPayDomesticRefundsQuery(string outTradeNo); - Task<WxPayDomesticRefundsQueryReponse> WxPayTradeQuery(string outTradeNo); + Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo); Task<WxPayTradeBillApplyReponse> WxPayTradeBillApply(WxPayTradeBillApplyRequest input); diff --git a/LifePayment/LifePayment.Domain/WeChat/WxPayApi.cs b/LifePayment/LifePayment.Domain/WeChat/WxPayApi.cs index d6f6097..f4bafa1 100644 --- a/LifePayment/LifePayment.Domain/WeChat/WxPayApi.cs +++ b/LifePayment/LifePayment.Domain/WeChat/WxPayApi.cs @@ -1,4 +1,5 @@ 锘縰sing LifePayment.Domain.Shared; +using Microsoft.Extensions.Options; using System.Threading.Tasks; using ZeroD.Util.Fadd; @@ -6,6 +7,13 @@ { public class WxPayApi : WxClient, IWxPayApi { + private readonly WxPayOption _wxPayOptions; + + public WxPayApi(IOptions<WxPayOption> wxPayOptions) + { + _wxPayOptions = wxPayOptions.Value; + } + public async Task<PayTransactionsNativeReponse> PayTransactionsNative(PayTransactionsNativeInput input) { var result = await PostAsync<PayTransactionsNativeInput, PayTransactionsNativeReponse>(input, LifePaymentConstant.PayTransactionsNative); @@ -43,10 +51,10 @@ return result; } - public async Task<WxPayDomesticRefundsQueryReponse> WxPayTradeQuery(string outTradeNo) + public async Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo) { - var url = $"{string.Format(LifePaymentConstant.WxPayTradeQyery, outTradeNo)}"; - var result = await Certificates<WxPayDomesticRefundsQueryReponse>(url); + var url = $"{string.Format(LifePaymentConstant.WxPayTradeQyery, outTradeNo, _wxPayOptions.Mchid)}"; + var result = await Certificates<WxPayTradeQueryReponse>(url); return result; } diff --git a/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml b/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml index 348afee..9bb9d5f 100644 --- a/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml +++ b/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml @@ -267,6 +267,13 @@ <param name="input"></param> <returns></returns> </member> + <member name="M:LifePayment.HttpApi.LifePayController.GetLifePayExpensesReceiptsPage(LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput)"> + <summary> + 鑾峰彇鏀舵敮娴佹按鍒嗛〉鏁版嵁 + </summary> + <param name="input"></param> + <returns></returns> + </member> <member name="M:LifePayment.HttpApi.LifePayController.QueryAlipayTrade(LifePayment.Domain.Shared.OrderInQuiryInput)"> <summary> 鏌ヨ鏀粯瀹濇敮浠樿鍗曚俊鎭� @@ -288,6 +295,13 @@ <param name="outTradeNo"></param> <returns></returns> </member> + <member name="M:LifePayment.HttpApi.LifePayController.WxPayTradeQuery(System.String)"> + <summary> + 鏌ヨ寰俊璁㈠崟淇℃伅 + </summary> + <param name="outTradeNo"></param> + <returns></returns> + </member> <member name="M:LifePayment.HttpApi.LifePayController.CreateLifePayPhoneOrder(LifePayment.Application.Contracts.CreateLifePayOrderInput{LifePayment.Application.Contracts.LifePhoneData})"> <summary> 鍒涘缓鐢熸椿缂磋垂璇濊垂璁㈠崟 diff --git a/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml b/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml index f850522..e3c5027 100644 --- a/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml +++ b/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml @@ -781,6 +781,31 @@ 鎷撳睍灞炴�� </summary> </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput.KeyWord"> + <summary> + 鏌ヨ鏉′欢 + </summary> + </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput.LifePayType"> + <summary> + 鏀粯娓犻亾 + </summary> + </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput.ExpensesReceiptsType"> + <summary> + 鏀舵敮绫诲瀷 + </summary> + </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput.TimeBegin"> + <summary> + 浜ゆ槗寮�濮嬫椂闂� + </summary> + </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageInput.TimeEnd"> + <summary> + 浜ゆ槗缁撴潫鏃堕棿 + </summary> + </member> <member name="P:LifePayment.Application.Contracts.LifePayIntroInfoInput.LifePayType"> <summary> 鐢熸椿缂磋垂绫诲瀷 @@ -1676,6 +1701,11 @@ 娓犻亾鍙� </summary> </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsListOutput.Id"> + <summary> + 缂栧彿 + </summary> + </member> <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsListOutput.OrderNo"> <summary> 骞冲彴璁㈠崟鍙� @@ -1706,6 +1736,21 @@ 浜ゆ槗鏃堕棿 </summary> </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageOutput`1.TotalIncome"> + <summary> + 绱鏀跺叆 + </summary> + </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageOutput`1.TotalRefund"> + <summary> + 绱閫�娆� + </summary> + </member> + <member name="P:LifePayment.Application.Contracts.LifePayExpensesReceiptsPageOutput`1.RealIncome"> + <summary> + 瀹為檯鏀跺叆 + </summary> + </member> <member name="P:LifePayment.Application.Contracts.RecordOperateHistoryEto.RelationId"> <summary> 鍏宠仈鍏崇郴ID diff --git a/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs b/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs index 9cef37a..434d829 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs +++ b/LifePayment/LifePayment.HttpApi/LifePay/LifePayController.cs @@ -443,6 +443,17 @@ } /// <summary> + /// 鑾峰彇鏀舵敮娴佹按鍒嗛〉鏁版嵁 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + public async Task<LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input) + { + return await _lifePayOrderService.GetLifePayExpensesReceiptsPage(input); + } + + /// <summary> /// 鏌ヨ鏀粯瀹濇敮浠樿鍗曚俊鎭� /// </summary> /// <param name="input"></param> @@ -451,7 +462,16 @@ [AllowAnonymous] public async Task<Alipay.EasySDK.Payment.Common.Models.AlipayTradeQueryResponse> QueryAlipayTrade(OrderInQuiryInput input) { - return await _lifePayService.QueryAlipayTrade(input); + var res = await _lifePayService.QueryAlipayTrade(input); + //await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() + //{ + // OrderNo = input.OutTradeNo, + // OutOrderNo = res.TradeNo, + // LifePayType = LifePayTypeEnum.AliPay, + // ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, + // Amount = Convert.ToDecimal(res.ReceiptAmount) + //}); + return res; } /// <summary> @@ -478,6 +498,27 @@ return await _lifePayService.WxPayDomesticRefundsQuery(outTradeNo); } + /// <summary> + /// 鏌ヨ寰俊璁㈠崟淇℃伅 + /// </summary> + /// <param name="outTradeNo"></param> + /// <returns></returns> + [HttpGet] + [AllowAnonymous] + public async Task<WxPayTradeQueryReponse> WxPayTradeQuery(string outTradeNo) + { + var res = await _lifePayService.WxPayTradeQuery(outTradeNo); + await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() + { + OrderNo = res.OutTradeNo, + OutOrderNo = res.TransactionId, + LifePayType = LifePayTypeEnum.WxPay, + ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, + Amount = Convert.ToDecimal(res.Amount.Total) + }); + return res; + } + #endregion #region 鎿嶄綔 -- Gitblit v1.9.1