public TPageResult <TblTicketViewModel> GetList(TblTicketQueryModel model) { var userInfo = _enterpriseUserService.LoginForSession(); model.ScenicId = userInfo.ScenicId; model.UserId = userInfo.UserId; return(_ticketService.GetList(model)); }
public TPageResult <TblTicketViewModel> GetList(TblTicketQueryModel model) { var result = new TPageResult <TblTicketViewModel>(); if (model.PlayTime.Date < DateTime.Now.Date) { return(result.FailureResult(null)); } DateTime playTime = model.PlayTime.Date; int total = 0; var ticketList = _ticketTypeRepository.db.Queryable <Tbl_EnterpriseUserTicket, Tbl_Ticket>((a, b) => new object[] { JoinType.Left, a.TicketId == b.TicketId }). Where((a, b) => a.EnterpriseUserId == model.UserId && b.ScenicId == model.ScenicId && b.TypeId == model.TicketTypeId && b.DataStatus == 0 && b.TicketSource == (int)TicketSourceStatus.ScenicSpot && b.ExpiryDateStart <= playTime && b.ExpiryDateEnd >= playTime ). OrderBy((a, b) => b.CreateTime). Select((a, b) => new TblTicketViewModel { TicketName = b.TicketName, Id = b.TicketId, Price = b.SalePrice, MinOQ = b.MinOQ, MaxOQ = b.MaxOQ, RuleId = b.RuleId }).ToPageList(model.Page, model.PageSize, ref total); var ruleIds = ticketList.Select(a => a.RuleId).Distinct().ToList(); var ticketRuleList = _ticketRuleRepository.GetAllList(a => ruleIds.Contains(a.Id)); var scanTicketList = new List <TblTicketViewModel>(); DateTime nowTime = DateTime.Now.Date; foreach (var row in ticketList) { var ticketRule = ticketRuleList.FirstOrDefault(a => a.Id == row.RuleId); if (ticketRule != null && ticketRule.CanBookAdvance) { var playDataTime = playTime.AddHours(nowTime.Hour).AddMinutes(nowTime.Minute).AddSeconds(nowTime.Second); var nowDataTime = nowTime.Date.AddHours(nowTime.Hour).AddMinutes(nowTime.Minute).AddSeconds(nowTime.Second); var time = nowDataTime.AddDays(ticketRule.BookDay ?? 0).AddHours(ticketRule.BookHour ?? 0).AddMinutes(ticketRule.BookMinute ?? 0); if (time > playDataTime) { continue; } } scanTicketList.Add(new TblTicketViewModel { TicketName = row.TicketName, Id = row.Id, Price = row.Price, MinOQ = row.MinOQ, MaxOQ = row.MaxOQ }); } var ticketIds = scanTicketList.Select(a => a.Id).ToList(); var Tbl_TicketRelations = _ticketRelationRepository.GetAllList(p => p.ScenicId == model.ScenicId && ticketIds.Contains(p.TicketId)); DateTime endPay = playTime.AddDays(-1); //根据游玩日期,变动价格 foreach (var item in scanTicketList) { //根据orderId 顺序排列 取第一条 var tbl_TicketRelation = Tbl_TicketRelations.Where(p => p.TicketId == item.Id && p.Type == (int)TicketRelationEnum.TimeSlot && p.ExpiryDateStart <= nowTime && p.ExpiryDateEnd >= nowTime ).OrderBy(c => c.OrderId).FirstOrDefault(); if (tbl_TicketRelation != null) { item.Price = tbl_TicketRelation.SalePrice; continue; } //特殊时间段价格表为空 同时 游玩日期 是周末则启动周末价格策略 var dayOfWeek = playTime.DayOfWeek; if (dayOfWeek != DayOfWeek.Saturday && dayOfWeek != DayOfWeek.Sunday) { continue; } var ticketRelation = Tbl_TicketRelations.FirstOrDefault(p => p.TicketId == item.Id && p.Type == (int)TicketRelationEnum.Weekend); if (ticketRelation != null) { item.Price = ticketRelation.SalePrice; } } return(result.SuccessResult(scanTicketList, total)); }