protected override void Execute(object state) { var model = state as VisitingOrderLateNoPaymentModel; if (null == model) { return; } try { //从备份区将备份删除 DeleteBackAfterDone(model.OrderID); var lastOrder = AppointOrderProvider.GetAppointOrder(model.OrderID); if (null == lastOrder) { throw new CustomException(string.Format("〖上门订单(ID:{0})〗信息已不存在!", model.OrderID)); } bool statusRight = false; if (lastOrder.QuoteWays == (int)BusinessServiceQuote.WhenOrder && lastOrder.Status == (int)VisitingServiceOrderStatus.WaitingMerchantReceive && !lastOrder.PaiedTime.HasValue) { statusRight = true; } else if (lastOrder.QuoteWays == (int)BusinessServiceQuote.WhenMeeting && lastOrder.Status == (int)VisitingServiceOrderStatus.UserConfirmQuote && !lastOrder.PaiedTime.HasValue) { statusRight = true; } if (!statusRight) { throw new CustomException(string.Format("〖上门订单(ID:{0})〗状态已发生变更,不能自动完成收货!", lastOrder.OrderID)); } //自动取消订单 bool success = AppointOrderProvider.AutoCancelOrder(lastOrder.OrderID); string message = string.Empty; if (success) { message = string.Format("〖上门订单(ID:{0}/{1})〗因超时未付款,系统已自动取消订单!", lastOrder.OrderID, lastOrder.BusinessName); } else { message = string.Format("〖上门订单(ID:{0}/{1})〗因超时未付款,系统自动取消订单时操作失败!", lastOrder.OrderID, lastOrder.BusinessName); } RunLogger(message); } catch (Exception ex) { this.OnThrowException(ex); } finally { Schedulers.Remove(model.OrderID); } }