public ActionResult Edit(long id = 0)
        {
            if (id == 0)
            {
                return(View(new RoomType()));
            }
            var info = RoomTypeBll.GetById(id);

            return(View(info));
        }
        public string GetNewRoomPrice(int type, long fnid, long roomId)
        {
            var now = DateTime.Now;

            var room     = RoomBll.GetById(roomId);
            var roomType = RoomTypeBll.GetById(room.RoomTypeId);

            if (type == (int)KaifangFangshiEnum.钟点房)
            {
                //钟点房
                var hourRoomList = HourRoomBll.GetList(UserContext.CurrentUser.HotelId);
                if (hourRoomList == null || hourRoomList.Count == 0)
                {
                    return(JsonConvert.SerializeObject(new { Ret = -1, Msg = "无钟点房方案" }));
                }
                var hourRoom = hourRoomList[0];//默认选择第一个
                if (fnid != 0 && hourRoomList.Any(a => a.Id == fnid))
                {
                    hourRoom = hourRoomList.FirstOrDefault(a => a.Id == fnid);
                }
                var yltime = now.AddMinutes(hourRoom.Minute).ToString("yyyy-MM-dd HH:mm:ss");


                return(JsonConvert.SerializeObject(new { Ret = 0, Id = hourRoom.Id, RoomPrice = hourRoom.Price }));
            }
            else if (type == (int)KaifangFangshiEnum.时段房)
            {
                //时段房
                var periodRoomList = PeriodRoomBll.GetList(UserContext.CurrentUser.HotelId);
                if (periodRoomList == null || periodRoomList.Count == 0)
                {
                    return(JsonConvert.SerializeObject(new { Ret = -1, Msg = "无时段房方案" }));
                }

                if (fnid != 0 && periodRoomList.Any(a => a.Id == fnid))
                {
                    var periodRoom  = periodRoomList.FirstOrDefault(a => a.Id == fnid);
                    var CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss");
                    var YlTime      = now.ToShortDateString() + $" {periodRoom.EndPoint}:00:00";
                    return(JsonConvert.SerializeObject(new { Ret = 0, Id = periodRoom.Id, RoomPrice = periodRoom.Price }));
                }

                return(JsonConvert.SerializeObject(new { Ret = -1, Msg = "无匹配的时段房方案,请手动选择" }));
            }
            return("");
        }
        /// <summary>
        /// 凌晨房检测,返回凌晨价
        /// </summary>
        /// <param name="roomId"></param>
        /// <returns></returns>
        public string LCRoomCheck(long roomId)
        {
            try
            {
                var hotelId  = UserContext.CurrentUser.HotelId;
                var model    = RoomBll.GetById(roomId);
                var roomType = RoomTypeBll.GetById(model.RoomTypeId);
                var setting  = GlobalFeeSetBll.GetByHotelId(hotelId);

                var now = DateTime.Now;

                if (now.Hour >= setting.LCStartFeePoint && now.Hour <= setting.LCEndFeePoint)
                {
                    return(JsonConvert.SerializeObject(new { IsLC = true, RoomPrice = roomType.MorningPrice }));
                }
                return(JsonConvert.SerializeObject(new { IsLC = false }));
            }
            catch
            {
                return(JsonConvert.SerializeObject(new { IsLC = false }));
            }
        }
        public JsonResult GetById(long id)
        {
            var model = RoomTypeBll.GetById(id);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 根据开房方式获取预离时间,同时绑定钟点房方案id或时段房方案id
        /// 20190828同时绑定价格
        /// </summary>
        /// <returns></returns>
        public string GetYlTimeByKffs(long roomRegId, int type, int rzDays, long fnid = 0, long roomId = 0)
        {
            var roomReg = RoomRegBll.GetById(roomRegId);
            var now     = DateTime.Now;

            if (roomReg != null)
            {
                now = TypeConvert.IntToDateTime(roomReg.RegTime);
            }

            var room     = RoomBll.GetById(roomId);
            var roomType = RoomTypeBll.GetById(room.RoomTypeId);

            if (type == (int)KaifangFangshiEnum.全天房 || type == (int)KaifangFangshiEnum.长包房 || type == (int)KaifangFangshiEnum.免费房)
            {
                var globalFeeSet = GlobalFeeSetBll.GetByHotelId(UserContext.CurrentUser.HotelId);
                if (globalFeeSet == null)
                {
                    return(JsonConvert.SerializeObject(new { Ret = 0, CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss"), YlTime = "" }));
                }

                var yltime = now;
                //如果是6点,那么当天6点之后开的房间就是第二天中午退房,0点到6点开房就是当天中午退房
                if (now.Hour >= 0 && now.Hour <= globalFeeSet.QTAfterPointToNextDay)
                {
                    //当天中午退房
                    yltime = now.Date.AddDays(rzDays - 1).AddHours(globalFeeSet.QTExitPoint);
                }
                else
                {
                    //第二天中午退房
                    yltime = now.Date.AddDays(1 + (rzDays - 1)).AddHours(globalFeeSet.QTExitPoint);
                }

                if (type != (int)KaifangFangshiEnum.免费房)
                {
                    return(JsonConvert.SerializeObject(new {
                        Ret = 0,
                        CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss"),
                        YlTime = yltime.ToString("yyyy-MM-dd HH:mm:ss"),
                        RoomPrice = roomType.Price
                    }));
                }

                return(JsonConvert.SerializeObject(new { Ret = 0, CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss"), YlTime = yltime.ToString("yyyy-MM-dd HH:mm:ss") }));
            }
            else if (type == (int)KaifangFangshiEnum.钟点房)
            {
                //钟点房
                var hourRoomList = HourRoomBll.GetList(UserContext.CurrentUser.HotelId);
                if (hourRoomList == null || hourRoomList.Count == 0)
                {
                    return(JsonConvert.SerializeObject(new { Ret = -1, Msg = "无钟点房方案" }));
                }
                var hourRoom = hourRoomList[0];//默认选择第一个
                if (fnid != 0 && hourRoomList.Any(a => a.Id == fnid))
                {
                    hourRoom = hourRoomList.FirstOrDefault(a => a.Id == fnid);
                }
                var yltime = now.AddMinutes(hourRoom.Minute).ToString("yyyy-MM-dd HH:mm:ss");


                return(JsonConvert.SerializeObject(new { Ret = 0, CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss"), YlTime = yltime, Id = hourRoom.Id, RoomPrice = hourRoom.Price }));
            }
            else if (type == (int)KaifangFangshiEnum.时段房)
            {
                //时段房
                var periodRoomList = PeriodRoomBll.GetList(UserContext.CurrentUser.HotelId);
                if (periodRoomList == null || periodRoomList.Count == 0)
                {
                    return(JsonConvert.SerializeObject(new { Ret = -1, Msg = "无时段房方案" }));
                }

                if (fnid != 0 && periodRoomList.Any(a => a.Id == fnid))
                {
                    var periodRoom  = periodRoomList.FirstOrDefault(a => a.Id == fnid);
                    var CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss");
                    var YlTime      = now.ToShortDateString() + $" {periodRoom.EndPoint}:00:00";
                    return(JsonConvert.SerializeObject(new { Ret = 0, CurrentTime = CurrentTime, YlTime = YlTime, Id = periodRoom.Id, RoomPrice = periodRoom.Price }));
                }
                else
                {
                    foreach (var periodRoom in periodRoomList)
                    {
                        if (now.Hour >= periodRoom.StartPoint && now.Hour <= periodRoom.EndPoint)
                        {
                            var CurrentTime = now.ToString("yyyy-MM-dd HH:mm:ss");
                            var YlTime      = now.ToShortDateString() + $" {periodRoom.EndPoint}:00:00";
                            return(JsonConvert.SerializeObject(new { Ret = 0, CurrentTime = CurrentTime, YlTime = YlTime, Id = periodRoom.Id, RoomPrice = periodRoom.Price }));
                        }
                    }
                }

                return(JsonConvert.SerializeObject(new { Ret = -1, Msg = "无匹配的时段房方案,请手动选择" }));
            }
            return("");
        }
        public string GetRoomInfo(long roomId)
        {
            var model = RoomBll.GetById(roomId);
            List <RoomPrice> priceList = null;

            if (model != null)
            {
                //根据房型id获取房价方案
                priceList = RoomPriceBll.GetList(UserContext.CurrentUser.HotelId, model.RoomTypeId);
            }
            else
            {
                model = new Room();
            }

            Hotel.Model.RoomReg reg = null;

            if (model.RoomRegId != 0)
            {
                reg = RoomRegBll.GetById(model.RoomRegId);
            }

            var roomType   = RoomTypeBll.GetById(model.RoomTypeId);
            var HolidaySet = HolidaySetBll.GetList(UserContext.CurrentUser.HotelId);
            var WeekendSet = WeekendSetBll.GetByHotelId(UserContext.CurrentUser.HotelId);

            var    SalePrice = model.Price;  //价
            double SaleRate  = 1.0;          //折扣率

            if (roomType.IsAllowWeekendRoom) //周末价判断
            {
                if (WeekendSet.IsMonday && DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
                if (WeekendSet.IsTuesday && DateTime.Now.DayOfWeek == DayOfWeek.Tuesday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
                if (WeekendSet.IsWednesday && DateTime.Now.DayOfWeek == DayOfWeek.Wednesday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
                if (WeekendSet.IsThursday && DateTime.Now.DayOfWeek == DayOfWeek.Thursday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
                if (WeekendSet.IsFriday && DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
                if (WeekendSet.IsSaturday && DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
                if (WeekendSet.IsSunday && DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                {
                    SalePrice = roomType.WeekendPrice;
                }
            }
            if (roomType.IsAllowHolidayRoom) //假日价
            {
                foreach (var h in HolidaySet)
                {
                    var start = TypeConvert.IntToDateTime(h.StartDate);
                    var end   = TypeConvert.IntToDateTime(h.EndDate).AddDays(1).AddSeconds(-1); //定位在这天最后一秒
                    if (DateTime.Now > start && DateTime.Now < end)
                    {
                        SalePrice = roomType.HolidayPrice;
                    }
                }
            }



            SaleRate = Convert.ToDouble(SalePrice) / Convert.ToDouble(model.Price);


            return(JsonConvert.SerializeObject(new
            {
                Room = model,
                RoomPrice = roomType.Price,
                SalePrice = SalePrice,
                SaleRate = SaleRate,
                PriceList = priceList,
                RoomReg = reg
            }));
        }