public ActionResult TicketWriteOff(TicketWriteOffRequest request) { WxPayAPI.Log.Info("PosApiController", string.Format("核销门票:code{0},token:{1}", request.code, request.token)); //TicketWriteOffResponse result = new TicketWriteOffResponse(); if (string.IsNullOrEmpty(request.code)) { return(Json(new ApiResponse() { Code = "-1", Msg = "门票代码为空" })); } if (string.IsNullOrEmpty(request.token)) { return(Json(new ApiResponse() { Code = "-1", Msg = "token为空" })); } var postToken = postTokenService.GetByToken(request.token); if (postToken == null) { return(Json(new ApiResponse() { Code = "-1", Msg = "token失效请重新登录" })); } var pos = posEndPointService.GetByName(postToken.posName); if (pos == null && pos.State != States.Normal) { return(Json(new ApiResponse() { Code = "-1", Msg = "pos账号不存在或已停用" })); } var transaction = transactionHelper.BeginTransaction(); try { var ticket = ticketsService.GetByCodeModel(request.code); if (ticket != null) { var admissionTicket = admissionTicketService.GetById(ticket.AdmissionTicketId); if (ticket.State == TicketsState.Used) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "已使用" })); } if (ticket.State == TicketsState.NotUse) { if (DateTime.Now.Date > ticket.ExpiredDate) { ticket.State = TicketsState.BeOverdue; ticketsService.Update(ticket); transactionHelper.Commit(); return(Json(new ApiResponse() { Code = "-1", Msg = "已过期" })); } } if (!string.IsNullOrWhiteSpace(ticket.useScope)) { var shop = shopService.GetById(pos.ShopId); if (shop != null) { if (ticket.useScope != shop.Name) { return(Json(new ApiResponse() { Code = "-1", Msg = "该门票不可以在此门店消费" })); } } } ticket.State = TicketsState.Used; ticket.userTime = DateTime.Now; ticketsService.Update(ticket); var ticketOff = new TicketOff(); ticketOff.code = ticket.Code; ticketOff.DisplayName = admissionTicket != null ? admissionTicket.name : ""; ticketOff.offOp = pos.Name; ticketOff.offType = OffTypes.TicKet; ticketOff.shopId = pos.ShopId; ticketOff.subTime = DateTime.Now; ticketOff.timers = 1; ticketOff.userId = ticket.UserId; ticketOffService.Insert(ticketOff); var handRingPrint = new HandRingPrint(); var user = membershipService.GetUserById(ticket.UserId) as AccountUser; if (user != null) { handRingPrint.babyBirthDate = user.babyBirthDate.ToString("yyyy-MM-dd hh:mm;ss"); handRingPrint.babyName = user.babyName; handRingPrint.babySex = user.babySex == 1 ? "男" : user.babySex == 2 ? "女" : ""; handRingPrint.userName = user.DisplayName; handRingPrint.mobile = user.Mobile; } handRingPrint.adultNum = ticket.adultNum; handRingPrint.childNum = ticket.childNum; handRingPrint.code = ticket.Code; handRingPrint.createTime = DateTime.Now; handRingPrint.state = 1; handRingPrint.ticketType = 1; handRingPrint.shopId = pos.ShopId; handRingPrintService.Insert(handRingPrint); transactionHelper.Commit(); return(Json(new ApiResponse() { Code = "1", Msg = "核销成功" })); } var card = accountService.GetByName(request.code); if (card == null) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "门票不存在" })); } if (card.State != AccountStates.Normal) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "此卡无效" })); } if (card.Frequency <= 0) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "此卡无效" })); } if (DateTime.Now.Date > card.ExpiredDate) { card.State = AccountStates.UseComplete; card.LastDealTime = DateTime.Now; accountService.Update(card); transactionHelper.Commit(); return(Json(new ApiResponse() { Code = "-1", Msg = "此卡已过期" })); } if (card.ShopId > 0) { if (card.ShopId != pos.ShopId) { return(Json(new ApiResponse() { Code = "-1", Msg = "该卡不可以在此门店消费" })); } } card.Frequency -= 1; card.FrequencyUsed += 1; card.LastDealTime = DateTime.Now; if (card.Frequency <= 0) { card.State = AccountStates.UseComplete; } accountService.Update(card); var cardType = accountTypeService.GetById(card.AccountTypeId); var ticketOff1 = new TicketOff(); ticketOff1.code = card.Name; ticketOff1.DisplayName = cardType != null ? cardType.DisplayName : ""; ticketOff1.offOp = pos.Name; ticketOff1.offType = OffTypes.Card; ticketOff1.shopId = pos.ShopId; ticketOff1.subTime = DateTime.Now; ticketOff1.timers = 1; ticketOff1.userId = card.OwnerId.HasValue?card.OwnerId.Value:0; ticketOffService.Insert(ticketOff1); var handRingPrint1 = new HandRingPrint(); var user1 = membershipService.GetUserById(card.OwnerId.HasValue?card.OwnerId.Value:0) as AccountUser; if (user1 != null) { handRingPrint1.babyBirthDate = user1.babyBirthDate.ToString("yyyy-MM-dd hh:mm;ss"); handRingPrint1.babyName = user1.babyName; handRingPrint1.babySex = user1.babySex == 1 ? "男" : user1.babySex == 2 ? "女" : ""; handRingPrint1.userName = user1.DisplayName; handRingPrint1.mobile = user1.Mobile; } handRingPrint1.adultNum = 1; handRingPrint1.childNum = cardType.NumberOfPeople; handRingPrint1.code = card.Name; handRingPrint1.createTime = DateTime.Now; handRingPrint1.state = 1; handRingPrint1.ticketType = 2; handRingPrint1.shopId = pos.ShopId; handRingPrintService.Insert(handRingPrint1); transactionHelper.Commit(); return(Json(new ApiResponse() { Code = "1", Msg = "核销成功" })); } catch (Exception ex) { transaction.Dispose(); WxPayAPI.Log.Info("PosApiController", string.Format("请求获取门票异常:{0}", ex.Message)); return(Json(new ApiResponse() { Code = "-1", Msg = "异常,请联系管理员" })); } }
public void Insert(TicketOff item) { item.id = _databaseInstance.Insert(item, TableName); }
public ActionResult TicketWriteOff(TicketWriteOffRequest request) { WxPayAPI.Log.Info("WindowTicketOffController", string.Format("核销门票:code{0},token:{1}", request.code, request.token)); //TicketWriteOffResponse result = new TicketWriteOffResponse(); if (string.IsNullOrEmpty(request.code)) { return(Json(new ApiResponse() { Code = "-1", Msg = "门票代码为空" })); } var shop = securityHelper.GetCurrentUser().CurrentUser as ShopUser; if (shop == null) { return(Json(new ApiResponse() { Code = "-1", Msg = "商户不存在" })); } var transaction = transactionHelper.BeginTransaction(); try { var ticket = ticketsService.GetByCodeModel(request.code); if (ticket != null) { var admissionTicket = admissionTicketService.GetById(ticket.AdmissionTicketId); if (ticket.State == TicketsState.Used) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "已使用" })); } if (ticket.State == TicketsState.NotUse) { if (DateTime.Now.Date > ticket.ExpiredDate) { ticket.State = TicketsState.BeOverdue; ticketsService.Update(ticket); transactionHelper.Commit(); return(Json(new ApiResponse() { Code = "-1", Msg = "已过期" })); } } if (!string.IsNullOrWhiteSpace(ticket.useScope)) { if (shop != null) { if (ticket.useScope != shop.Name) { return(Json(new ApiResponse() { Code = "-1", Msg = "该门票不可以在此门店消费" })); } } } ticket.State = TicketsState.Used; ticket.userTime = DateTime.Now; ticketsService.Update(ticket); var ticketOff = new TicketOff(); ticketOff.code = ticket.Code; ticketOff.DisplayName = admissionTicket != null ? admissionTicket.name : ""; ticketOff.offOp = ""; ticketOff.offType = OffTypes.TicKet; ticketOff.shopId = shop.ShopId; ticketOff.subTime = DateTime.Now; ticketOff.timers = 1; ticketOff.userId = ticket.UserId; ticketOffService.Insert(ticketOff); var handRingPrint = new HandRingPrint(); var user = membershipService.GetUserById(ticket.UserId) as AccountUser; if (user != null) { handRingPrint.babyBirthDate = user.babyBirthDate.ToString("yyyy-MM-dd hh:mm;ss"); handRingPrint.babyName = user.babyName; handRingPrint.babySex = user.babySex == 1 ? "男" : user.babySex == 2 ? "女" : ""; handRingPrint.userName = user.DisplayName; handRingPrint.mobile = user.Mobile; } List <PritModel> dataPrint = new List <PritModel>(); handRingPrint.adultNum = ticket.adultNum; handRingPrint.childNum = ticket.childNum; handRingPrint.code = ticket.Code; handRingPrint.createTime = DateTime.Now; handRingPrint.state = 1; handRingPrint.ticketType = 1; handRingPrint.shopId = shop.ShopId; handRingPrintService.Insert(handRingPrint); for (int j = 0; j < ticket.adultNum + ticket.childNum; j++) { PritModel model = new PritModel(); model.effectiveTime = DateTime.Now.AddHours(3).ToString("MM月dd日hh时mm分"); model.einlass = DateTime.Now.ToString("MM月dd日hh时mm分"); model.name = user != null?user.DisplayName:""; model.mobile = user != null? user.Mobile:""; model.people = ticket.adultNum + ticket.childNum; dataPrint.Add(model); } transactionHelper.Commit(); return(Json(new ApiResponse <List <PritModel> >() { Code = "1", Msg = "核销成功", data = dataPrint })); } var card = accountService.GetByName(request.code); if (card == null) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "门票不存在" })); } if (card.State != AccountStates.Normal) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "此卡无效" })); } if (card.Frequency <= 0) { transaction.Dispose(); return(Json(new ApiResponse() { Code = "-1", Msg = "此卡无效" })); } if (DateTime.Now.Date > card.ExpiredDate) { card.State = AccountStates.UseComplete; card.LastDealTime = DateTime.Now; accountService.Update(card); transactionHelper.Commit(); return(Json(new ApiResponse() { Code = "-1", Msg = "此卡已过期" })); } if (card.ShopId > 0) { if (card.ShopId != shop.ShopId) { return(Json(new ApiResponse() { Code = "-1", Msg = "该卡不可以在此门店消费" })); } } card.Frequency -= 1; card.FrequencyUsed += 1; card.LastDealTime = DateTime.Now; if (card.Frequency <= 0) { card.State = AccountStates.UseComplete; } accountService.Update(card); var cardType = accountTypeService.GetById(card.AccountTypeId); var ticketOff1 = new TicketOff(); ticketOff1.code = card.Name; ticketOff1.DisplayName = cardType != null ? cardType.DisplayName : ""; ticketOff1.offOp = ""; ticketOff1.offType = OffTypes.Card; ticketOff1.shopId = shop.ShopId; ticketOff1.subTime = DateTime.Now; ticketOff1.timers = 1; ticketOff1.userId = card.OwnerId.HasValue ? card.OwnerId.Value : 0; ticketOffService.Insert(ticketOff1); var handRingPrint1 = new HandRingPrint(); var user1 = membershipService.GetUserById(card.OwnerId.HasValue ? card.OwnerId.Value : 0) as AccountUser; if (user1 != null) { handRingPrint1.babyBirthDate = user1.babyBirthDate.ToString("yyyy-MM-dd hh:mm;ss"); handRingPrint1.babyName = user1.babyName; handRingPrint1.babySex = user1.babySex == 1 ? "男" : user1.babySex == 2 ? "女" : ""; handRingPrint1.userName = user1.DisplayName; handRingPrint1.mobile = user1.Mobile; } handRingPrint1.adultNum = 1; handRingPrint1.childNum = cardType.NumberOfPeople; handRingPrint1.code = card.Name; handRingPrint1.createTime = DateTime.Now; handRingPrint1.state = 1; handRingPrint1.ticketType = 2; handRingPrint1.shopId = shop.ShopId; handRingPrintService.Insert(handRingPrint1); List <PritModel> dataPrint1 = new List <PritModel>(); for (int j = 0; j < ticket.adultNum + ticket.childNum; j++) { PritModel model = new PritModel(); model.effectiveTime = DateTime.Now.AddHours(3).ToString("MM月dd日hh时mm分"); model.einlass = DateTime.Now.ToString("MM月dd日hh时mm分"); model.name = user1 != null ? user1.DisplayName : ""; model.mobile = user1 != null ? user1.Mobile : ""; model.people = handRingPrint1.adultNum + handRingPrint1.childNum; dataPrint1.Add(model); } transactionHelper.Commit(); return(Json(new ApiResponse <List <PritModel> >() { Code = "1", Msg = "核销成功", data = dataPrint1 })); } catch (Exception ex) { transaction.Dispose(); WxPayAPI.Log.Info("WindowTicketOffController", string.Format("请求核销门票异常:{0}", ex.Message)); return(Json(new ApiResponse() { Code = "-1", Msg = "异常,请联系管理员" })); } }