public TResult PayOrder(OrderCreateModel order) { var result = new TResult(); if (order.TicketItem.Count <= 0) { return(result.ErrorResult("请选择您要购买的产品")); } var userInfo = _enterpriseUserService.LoginForSession(); var orderInfo = new OrderInfoCreateModel { PayType = order.PayType, UserId = userInfo.UserId, ValidityDate = order.ValidityDate, Mobile = "", Linkman = "", TicketCategory = (int)TicketCategoryStatus.QrCodePrintTicket, TicketSource = (int)TicketSourceStatus.ScenicSpot, TicketItem = order.TicketItem }; List <int> productIds = orderInfo.TicketItem.Select(a => a.TicketId).ToList(); var tbl_Tickets = _ticketService.GetTickets(productIds); var tbl_Order = _orderService.AddOrder(orderInfo); var tbl_OrderDetails = _orderDetailService.AddOrderDetails(orderInfo, tbl_Order); _orderService.UpdateOrder(tbl_Order, tbl_OrderDetails); var tbl_Ticket_Testings = _ticketTestingService.addTicketTestings(tbl_Order, tbl_OrderDetails); _ticketService.UpdateTicketBySellCount(tbl_Tickets, tbl_OrderDetails); try { _orderService.BeginTran(); _orderService.Add(tbl_Order); _orderDetailService.Add(tbl_OrderDetails); _ticketTestingService.Add(tbl_Ticket_Testings); _saleLogService.Add(tbl_Order); _ticketService.Update(tbl_Tickets); //提交事物 _orderService.CommitTran(); } catch { _orderService.RollbackTran(); return(result.ErrorResult()); } //打印机打印 if (order.IsPrint && !string.IsNullOrEmpty(order.PrintKey)) { var isPrint = _printService.Print(tbl_Order.OrderNo, order.PrintKey); if (!isPrint.Success) { return(result.ErrorResult("门票创建成功," + isPrint.Message)); } } return(result.SuccessResult()); }
protected override void OnException(ExceptionContext filterContext) { var exception = filterContext.Exception; var exceptionType = exception.GetType(); //对于Ajax请求,直接返回一个用于封装异常的JsonResult if (filterContext.HttpContext.Request.IsAjaxRequest()) { TResult result = new TResult(); if (exceptionType == typeof(SimpleBadRequestException)) { filterContext.Result = Json(result.FailureResult(exception.Message), JsonRequestBehavior.AllowGet); } else { filterContext.Result = Json(result.ErrorResult("服务器错误,请联系管理员!"), JsonRequestBehavior.AllowGet); } //当结果为json时,设置异常已处理 filterContext.ExceptionHandled = true; } else { //否则调用原始设置 base.OnException(filterContext); } }
/// <summary> /// 退票 /// </summary> /// <returns></returns> public TResult RefundOrder(int orderDetailId, int userId) { var result = new TResult(); var orderDetail = _orderDetailRepository.FirstOrDefault(o => o.OrderDetailId == orderDetailId); if (orderDetail == null) { return(result.ErrorResult("订单信息有误")); } var order = _orderService.Get(orderDetail.OrderNo); if (!orderDetail.CanRefund) { return(result.ErrorResult("门票不支持退票")); } if (orderDetail.CanRefundTime.HasValue && orderDetail.CanRefundTime < DateTime.Now.Date) { return(result.ErrorResult("门票已过可退票时间,不能退票")); } if (orderDetail.OrderStatus == (int)OrderDetailsDataStatus.Refund || orderDetail.OrderStatus == (int)OrderDetailsDataStatus.Consume || orderDetail.OrderStatus == (int)OrderDetailsDataStatus.Canncel) { return(result.ErrorResult("门票已消费或已退票(取消)")); } orderDetail.OrderStatus = (int)OrderDetailsDataStatus.Refund; //印刷票 退票 库存状态修改为在售 //记录条形码 var barcode = string.Empty; if (orderDetail.TicketCategory == 1) { barcode = orderDetail.BarCode; } //退票后该条码能继续激活 orderDetail.BarCode = ""; Tbl_RefundDetail refDtl = new Tbl_RefundDetail { OrderNo = orderDetail.OrderNo, EnterpriseId = orderDetail.EnterpriseId, ScenicId = orderDetail.ScenicId, SellerId = orderDetail.SellerId, SellerType = orderDetail.SellerType, TicketSource = orderDetail.TicketSource, TicketCategory = orderDetail.TicketCategory, UsedQuantity = orderDetail.UsedQuantity, TicketId = orderDetail.TicketId, TicketName = orderDetail.TicketName, Quantity = orderDetail.Quantity, Price = orderDetail.Price, BarCode = orderDetail.BarCode, Stub = orderDetail.Stub, CertificateNO = orderDetail.CertificateNO, WindowId = orderDetail.WindowId, IDCard = orderDetail.IDCard, Linkman = orderDetail.Linkman, Mobile = orderDetail.Mobile, RefundStatus = 0,//退款状态 RefundQuantity = orderDetail.Quantity, RefundFee = 0, RefundTotalAmount = (orderDetail.Price * orderDetail.Quantity), RefundSummary = "", OrderTime = orderDetail.CreateTime, ValidityDateStart = orderDetail.ValidityDateStart, ValidityDateEnd = orderDetail.ValidityDateEnd, PrintCount = orderDetail.PrintCount, Qrcode = orderDetail.QRcode, QrcodeUrl = orderDetail.QRcodeUrl, OrderDetailId = orderDetail.OrderDetailId, CreateTime = DateTime.Now, CreateUserId = userId }; var ticketTesting = _ticketTestingRepository.FirstOrDefault(o => o.OrderDetailId == orderDetail.OrderDetailId || o.OrderDetailNumber == orderDetail.Number); var ticket = _ticketRepository.FirstOrDefault(o => o.TicketId == orderDetail.TicketId); try { _refundDetailRepository.BeginTran(); _orderDetailRepository.Update(orderDetail); _ticketTestingRepository.Delete(ticketTesting); _refundDetailRepository.Add(refDtl); if (ticket != null) { int?selCount = 0; if (ticket.SellCount > orderDetail.Quantity) { selCount = ticket.SellCount - orderDetail.Quantity; } ticket.SellCount = ticket.SellCount.HasValue ? selCount : 0; _ticketRepository.Update(ticket); } _refundDetailRepository.CommitTran(); } catch { _refundDetailRepository.RollbackTran(); return(result.ErrorResult()); } return(result.SuccessResult()); }