/// <summary> /// 再次同步支付结果 /// </summary> /// <param name="orderId"></param> /// <param name="payTime"></param> /// <returns></returns> public static void AgainSyncPayResult(decimal orderId, DateTime payTime) { lock (order_lock) { IOnlineOrder factory = OnlineOrderFactory.GetFactory(); OnlineOrder order = factory.QueryByOrderId(orderId); if (order.Status == OnlineOrderStatus.SyncPayResultFail) { using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); bool result = factory.SyncPayResultSuccess(orderId, dbOperator); if (!result) { throw new MyException("更改同步成功状态失败"); } string payDetailId = string.Empty; bool noticePayResult = SyncNoticePayResult(orderId, payTime, order, out payDetailId); if (!noticePayResult) { throw new MyException("同步支付结果失败"); } dbOperator.CommitTransaction(); UpdateSyncResultTimes(order.OrderID, payDetailId); SendSyncResultMessage(order); } catch (MyException ex) { dbOperator.RollbackTransaction(); factory.SyncPayResultFail(order.OrderID, ex.Message); } catch (Exception ex) { dbOperator.RollbackTransaction(); factory.SyncPayResultFail(orderId, "同步支付结果异常"); string message = string.Format("【{0}】再次同步支付结果,订单编号:{1},描述:{2}", order.PaymentChannel.GetDescription(), order.OrderTime, ex.Message); ExceptionsServices.AddExceptionToDbAndTxt("OnlineOrderServices", message, ex, LogFrom.WeiXin); } } } } }
private static bool NoticePaymentResult(OnlineOrder order) { if (order.Status != OnlineOrderStatus.PaySuccess) { TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "【通知支付结果】订单不是已支付状态,订单编号:{0},支付账号:{1}", order.OrderID, order.PayAccount); return(false); } bool noticePayResult = false; IOnlineOrder factory = OnlineOrderFactory.GetFactory(); using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); bool result = factory.SyncPayResultSuccess(order.OrderID, dbOperator); if (!result) { throw new MyException("更改同步成功状态失败"); } string payDetailId = string.Empty; noticePayResult = SyncNoticePayResult(order.OrderID, order.RealPayTime, order, out payDetailId); if (!noticePayResult) { throw new MyException("同步支付结果失败"); } dbOperator.CommitTransaction(); factory.UpdateSyncResultTimes(order.OrderID, payDetailId); SendSyncResultMessage(order); return(true); } catch (MyException ex) { dbOperator.RollbackTransaction(); factory.SyncPayResultFail(order.OrderID, ex.Message); return(false); } catch (Exception ex) { dbOperator.RollbackTransaction(); factory.SyncPayResultFail(order.OrderID, "同步支付结果异常"); TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "【{0}】支付账号{3},订单编号:{1},描述:{2}", order.PaymentChannel.GetDescription(), order.OrderID, ex.Message, order.PayAccount); return(false); } } }