| | |
| | | order.OutRequestNo = result.RequestNo.IsNullOrEmpty() ? null : result.RequestNo; |
| | | order.ACOOLYOrderNo = result.ACOOLYOrderNo; |
| | | order.ACOOLYStatus = ACOOLYStatusEnum.充值中; |
| | | await _lifePayOrderRepository.UpdateAsync(order); |
| | | _logger.LogInformation("生活缴费订单:" + order.ToJson()); |
| | | |
| | | /// 创建生活缴费消费记录 |
| | |
| | | order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; |
| | | order.ACOOLYStatus = ACOOLYStatusEnum.充值失败; |
| | | order.RefundApplyRemark = ex.Message; |
| | | await _lifePayOrderRepository.UpdateAsync(order); |
| | | _logger.LogError("生活缴费订单状态:" + order.LifePayOrderStatus.ToString()); |
| | | } |
| | | _logger.LogError("生活缴费订单状态:" + order.LifePayOrderStatus.ToString()); |
| | | await _lifePayOrderRepository.UpdateAsync(order); |
| | | } |
| | | |
| | | public async Task LifePayRefundsHandler(string orderNo, LifePayRefundStatusEnum refundStatus) |
| | |
| | | /// <returns></returns> |
| | | public async Task ACOOLYOrderNotifyHandler(string orderNo, string acoolyOrderNo, LifePayOrderStatusEnum status, ACOOLYStatusEnum acoolyStatus, decimal payAmount, string refundApplyRemark, decimal? parValue = 0, decimal? actualParValue = 0) |
| | | { |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{orderNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{orderNo} - {orderLock != null}"); |
| | | |
| | | var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); |
| | | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在"); |
| | | |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{orderNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{orderNo} - {orderLock != null}"); |
| | | |
| | | if (order.ACOOLYStatus.HasValue && (int)order.ACOOLYStatus > (int)acoolyStatus) |
| | | { |
| | |
| | | order.RefundPrice = Math.Round((1 - ((order.ActualReceivedAmount ?? 0) / (order.RechargeAmount ?? 0))) * (order.PayAmount ?? 0), 2); |
| | | } |
| | | |
| | | await _lifePayOrderRepository.UpdateAsync(order); |
| | | |
| | | if (order.LifePayOrderStatus == LifePayOrderStatusEnum.已完成) |
| | | { |
| | | ///结算渠道佣金 |
| | |
| | | /// 创建生活缴费消费记录 |
| | | await _lifePayOrderService.CreatLifePayConsumption(acoolyStatus, order.OrderNo, order.ACOOLYOrderNo, |
| | | order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime, order.ChannleRate, parValue, actualParValue); |
| | | |
| | | await CurrentUnitOfWork.SaveChangesAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | using System; |
| | | using System.IO; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using Volo.Abp; |
| | | using Volo.Abp.AspNetCore.Mvc; |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [UnitOfWork] |
| | | [AllowAnonymous] |
| | | public async Task ACOOLYNotify() |
| | | { |
| | | _logger.LogError("ACOOLY回调通知开始进入"); |
| | | Thread.Sleep(200); |
| | | var body = string.Empty; |
| | | using (var reader = new StreamReader(Request.Body, Encoding.UTF8)) |
| | | { |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [UnitOfWork] |
| | | public async Task<ContentResult> AliRechargeNotify() |
| | | { |
| | | _logger.LogError($"生活管家支付宝充值回调通知:进入支付宝回调"); |
| | |
| | | //var serializeRequest = "{\"gmt_create\":\"2025-02-25 13:18:59\",\"charset\":\"UTF-8\",\"seller_email\":\"zfb1@818nb.com\",\"subject\":\"生活缴费-话费\",\"sign\":\"Sp06G1GxrAfDvoHPz9l3DJ20SxhvRzEGFeCGu4LHrSWmEG4OY7MHMx+iJi54ETbdXV0YsyDH9JZD7PWN3HCpEq/wGO4Wh4VSYSe7lqxD6r4f/HFiB0YlrdQoSzjZgYPzLjy6bcdlKRRHOeDkgs2i7TfvIsxWxHs9t0xuS0RlkpdZfb7d7m0EuZ/3v2Cbsj5AHjxb1S2PkO0oQyriYgGQdmkPqILZHwieST+tNEHS4dGFKYu2nkfctAGjWIDv/hKQNY7jEUxsEeG0SnK4TPU8zNplFR9/aKM0Wfwp1pdlaiP2u/d8vOtNh5q+emvaYbKrUkIEFBok8pDLNDta7ZjtVw==\",\"invoice_amount\":\"0.01\",\"buyer_open_id\":\"071xYXDfXBLAI9U11jg_WrH1K6hWq8HYGz0u85xBivf3Sce\",\"notify_id\":\"2025022501222131904087711494539601\",\"fund_bill_list\":\"[{\\\"amount\\\":\\\"0.01\\\",\\\"fundChannel\\\":\\\"ALIPAYACCOUNT\\\"}]\",\"notify_type\":\"trade_status_sync\",\"trade_status\":\"TRADE_SUCCESS\",\"receipt_amount\":\"0.01\",\"buyer_pay_amount\":\"0.01\",\"app_id\":\"2021004171602214\",\"sign_type\":\"RSA2\",\"seller_id\":\"2088050542042301\",\"gmt_payment\":\"2025-02-25 13:19:03\",\"notify_time\":\"2025-02-25 13:44:34\",\"merchant_app_id\":\"2021004171602214\",\"version\":\"1.0\",\"out_trade_no\":\"JF202502251318555214671\",\"total_amount\":\"0.01\",\"trade_no\":\"2025022522001487711401331043\",\"auth_app_id\":\"2021004171602214\",\"buyer_logon_id\":\"130****2238\",\"point_amount\":\"0.00\"}"; |
| | | var input = JsonConvert.DeserializeObject<AliRechargeNotifyInput>(serializeRequest); |
| | | |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{input.OutTradeNo} - {orderLock != null}"); |
| | | |
| | | if (input.OutTradeNo.Contains("JF")) |
| | | { |
| | | if (input.TradeStatus == LifePaymentConstant.AliPayStatus.支付成功 && input.OutBizNo.IsNullOrEmpty()) |
| | | { |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{input.OutTradeNo} - {orderLock != null}"); |
| | | |
| | | await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo); |
| | | // 插入收支流水 |
| | | await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() |
| | |
| | | LifePayType = LifePayTypeEnum.AliPay, |
| | | ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses |
| | | }); |
| | | await CurrentUnitOfWork.SaveChangesAsync(); |
| | | } |
| | | else if (((input.TradeStatus == LifePaymentConstant.AliPayStatus.支付成功 || input.TradeStatus == LifePaymentConstant.AliPayStatus.超时关闭) |
| | | && input.OutBizNo.IsNotNullOrEmpty() |
| | | && (input.RefundFee.HasValue && input.RefundFee > 0))) |
| | | { |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{input.OutTradeNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{input.OutTradeNo} - {orderLock != null}"); |
| | | |
| | | await _lifePayService.LifePayRefundsHandler(input.OutTradeNo, LifePayRefundStatusEnum.已退款); |
| | | // 插入收支流水 |
| | | await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() |
| | |
| | | LifePayType = LifePayTypeEnum.AliPay, |
| | | ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts |
| | | }); |
| | | await CurrentUnitOfWork.SaveChangesAsync(); |
| | | } |
| | | } |
| | | else |
| | |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [UnitOfWork] |
| | | public async Task<WxRechargeNotifyResult> WxRechargeNotify(WxRechargeNotifyInput input) |
| | | { |
| | | try |
| | |
| | | _logger.LogInformation($"生活管家微信充值回调通知data:" + data); |
| | | var wxPayNotice = JsonConvert.DeserializeObject<WxPayNotice>(data); |
| | | |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{wxPayNotice.OutTradeNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{wxPayNotice.OutTradeNo} - {orderLock != null}"); |
| | | |
| | | if (wxPayNotice.OutTradeNo.Contains("JF")) |
| | | { |
| | | if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功) |
| | | { |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{wxPayNotice.OutTradeNo}", TimeSpan.FromSeconds(60)); |
| | | _logger.LogInformation($"锁:LockKey:UpdateOrder:{wxPayNotice.OutTradeNo} - {orderLock != null}"); |
| | | |
| | | var key = $"WxRechargeNotify_{wxPayNotice.OutTradeNo}"; |
| | | if (string.IsNullOrWhiteSpace(distributedCache.Get(key))) |
| | |
| | | { |
| | | AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) |
| | | }); |
| | | |
| | | await CurrentUnitOfWork.SaveChangesAsync(); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | await CurrentUnitOfWork.RollbackAsync(); |
| | | return new WxRechargeNotifyResult |
| | | { |
| | | Code = "FAIL", |
| | |
| | | public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) |
| | | { |
| | | await context.AddBackgroundWorkerAsync<GetStaticsWorker>(); |
| | | await context.AddBackgroundWorkerAsync<CheckUnPayOrderWork>(); |
| | | //await context.AddBackgroundWorkerAsync<CheckUnPayOrderWork>();s |
| | | } |
| | | |
| | | private void ConfigurePays(ServiceConfigurationContext context, IConfiguration configuration) |
| | |
| | | IAbpDistributedLock distributedLock, |
| | | IRepository<LifePayOrder, Guid> lifePayOrderRepository) : base(timer, serviceScopeFactory) |
| | | { |
| | | timer.Period = (int)TimeSpan.FromSeconds(5).TotalMilliseconds; |
| | | timer.Period = (int)TimeSpan.FromMinutes(30).TotalMilliseconds; |
| | | this.logger = logger; |
| | | this.lifePayOrderService = lifePayOrderService; |
| | | this.lifePayService = lifePayService; |
| | |
| | | try |
| | | { |
| | | Logger.LogInformation($"检查未支付订单状态开始: {DateTime.Now}"); |
| | | var end = DateTime.Now; |
| | | var start = end.AddMinutes(-15); |
| | | var orders = lifePayOrderRepository.Where(it => it.PayStatus == LifePayStatusEnum.未支付 && it.CreationTime >= start && it.CreationTime <= end).ToList(); |
| | | foreach (var order in orders) |
| | | { |
| | | await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{order.OrderNo}", TimeSpan.FromSeconds(60)); |
| | | logger.LogInformation($"锁:LockKey:UpdateOrder:{order.OrderNo} - {orderLock != null}"); |
| | | //var end = DateTime.Now; |
| | | //var start = end.AddMinutes(-45); |
| | | //end = end.AddMinutes(-15); |
| | | //var orders = lifePayOrderRepository.Where(it => it.PayStatus == LifePayStatusEnum.未支付 && it.CreationTime >= start && it.CreationTime <= end).ToList(); |
| | | //foreach (var order in orders) |
| | | //{ |
| | | // await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{order.OrderNo}", TimeSpan.FromSeconds(60)); |
| | | // logger.LogInformation($"锁:LockKey:UpdateOrder:{order.OrderNo} - {orderLock != null}"); |
| | | |
| | | Logger.LogInformation($"订单:{order.OrderNo}-{order.ToJson()}"); |
| | | var wxPayNotice = await lifePayService.WxPayTradeQuery(order.OrderNo); |
| | | var json = wxPayNotice.ToJson(); |
| | | Logger.LogInformation($"订单({wxPayNotice.OutTradeNo})信息: {json}"); |
| | | if (wxPayNotice.OutTradeNo.Contains("JF") && wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功) |
| | | { |
| | | await lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId); |
| | | // Logger.LogInformation($"订单:{order.OrderNo}-{order.ToJson()}"); |
| | | // var wxPayNotice = await lifePayService.WxPayTradeQuery(order.OrderNo); |
| | | // var json = wxPayNotice.ToJson(); |
| | | // Logger.LogInformation($"订单({wxPayNotice.OutTradeNo})信息: {json}"); |
| | | // if (wxPayNotice.OutTradeNo.Contains("JF") && wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功) |
| | | // { |
| | | // await lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId); |
| | | |
| | | // 插入收支流水 |
| | | await lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() |
| | | { |
| | | OrderNo = wxPayNotice.OutTradeNo, |
| | | OutOrderNo = wxPayNotice.TransactionId, |
| | | LifePayType = LifePayTypeEnum.WxPay, |
| | | ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, |
| | | Amount = wxPayNotice.Amount.Total |
| | | }); |
| | | // // 插入收支流水 |
| | | // await lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() |
| | | // { |
| | | // OrderNo = wxPayNotice.OutTradeNo, |
| | | // OutOrderNo = wxPayNotice.TransactionId, |
| | | // LifePayType = LifePayTypeEnum.WxPay, |
| | | // ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, |
| | | // Amount = wxPayNotice.Amount.Total |
| | | // }); |
| | | |
| | | Logger.LogInformation("已改为支付成功"); |
| | | } |
| | | else |
| | | { |
| | | Logger.LogInformation("未更新"); |
| | | } |
| | | } |
| | | // Logger.LogInformation("已改为支付成功"); |
| | | // } |
| | | // else |
| | | // { |
| | | // Logger.LogInformation("未更新"); |
| | | // } |
| | | //} |
| | | } |
| | | catch (Exception ex) |
| | | { |