/*********************************************************************** * Project: CoreCms * ProjectName: 核心内容管理系统 * Web: https://www.corecms.net * Author: 大灰灰 * Email: jianweie@163.com * CreateTime: 2025/12/7 0:55:50 * Description: 暂无 ***********************************************************************/ using CoreCms.Net.Configuration; using CoreCms.Net.Filter; using CoreCms.Net.IServices; using CoreCms.Net.Loging; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities.Expression; using CoreCms.Net.Model.FromBody; using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.SQ; using CoreCms.Net.Utility.Extensions; using CoreCms.Net.Utility.Helper; using CoreCms.Net.Web.Admin.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using NPOI.HSSF.UserModel; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using NLog; using AutoMapper; namespace CoreCms.Net.Web.Admin.Controllers { /// /// /// [Description("")] [Route("api/[controller]/[action]")] [ApiController] [RequiredErrorForAdmin] [Authorize] public class SQRoomPricingController : ControllerBase { private readonly IWebHostEnvironment _webHostEnvironment; private readonly ISQRoomPricingServices _SQRoomPricingServices; private readonly ISQRoomsServices _SQRoomsServices; private readonly ISQReservationsServices _SQReservationsServices; private readonly ISQReservationParticipantsServices _SQReservationParticipantsServices; private readonly ISQRoomUnavailableTimesServices _SQRoomUnavailableTimesServices; private readonly ICoreCmsUserServices _userServices; private readonly IMapper _mapper; /// /// 构造函数 /// public SQRoomPricingController(IWebHostEnvironment webHostEnvironment , ISQRoomPricingServices SQRoomPricingServices , ISQRoomsServices SQRoomsServices , ISQReservationsServices SQReservationsServices , ISQReservationParticipantsServices SQReservationParticipantsServices , ISQRoomUnavailableTimesServices SQRoomUnavailableTimesServices , ICoreCmsUserServices userServices , IMapper mapper ) { _webHostEnvironment = webHostEnvironment; _SQRoomPricingServices = SQRoomPricingServices; _SQRoomsServices = SQRoomsServices; _SQReservationsServices = SQReservationsServices; _SQReservationParticipantsServices = SQReservationParticipantsServices; _SQRoomUnavailableTimesServices = SQRoomUnavailableTimesServices; _userServices = userServices; _mapper = mapper; } #region 获取列表============================================================ // POST: Api/SQRoomPricing/GetPageList /// /// 获取列表 /// /// [HttpPost] [Description("获取列表")] public async Task GetPageList() { var jm = new AdminUiCallBack(); var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1); var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30); var where = PredicateBuilder.True(); //获取排序字段 var orderField = Request.Form["orderField"].FirstOrDefault(); Expression> orderEx = orderField switch { "id" => p => p.id, "room_id" => p => p.room_id, "time_slot_type" => p => p.time_slot_type, "standard_price" => p => p.standard_price, "member_price" => p => p.member_price, "price_desc_standard" => p => p.price_desc_standard, "price_desc_member" => p => p.price_desc_member, "effective_date_start" => p => p.effective_date_start, "effective_date_end" => p => p.effective_date_end, "is_active" => p => p.is_active, "created_at" => p => p.created_at, "updated_at" => p => p.updated_at, _ => p => p.id }; //设置排序方式 var orderDirection = Request.Form["orderDirection"].FirstOrDefault(); var orderBy = orderDirection switch { "asc" => OrderByType.Asc, "desc" => OrderByType.Desc, _ => OrderByType.Desc }; //查询筛选 // int var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0); if (id > 0) { where = where.And(p => p.id == id); } // int var room_id = Request.Form["room_id"].FirstOrDefault().ObjectToInt(0); if (room_id > 0) { where = where.And(p => p.room_id == room_id); } // int var time_slot_type = Request.Form["time_slot_type"].FirstOrDefault().ObjectToInt(0); if (time_slot_type > 0) { where = where.And(p => p.time_slot_type == time_slot_type); } // decimal var standard_price = Request.Form["standard_price"].FirstOrDefault().ObjectToDecimal(0); if (standard_price > 0) { where = where.And(p => p.standard_price == standard_price); } // decimal var member_price = Request.Form["member_price"].FirstOrDefault().ObjectToDecimal(0); if (member_price > 0) { where = where.And(p => p.member_price == member_price); } // nvarchar var price_desc_standard = Request.Form["price_desc_standard"].FirstOrDefault(); if (!string.IsNullOrEmpty(price_desc_standard)) { where = where.And(p => p.price_desc_standard.Contains(price_desc_standard)); } // nvarchar var price_desc_member = Request.Form["price_desc_member"].FirstOrDefault(); if (!string.IsNullOrEmpty(price_desc_member)) { where = where.And(p => p.price_desc_member.Contains(price_desc_member)); } // bit var is_active = Request.Form["is_active"].FirstOrDefault(); if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "true") { where = where.And(p => p.is_active == true); } else if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "false") { where = where.And(p => p.is_active == false); } // datetime var created_at = Request.Form["created_at"].FirstOrDefault(); if (!string.IsNullOrEmpty(created_at)) { if (created_at.Contains("到")) { var dts = created_at.Split("到"); var dtStart = dts[0].Trim().ObjectToDate(); where = where.And(p => p.created_at > dtStart); var dtEnd = dts[1].Trim().ObjectToDate(); where = where.And(p => p.created_at < dtEnd); } else { var dt = created_at.ObjectToDate(); where = where.And(p => p.created_at > dt); } } // datetime var updated_at = Request.Form["updated_at"].FirstOrDefault(); if (!string.IsNullOrEmpty(updated_at)) { if (updated_at.Contains("到")) { var dts = updated_at.Split("到"); var dtStart = dts[0].Trim().ObjectToDate(); where = where.And(p => p.updated_at > dtStart); var dtEnd = dts[1].Trim().ObjectToDate(); where = where.And(p => p.updated_at < dtEnd); } else { var dt = updated_at.ObjectToDate(); where = where.And(p => p.updated_at > dt); } } //获取数据 var list = await _SQRoomPricingServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true); //返回数据 jm.data = list; jm.code = 0; jm.count = list.TotalCount; jm.msg = "数据调用成功!"; return jm; } #endregion #region 首页数据============================================================ // POST: Api/SQRoomPricing/GetIndex /// /// 首页数据 /// /// [HttpPost] [Description("首页数据")] public AdminUiCallBack GetIndex() { //返回数据 var jm = new AdminUiCallBack { code = 0 }; return jm; } #endregion #region 创建数据============================================================ // POST: Api/SQRoomPricing/GetCreate /// /// 创建数据 /// /// [HttpPost] [Description("创建数据")] public AdminUiCallBack GetCreate() { //返回数据 var jm = new AdminUiCallBack { code = 0, data = new SQRoomPricing() }; return jm; } #endregion #region 创建提交============================================================ // POST: Api/SQRoomPricing/DoCreate /// /// 创建提交 /// /// /// [HttpPost] [Description("创建提交")] public async Task DoCreate([FromBody] SQRoomPricing entity) { entity.created_at = DateTime.Now; entity.updated_at = DateTime.Now; entity.member_price = 0; entity.standard_price = 0; var jm = await _SQRoomPricingServices.InsertAsync(entity); return new AdminUiCallBack() { code = 0, msg = "删除成功" }; ; } #endregion #region 编辑数据============================================================ // POST: Api/SQRoomPricing/GetEdit /// /// 编辑数据 /// /// /// [HttpPost] [Description("编辑数据")] public async Task GetEdit([FromBody] FMIntId entity) { var jm = new AdminUiCallBack(); var model = await _SQRoomPricingServices.QueryByIdAsync(entity.id, false); if (model == null) { jm.msg = "不存在此信息"; return jm; } jm.code = 0; jm.data = model; return jm; } #endregion #region 编辑提交============================================================ // POST: Api/SQRoomPricing/Edit /// /// 编辑提交 /// /// /// [HttpPost] [Description("编辑提交")] public async Task DoEdit([FromBody] SQRoomPricing entity) { entity.updated_at = DateTime.Now; entity.member_price = 0; entity.standard_price = 0; var jm = await _SQRoomPricingServices.UpdateAsync(entity); return new AdminUiCallBack() { code = 0, msg = "删除成功" }; ; } #endregion #region 删除数据============================================================ // POST: Api/SQRoomPricing/DoDelete/10 /// /// 单选删除 /// /// /// [HttpPost] [Description("单选删除")] public async Task DoDelete([FromBody] FMIntId entity) { var jm = new AdminUiCallBack(); var model = await _SQRoomPricingServices.ExistsAsync(p => p.id == entity.id, true); if (!model) { jm.msg = GlobalConstVars.DataisNo; return jm; } await _SQRoomPricingServices.DeleteByIdAsync(entity.id); return jm; } #endregion #region 批量删除============================================================ // POST: Api/SQRoomPricing/DoBatchDelete/10,11,20 /// /// 批量删除 /// /// /// [HttpPost] [Description("批量删除")] public async Task DoBatchDelete([FromBody] FMArrayIntIds entity) { await _SQRoomPricingServices.DeleteByIdsAsync(entity.id); return new AdminUiCallBack() { code = 0, msg = "删除成功" }; } #endregion #region 预览数据============================================================ // POST: Api/SQRoomPricing/GetDetails/10 /// /// 预览数据 /// /// /// [HttpPost] [Description("预览数据")] public async Task GetDetails([FromBody] FMIntId entity) { var jm = new AdminUiCallBack(); var model = await _SQRoomPricingServices.QueryByIdAsync(entity.id, false); if (model == null) { jm.msg = "不存在此信息"; return jm; } jm.code = 0; jm.data = model; return jm; } #endregion #region 选择导出============================================================ // POST: Api/SQRoomPricing/SelectExportExcel/10 /// /// 选择导出 /// /// /// [HttpPost] [Description("选择导出")] public async Task SelectExportExcel([FromBody] FMArrayIntIds entity) { var jm = new AdminUiCallBack(); //创建Excel文件的对象 var book = new HSSFWorkbook(); //添加一个sheet var mySheet = book.CreateSheet("Sheet1"); //获取list数据 var listModel = await _SQRoomPricingServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc, true); //给sheet1添加第一行的头部标题 var headerRow = mySheet.CreateRow(0); var headerStyle = ExcelHelper.GetHeaderStyle(book); var cell0 = headerRow.CreateCell(0); cell0.SetCellValue(""); cell0.CellStyle = headerStyle; mySheet.SetColumnWidth(0, 10 * 256); var cell1 = headerRow.CreateCell(1); cell1.SetCellValue(""); cell1.CellStyle = headerStyle; mySheet.SetColumnWidth(1, 10 * 256); var cell2 = headerRow.CreateCell(2); cell2.SetCellValue(""); cell2.CellStyle = headerStyle; mySheet.SetColumnWidth(2, 10 * 256); var cell3 = headerRow.CreateCell(3); cell3.SetCellValue(""); cell3.CellStyle = headerStyle; mySheet.SetColumnWidth(3, 10 * 256); var cell4 = headerRow.CreateCell(4); cell4.SetCellValue(""); cell4.CellStyle = headerStyle; mySheet.SetColumnWidth(4, 10 * 256); var cell5 = headerRow.CreateCell(5); cell5.SetCellValue(""); cell5.CellStyle = headerStyle; mySheet.SetColumnWidth(5, 10 * 256); var cell6 = headerRow.CreateCell(6); cell6.SetCellValue(""); cell6.CellStyle = headerStyle; mySheet.SetColumnWidth(6, 10 * 256); var cell7 = headerRow.CreateCell(7); cell7.SetCellValue(""); cell7.CellStyle = headerStyle; mySheet.SetColumnWidth(7, 10 * 256); var cell8 = headerRow.CreateCell(8); cell8.SetCellValue(""); cell8.CellStyle = headerStyle; mySheet.SetColumnWidth(8, 10 * 256); var cell9 = headerRow.CreateCell(9); cell9.SetCellValue(""); cell9.CellStyle = headerStyle; mySheet.SetColumnWidth(9, 10 * 256); var cell10 = headerRow.CreateCell(10); cell10.SetCellValue(""); cell10.CellStyle = headerStyle; mySheet.SetColumnWidth(10, 10 * 256); var cell11 = headerRow.CreateCell(11); cell11.SetCellValue(""); cell11.CellStyle = headerStyle; mySheet.SetColumnWidth(11, 10 * 256); headerRow.Height = 30 * 20; var commonCellStyle = ExcelHelper.GetCommonStyle(book); //将数据逐步写入sheet1各个行 for (var i = 0; i < listModel.Count; i++) { var rowTemp = mySheet.CreateRow(i + 1); var rowTemp0 = rowTemp.CreateCell(0); rowTemp0.SetCellValue(listModel[i].id.ToString()); rowTemp0.CellStyle = commonCellStyle; var rowTemp1 = rowTemp.CreateCell(1); rowTemp1.SetCellValue(listModel[i].room_id.ToString()); rowTemp1.CellStyle = commonCellStyle; var rowTemp2 = rowTemp.CreateCell(2); rowTemp2.SetCellValue(listModel[i].time_slot_type.ToString()); rowTemp2.CellStyle = commonCellStyle; var rowTemp3 = rowTemp.CreateCell(3); rowTemp3.SetCellValue(listModel[i].standard_price.ToString()); rowTemp3.CellStyle = commonCellStyle; var rowTemp4 = rowTemp.CreateCell(4); rowTemp4.SetCellValue(listModel[i].member_price.ToString()); rowTemp4.CellStyle = commonCellStyle; var rowTemp5 = rowTemp.CreateCell(5); rowTemp5.SetCellValue(listModel[i].price_desc_standard.ToString()); rowTemp5.CellStyle = commonCellStyle; var rowTemp6 = rowTemp.CreateCell(6); rowTemp6.SetCellValue(listModel[i].price_desc_member.ToString()); rowTemp6.CellStyle = commonCellStyle; var rowTemp7 = rowTemp.CreateCell(7); rowTemp7.SetCellValue(listModel[i].effective_date_start.ToString()); rowTemp7.CellStyle = commonCellStyle; var rowTemp8 = rowTemp.CreateCell(8); rowTemp8.SetCellValue(listModel[i].effective_date_end.ToString()); rowTemp8.CellStyle = commonCellStyle; var rowTemp9 = rowTemp.CreateCell(9); rowTemp9.SetCellValue(listModel[i].is_active.ToString()); rowTemp9.CellStyle = commonCellStyle; var rowTemp10 = rowTemp.CreateCell(10); rowTemp10.SetCellValue(listModel[i].created_at.ToString()); rowTemp10.CellStyle = commonCellStyle; var rowTemp11 = rowTemp.CreateCell(11); rowTemp11.SetCellValue(listModel[i].updated_at.ToString()); rowTemp11.CellStyle = commonCellStyle; } // 导出excel string webRootPath = _webHostEnvironment.WebRootPath; string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-SQRoomPricing导出(选择结果).xls"; string filePath = webRootPath + tpath; DirectoryInfo di = new DirectoryInfo(filePath); if (!di.Exists) { di.Create(); } FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create); book.Write(fileHssf); fileHssf.Close(); jm.code = 0; jm.msg = GlobalConstVars.ExcelExportSuccess; jm.data = tpath + fileName; return jm; } #endregion #region 查询导出============================================================ // POST: Api/SQRoomPricing/QueryExportExcel/10 /// /// 查询导出 /// /// [HttpPost] [Description("查询导出")] public async Task QueryExportExcel() { var jm = new AdminUiCallBack(); var where = PredicateBuilder.True(); //查询筛选 // int var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0); if (id > 0) { where = where.And(p => p.id == id); } // int var room_id = Request.Form["room_id"].FirstOrDefault().ObjectToInt(0); if (room_id > 0) { where = where.And(p => p.room_id == room_id); } // int var time_slot_type = Request.Form["time_slot_type"].FirstOrDefault().ObjectToInt(0); if (time_slot_type > 0) { where = where.And(p => p.time_slot_type == time_slot_type); } // decimal var standard_price = Request.Form["standard_price"].FirstOrDefault().ObjectToDecimal(0); if (standard_price > 0) { where = where.And(p => p.standard_price == standard_price); } // decimal var member_price = Request.Form["member_price"].FirstOrDefault().ObjectToDecimal(0); if (member_price > 0) { where = where.And(p => p.member_price == member_price); } // nvarchar var price_desc_standard = Request.Form["price_desc_standard"].FirstOrDefault(); if (!string.IsNullOrEmpty(price_desc_standard)) { where = where.And(p => p.price_desc_standard.Contains(price_desc_standard)); } // nvarchar var price_desc_member = Request.Form["price_desc_member"].FirstOrDefault(); if (!string.IsNullOrEmpty(price_desc_member)) { where = where.And(p => p.price_desc_member.Contains(price_desc_member)); } // bit var is_active = Request.Form["is_active"].FirstOrDefault(); if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "true") { where = where.And(p => p.is_active == true); } else if (!string.IsNullOrEmpty(is_active) && is_active.ToLowerInvariant() == "false") { where = where.And(p => p.is_active == false); } // datetime var created_at = Request.Form["created_at"].FirstOrDefault(); if (!string.IsNullOrEmpty(created_at)) { var dt = created_at.ObjectToDate(); where = where.And(p => p.created_at > dt); } // datetime var updated_at = Request.Form["updated_at"].FirstOrDefault(); if (!string.IsNullOrEmpty(updated_at)) { var dt = updated_at.ObjectToDate(); where = where.And(p => p.updated_at > dt); } //获取数据 //创建Excel文件的对象 var book = new HSSFWorkbook(); //添加一个sheet var mySheet = book.CreateSheet("Sheet1"); //获取list数据 var listModel = await _SQRoomPricingServices.QueryListByClauseAsync(where, p => p.id, OrderByType.Asc, true); //给sheet1添加第一行的头部标题 var headerRow = mySheet.CreateRow(0); var headerStyle = ExcelHelper.GetHeaderStyle(book); var cell0 = headerRow.CreateCell(0); cell0.SetCellValue(""); cell0.CellStyle = headerStyle; mySheet.SetColumnWidth(0, 10 * 256); var cell1 = headerRow.CreateCell(1); cell1.SetCellValue(""); cell1.CellStyle = headerStyle; mySheet.SetColumnWidth(1, 10 * 256); var cell2 = headerRow.CreateCell(2); cell2.SetCellValue(""); cell2.CellStyle = headerStyle; mySheet.SetColumnWidth(2, 10 * 256); var cell3 = headerRow.CreateCell(3); cell3.SetCellValue(""); cell3.CellStyle = headerStyle; mySheet.SetColumnWidth(3, 10 * 256); var cell4 = headerRow.CreateCell(4); cell4.SetCellValue(""); cell4.CellStyle = headerStyle; mySheet.SetColumnWidth(4, 10 * 256); var cell5 = headerRow.CreateCell(5); cell5.SetCellValue(""); cell5.CellStyle = headerStyle; mySheet.SetColumnWidth(5, 10 * 256); var cell6 = headerRow.CreateCell(6); cell6.SetCellValue(""); cell6.CellStyle = headerStyle; mySheet.SetColumnWidth(6, 10 * 256); var cell7 = headerRow.CreateCell(7); cell7.SetCellValue(""); cell7.CellStyle = headerStyle; mySheet.SetColumnWidth(7, 10 * 256); var cell8 = headerRow.CreateCell(8); cell8.SetCellValue(""); cell8.CellStyle = headerStyle; mySheet.SetColumnWidth(8, 10 * 256); var cell9 = headerRow.CreateCell(9); cell9.SetCellValue(""); cell9.CellStyle = headerStyle; mySheet.SetColumnWidth(9, 10 * 256); var cell10 = headerRow.CreateCell(10); cell10.SetCellValue(""); cell10.CellStyle = headerStyle; mySheet.SetColumnWidth(10, 10 * 256); var cell11 = headerRow.CreateCell(11); cell11.SetCellValue(""); cell11.CellStyle = headerStyle; mySheet.SetColumnWidth(11, 10 * 256); headerRow.Height = 30 * 20; var commonCellStyle = ExcelHelper.GetCommonStyle(book); //将数据逐步写入sheet1各个行 for (var i = 0; i < listModel.Count; i++) { var rowTemp = mySheet.CreateRow(i + 1); var rowTemp0 = rowTemp.CreateCell(0); rowTemp0.SetCellValue(listModel[i].id.ToString()); rowTemp0.CellStyle = commonCellStyle; var rowTemp1 = rowTemp.CreateCell(1); rowTemp1.SetCellValue(listModel[i].room_id.ToString()); rowTemp1.CellStyle = commonCellStyle; var rowTemp2 = rowTemp.CreateCell(2); rowTemp2.SetCellValue(listModel[i].time_slot_type.ToString()); rowTemp2.CellStyle = commonCellStyle; var rowTemp3 = rowTemp.CreateCell(3); rowTemp3.SetCellValue(listModel[i].standard_price.ToString()); rowTemp3.CellStyle = commonCellStyle; var rowTemp4 = rowTemp.CreateCell(4); rowTemp4.SetCellValue(listModel[i].member_price.ToString()); rowTemp4.CellStyle = commonCellStyle; var rowTemp5 = rowTemp.CreateCell(5); rowTemp5.SetCellValue(listModel[i].price_desc_standard.ToString()); rowTemp5.CellStyle = commonCellStyle; var rowTemp6 = rowTemp.CreateCell(6); rowTemp6.SetCellValue(listModel[i].price_desc_member.ToString()); rowTemp6.CellStyle = commonCellStyle; var rowTemp7 = rowTemp.CreateCell(7); rowTemp7.SetCellValue(listModel[i].effective_date_start.ToString()); rowTemp7.CellStyle = commonCellStyle; var rowTemp8 = rowTemp.CreateCell(8); rowTemp8.SetCellValue(listModel[i].effective_date_end.ToString()); rowTemp8.CellStyle = commonCellStyle; var rowTemp9 = rowTemp.CreateCell(9); rowTemp9.SetCellValue(listModel[i].is_active.ToString()); rowTemp9.CellStyle = commonCellStyle; var rowTemp10 = rowTemp.CreateCell(10); rowTemp10.SetCellValue(listModel[i].created_at.ToString()); rowTemp10.CellStyle = commonCellStyle; var rowTemp11 = rowTemp.CreateCell(11); rowTemp11.SetCellValue(listModel[i].updated_at.ToString()); rowTemp11.CellStyle = commonCellStyle; } // 写入到excel string webRootPath = _webHostEnvironment.WebRootPath; string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-SQRoomPricing导出(查询结果).xls"; string filePath = webRootPath + tpath; DirectoryInfo di = new DirectoryInfo(filePath); if (!di.Exists) { di.Create(); } FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create); book.Write(fileHssf); fileHssf.Close(); jm.code = 0; jm.msg = GlobalConstVars.ExcelExportSuccess; jm.data = tpath + fileName; return jm; } #endregion #region 设置============================================================ // POST: Api/SQRoomPricing/DoSetis_active/10 /// /// 设置 /// /// /// [HttpPost] [Description("设置")] public async Task DoSetis_active([FromBody] FMUpdateBoolDataByIntId entity) { var jm = new AdminUiCallBack(); var oldModel = await _SQRoomPricingServices.QueryByIdAsync(entity.id, false); if (oldModel == null) { jm.msg = "不存在此信息"; return jm; } oldModel.is_active = (bool)entity.data; var bl = await _SQRoomPricingServices.UpdateAsync(p => new SQRoomPricing() { is_active = oldModel.is_active }, p => p.id == oldModel.id); jm.code = bl ? 0 : 1; jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure; return jm; } #endregion #region 获取房间时段状态============================================================ // GET: Api/SQRoomPricing/GetRoomListWithSlots /// /// 获取房间列表及时段状态(用于日历视图) /// /// 日期 /// 是否只显示可用房间 /// 当前时段 /// [HttpGet] [AllowAnonymous] [Description("获取房间列表及时段状态")] public async Task GetRoomListWithSlots([FromQuery] string date, [FromQuery] bool showOnlyAvailable = false, [FromQuery] int? currentTimeSlot = null) { var jm = new AdminUiCallBack(); // 验证日期参数 if (string.IsNullOrEmpty(date)) { jm.msg = "请提供日期参数"; return jm; } if (!DateTime.TryParse(date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } // 调用服务获取数据 var result = await _SQRoomsServices.GetRoomListWithSlotsAsync(dateValue, showOnlyAvailable, currentTimeSlot); jm.code = 0; jm.msg = "获取成功"; jm.data = result; return jm; } #endregion #region 获取日期详情============================================================ // GET: Api/SQRoomPricing/GetDateDetails /// /// 获取指定日期和房间的详细信息(用于日历视图点击日期) /// /// 日期 /// 房间ID /// [HttpGet] [AllowAnonymous] [Description("获取日期详情")] public async Task GetDateDetails([FromQuery] string date, [FromQuery] int roomId) { var jm = new AdminUiCallBack(); try { // 验证参数 if (string.IsNullOrEmpty(date)) { jm.msg = "请提供日期参数"; return jm; } if (roomId <= 0) { jm.msg = "请提供房间ID"; return jm; } if (!DateTime.TryParse(date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } // 获取房间信息 var room = await _SQRoomsServices.QueryByIdAsync(roomId); if (room == null) { jm.msg = "房间不存在"; return jm; } // 获取该日期该房间的时段状态 var roomListWithSlots = await _SQRoomsServices.GetRoomListWithSlotsAsync(dateValue, false, null); var roomData = roomListWithSlots?.FirstOrDefault(r => r.id == roomId); // 获取该日期该房间的预约列表 var startTime = dateValue.Date; var endTime = dateValue.Date.AddDays(1); var reservations = await _SQReservationsServices.QueryListByClauseAsync( p => p.room_id == roomId && p.start_time >= startTime && p.start_time < endTime && p.status != 4, // 排除已取消的预约 p => p.start_time, OrderByType.Asc ); // 查询所有预约的参与者 var reservationIds = reservations.Select(r => r.id).ToList(); List allParticipants = new List(); List userList = new List(); if (reservationIds.Any()) { allParticipants = await _SQReservationParticipantsServices.QueryListByClauseAsync( p => reservationIds.Contains(p.reservation_id), p => p.role, OrderByType.Desc, true ); // 查询所有参与者的用户信息 var userIds = allParticipants.Select(p => p.user_id).Distinct().ToList(); if (userIds.Any()) { userList = await _userServices.QueryListByClauseAsync( u => userIds.Contains(u.id), u => u.id, OrderByType.Asc, true ); } } // 处理时段数据,添加参与者头像和数量 var enhancedTimeSlots = new List(); if (roomData?.time_slots != null) { foreach (var slot in roomData.time_slots) { // 获取该时段的所有预约 var slotReservations = reservations.Where(r => r.time_slot_type.HasValue && r.time_slot_type.Value == slot.slot_type ).ToList(); // 获取该时段所有预约的参与者(正常状态) var slotReservationIds = slotReservations.Select(r => r.id).ToList(); var slotParticipants = allParticipants.Where(p => slotReservationIds.Contains(p.reservation_id) && p.status == 0 ).ToList(); // 提取头像列表 var avatars = slotParticipants .Select(p => userList.FirstOrDefault(u => u.id == p.user_id)?.avatarImage) .Where(avatar => !string.IsNullOrEmpty(avatar)) .Distinct() .ToList(); enhancedTimeSlots.Add(new { slot_type = slot.slot_type, slot_name = slot.slot_name, status = slot.status, price_desc_standard = slot.price_desc_standard, price_desc_member = slot.price_desc_member, reservation_count = slotParticipants.Count, participant_avatars = avatars }); } } // 按时段分组预约 var reservationsBySlot = new Dictionary>(); for (int i = 0; i <= 3; i++) { reservationsBySlot[i] = new List(); } foreach (var reservation in reservations) { // 确定预约所属时段 int slotType = reservation.time_slot_type ?? GetTimeSlotTypeFromTime(reservation.start_time); // 获取该预约的参与者 var participants = allParticipants.Where(p => p.reservation_id == reservation.id) .OrderBy(p => p.role == 1 ? 0 : 1) // 发起者优先 .ThenBy(p => p.status) // 正常状态优先 .ToList(); var participantsDto = _mapper.Map>(participants); // 填充用户信息 foreach (var p in participantsDto) { var user = userList.FirstOrDefault(u => u.id == p.user_id); if (user != null) { p.UserName = user.nickName; p.AvatarImage = user.avatarImage; } } reservationsBySlot[slotType].Add(new { id = reservation.id, title = reservation.title, player_count = reservation.player_count, deposit_fee = reservation.deposit_fee, latest_arrival_time = reservation.latest_arrival_time?.ToString("yyyy-MM-dd HH:mm:ss"), game_type = reservation.game_type, game_rule = reservation.game_rule, start_time = reservation.start_time.ToString("yyyy-MM-dd HH:mm:ss"), end_time = reservation.end_time.ToString("yyyy-MM-dd HH:mm:ss"), status = reservation.status, participants = participantsDto.Select(p => new { id = p.id, user_id = p.user_id, user_name = p.UserName, avatar_image = p.AvatarImage, join_time = p.join_time.ToString("yyyy-MM-dd HH:mm:ss"), role = p.role, quit_time = p.quit_time?.ToString("yyyy-MM-dd HH:mm:ss"), status = p.status, is_refund = p.is_refund, remarks = p.remarks }).ToList() }); } // 构建返回数据 var result = new { date = date, room_id = roomId, room_name = room.name, time_slots = enhancedTimeSlots, reservations_by_slot = reservationsBySlot }; jm.code = 0; jm.msg = "获取成功"; jm.data = result; } catch (Exception ex) { jm.msg = "获取数据时发生错误:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "获取日期详情", "GetDateDetails", ex); } return jm; } /// /// 根据时间判断时段类型 /// private int GetTimeSlotTypeFromTime(DateTime time) { var hour = time.Hour; if (hour >= 0 && hour < 6) return 0; // 凌晨 00:00-06:00 if (hour >= 6 && hour < 12) return 1; // 上午 06:00-12:00 if (hour >= 12 && hour < 18) return 2; // 下午 12:00-18:00 return 3; // 晚上 18:00-24:00 } #endregion #region 设置房间时段不可用============================================================ // POST: Api/SQRoomPricing/SetRoomUnavailable /// /// 设置房间时段不可用 /// /// 房间ID /// 日期 /// 时段类型(0=凌晨,1=上午,2=下午,3=晚上) /// 不可用类型(1=禁用/维护,2=后台预约,3=线下预约) /// 原因/备注 /// [HttpPost] [Description("设置房间时段不可用")] public async Task SetRoomUnavailable([FromBody] SetRoomUnavailableRequest request) { var jm = new AdminUiCallBack(); try { // 参数验证 if (request.roomId <= 0) { jm.msg = "请选择房间"; return jm; } if (string.IsNullOrEmpty(request.date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(request.date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } if (request.timeSlotType < 0 || request.timeSlotType > 3) { jm.msg = "时段类型不正确"; return jm; } if (request.type < 1 || request.type > 3) { jm.msg = "不可用类型不正确"; return jm; } // 检查房间是否存在 var room = await _SQRoomsServices.QueryByIdAsync(request.roomId); if (room == null) { jm.msg = "房间不存在"; return jm; } // 根据时段类型计算开始和结束时间 var (startTime, endTime) = GetTimeSlotRange(dateValue, request.timeSlotType); // 检查该时段是否已有用户预约 var hasReservation = await _SQReservationsServices.ExistsAsync( r => r.room_id == request.roomId && r.status < 4 && // 排除已取消的预约 r.start_time < endTime && r.end_time > startTime ); if (hasReservation) { jm.msg = "该时段已有用户预约,请先处理预约后再设置禁用"; return jm; } // 检查是否已存在禁用记录 var existingRecord = await _SQRoomUnavailableTimesServices.QueryByClauseAsync( u => u.room_id == request.roomId && u.time_slot_type == request.timeSlotType && u.start_time == startTime && u.end_time == endTime, u => u.id, OrderByType.Asc ); if (existingRecord != null) { // 更新现有记录 existingRecord.type = request.type; existingRecord.reason = request.reason; await _SQRoomUnavailableTimesServices.UpdateAsync(existingRecord); jm.code = 0; jm.msg = "更新成功"; } else { // 新增记录 var newRecord = new SQRoomUnavailableTimes { room_id = request.roomId, start_time = startTime, end_time = endTime, time_slot_type = request.timeSlotType, type = request.type, reason = request.reason, created_at = DateTime.Now }; await _SQRoomUnavailableTimesServices.InsertAsync(newRecord); jm.code = 0; jm.msg = "设置成功"; } } catch (Exception ex) { jm.msg = "设置失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "设置房间不可用", "SetRoomUnavailable", ex); } return jm; } /// /// 根据时段类型获取时间范围 /// private (DateTime startTime, DateTime endTime) GetTimeSlotRange(DateTime date, int timeSlotType) { var baseDate = date.Date; return timeSlotType switch { 0 => (baseDate, baseDate.AddHours(6)), // 凌晨 00:00-06:00 1 => (baseDate.AddHours(6), baseDate.AddHours(12)), // 上午 06:00-12:00 2 => (baseDate.AddHours(12), baseDate.AddHours(18)), // 下午 12:00-18:00 3 => (baseDate.AddHours(18), baseDate.AddDays(1)), // 晚上 18:00-24:00 _ => (baseDate, baseDate.AddDays(1)) }; } #endregion #region 取消房间时段不可用============================================================ // POST: Api/SQRoomPricing/CancelRoomUnavailable /// /// 取消房间时段不可用 /// /// 不可用记录ID /// [HttpPost] [Description("取消房间时段不可用")] public async Task CancelRoomUnavailable([FromBody] CancelRoomUnavailableRequest request) { var jm = new AdminUiCallBack(); try { if (request.ids == null || request.ids.Length == 0) { jm.msg = "请选择要取消的记录"; return jm; } await _SQRoomUnavailableTimesServices.DeleteByIdsAsync(request.ids); jm.code = 0; jm.msg = "取消成功"; } catch (Exception ex) { jm.msg = "取消失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "取消房间不可用", "CancelRoomUnavailable", ex); } return jm; } #endregion #region 取消房间整天不可用============================================================ // POST: Api/SQRoomPricing/CancelRoomUnavailableAllDay /// /// 取消房间整天不可用(删除该日期的所有禁用记录) /// /// 房间ID /// 日期 /// [HttpPost] [Description("取消房间整天不可用")] public async Task CancelRoomUnavailableAllDay([FromBody] CancelRoomUnavailableAllDayRequest request) { var jm = new AdminUiCallBack(); try { // 参数验证 if (request.roomId <= 0) { jm.msg = "请选择房间"; return jm; } if (string.IsNullOrEmpty(request.date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(request.date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } // 检查房间是否存在 var room = await _SQRoomsServices.QueryByIdAsync(request.roomId); if (room == null) { jm.msg = "房间不存在"; return jm; } // 获取该日期的开始和结束时间 var startOfDay = dateValue.Date; var endOfDay = dateValue.Date.AddDays(1); // 查询该房间该日期的所有禁用记录 var unavailableRecords = await _SQRoomUnavailableTimesServices.QueryListByClauseAsync( u => u.room_id == request.roomId && u.start_time >= startOfDay && u.start_time < endOfDay ); if (unavailableRecords == null || unavailableRecords.Count == 0) { jm.msg = "该日期没有禁用记录"; return jm; } // 获取所有记录的ID var ids = unavailableRecords.Select(r => r.id).ToArray(); // 批量删除 await _SQRoomUnavailableTimesServices.DeleteByIdsAsync(ids); jm.code = 0; jm.msg = $"取消成功,共删除 {ids.Length} 条禁用记录"; } catch (Exception ex) { jm.msg = "取消失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "取消房间整天不可用", "CancelRoomUnavailableAllDay", ex); } return jm; } #endregion #region 设置房间整天不可用============================================================ // POST: Api/SQRoomPricing/SetRoomUnavailableAllDay /// /// 设置房间整天不可用(禁用所有时段,类型为维护) /// /// 房间ID /// 日期 /// [HttpPost] [Description("设置房间整天不可用")] public async Task SetRoomUnavailableAllDay([FromBody] SetRoomUnavailableAllDayRequest request) { var jm = new AdminUiCallBack(); try { // 参数验证 if (request.roomId <= 0) { jm.msg = "请选择房间"; return jm; } if (string.IsNullOrEmpty(request.date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(request.date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } // 检查房间是否存在 var room = await _SQRoomsServices.QueryByIdAsync(request.roomId); if (room == null) { jm.msg = "房间不存在"; return jm; } // 检查该日期是否已有用户预约 var startOfDay = dateValue.Date; var endOfDay = dateValue.Date.AddDays(1); var hasReservation = await _SQReservationsServices.ExistsAsync( r => r.room_id == request.roomId && r.status < 4 && // 排除已取消的预约 r.start_time < endOfDay && r.end_time > startOfDay ); if (hasReservation) { jm.msg = "该日期已有用户预约,请先处理预约后再设置禁用"; return jm; } // 禁用类型为维护(type=1),原因默认为"整天维护" var maintenanceType = 1; var defaultReason = "整天维护"; // 遍历所有4个时段,设置禁用 var successCount = 0; var updateCount = 0; var insertCount = 0; for (int timeSlotType = 0; timeSlotType <= 3; timeSlotType++) { var (startTime, endTime) = GetTimeSlotRange(dateValue, timeSlotType); // 检查是否已存在禁用记录 var existingRecord = await _SQRoomUnavailableTimesServices.QueryByClauseAsync( u => u.room_id == request.roomId && u.time_slot_type == timeSlotType && u.start_time == startTime && u.end_time == endTime, u => u.id, OrderByType.Asc ); if (existingRecord != null) { // 更新现有记录为维护类型 existingRecord.type = maintenanceType; existingRecord.reason = defaultReason; await _SQRoomUnavailableTimesServices.UpdateAsync(existingRecord); updateCount++; } else { // 新增记录 var newRecord = new SQRoomUnavailableTimes { room_id = request.roomId, start_time = startTime, end_time = endTime, time_slot_type = timeSlotType, type = maintenanceType, reason = defaultReason, created_at = DateTime.Now }; await _SQRoomUnavailableTimesServices.InsertAsync(newRecord); insertCount++; } successCount++; } jm.code = 0; jm.msg = $"禁用成功,共设置 {successCount} 个时段(新增 {insertCount} 条,更新 {updateCount} 条)"; } catch (Exception ex) { jm.msg = "禁用失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "设置房间整天不可用", "SetRoomUnavailableAllDay", ex); } return jm; } #endregion #region 获取房间某日期的禁用列表============================================================ // GET: Api/SQRoomPricing/GetRoomUnavailableList /// /// 获取房间某日期的禁用列表 /// /// 房间ID /// 日期 /// [HttpGet] [Description("获取房间禁用列表")] public async Task GetRoomUnavailableList([FromQuery] int roomId, [FromQuery] string date) { var jm = new AdminUiCallBack(); try { if (roomId <= 0) { jm.msg = "请选择房间"; return jm; } if (string.IsNullOrEmpty(date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } // 获取该日期的开始和结束时间 var startOfDay = dateValue.Date; var endOfDay = dateValue.Date.AddDays(1); // 查询该房间该日期的所有禁用记录 var list = await _SQRoomUnavailableTimesServices.QueryListByClauseAsync( u => u.room_id == roomId && u.start_time >= startOfDay && u.start_time < endOfDay, u => u.time_slot_type, OrderByType.Asc ); // 时段名称映射 var slotNames = new[] { "凌晨", "上午", "下午", "晚上" }; var typeNames = new Dictionary { { 1, "禁用/维护" }, { 2, "后台预约" }, { 3, "线下预约" } }; var result = list.Select(item => new { item.id, item.room_id, item.time_slot_type, slot_name = item.time_slot_type.HasValue && item.time_slot_type.Value >= 0 && item.time_slot_type.Value <= 3 ? slotNames[item.time_slot_type.Value] : "未知", item.type, type_name = typeNames.ContainsKey(item.type) ? typeNames[item.type] : "未知", item.reason, start_time = item.start_time.ToString("yyyy-MM-dd HH:mm:ss"), end_time = item.end_time.ToString("yyyy-MM-dd HH:mm:ss"), created_at = item.created_at.ToString("yyyy-MM-dd HH:mm:ss") }).ToList(); jm.code = 0; jm.msg = "获取成功"; jm.data = result; } catch (Exception ex) { jm.msg = "获取失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "获取房间禁用列表", "GetRoomUnavailableList", ex); } return jm; } #endregion #region 节假日价格管理============================================================ // GET: Api/SQRoomPricing/GetHolidayPricing /// /// 获取某日期的节假日价格(用于弹窗回显) /// /// 日期 /// 房间ID /// [HttpGet] [Description("获取节假日价格")] public async Task GetHolidayPricing([FromQuery] string date, [FromQuery] int roomId) { var jm = new AdminUiCallBack(); try { // 参数验证 if (roomId <= 0) { jm.msg = "请选择房间"; return jm; } if (string.IsNullOrEmpty(date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } // 检查房间是否存在 var room = await _SQRoomsServices.QueryByIdAsync(roomId); if (room == null) { jm.msg = "房间不存在"; return jm; } // 查询节假日价格 var holidayPricing = await _SQRoomPricingServices.GetHolidayPricingByDateAsync(roomId, dateValue); // 查询默认价格(用于对比) var defaultPricing = await _SQRoomPricingServices.GetRoomAllPricingAsync(roomId, null); // 时段名称映射 var slotNames = new[] { "凌晨", "上午", "下午", "晚上" }; // 构建返回数据(包含所有4个时段) var result = new List(); for (int slotType = 0; slotType <= 3; slotType++) { var holidaySlot = holidayPricing.FirstOrDefault(p => p.time_slot_type == slotType); var defaultSlot = defaultPricing.FirstOrDefault(p => p.time_slot_type == slotType); result.Add(new { time_slot_type = slotType, slot_name = slotNames[slotType], has_holiday_price = holidaySlot != null, // 节假日价格描述 holiday_price_desc_standard = holidaySlot?.price_desc_standard ?? "", holiday_price_desc_member = holidaySlot?.price_desc_member ?? "", // 默认价格描述(用于前端显示对比) default_price_desc_standard = defaultSlot?.price_desc_standard ?? "", default_price_desc_member = defaultSlot?.price_desc_member ?? "" }); } jm.code = 0; jm.msg = "获取成功"; jm.data = new { date = date, room_id = roomId, room_name = room.name, slots = result }; } catch (Exception ex) { jm.msg = "获取失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "获取节假日价格", "GetHolidayPricing", ex); } return jm; } // POST: Api/SQRoomPricing/DoSetHolidayPricing /// /// 设置节假日价格(保存) /// /// [HttpPost] [Description("设置节假日价格")] public async Task DoSetHolidayPricing([FromBody] SetHolidayPricingRequest request) { var jm = new AdminUiCallBack(); try { // 参数验证 if (string.IsNullOrEmpty(request.date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(request.date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } if (request.roomIds == null || request.roomIds.Length == 0) { jm.msg = "请选择房间"; return jm; } if (request.slots == null || request.slots.Length == 0) { jm.msg = "请至少启用一个时段"; return jm; } var successCount = 0; var errorMsg = ""; // 遍历房间 foreach (var roomId in request.roomIds) { // 检查房间是否存在 var room = await _SQRoomsServices.QueryByIdAsync(roomId); if (room == null) { errorMsg = $"房间ID {roomId} 不存在"; continue; } // 先删除该房间该日期已有的节假日价格 await _SQRoomPricingServices.DeleteHolidayPricingAsync(roomId, dateValue); // 保存新的节假日价格 foreach (var slot in request.slots) { if (!slot.enabled) { continue; // 未启用的时段不保存 } var pricing = new SQRoomPricing { room_id = roomId, time_slot_type = slot.time_slot_type, standard_price = 0, // 不使用此字段,但数据库要求非空,设为0 member_price = 0, // 不使用此字段,但数据库要求非空,设为0 price_desc_standard = slot.price_desc_standard, price_desc_member = slot.price_desc_member, effective_date_start = dateValue.Date, effective_date_end = dateValue.Date, is_active = true, created_at = DateTime.Now, updated_at = DateTime.Now }; await _SQRoomPricingServices.InsertAsync(pricing); } successCount++; } if (successCount > 0) { jm.code = 0; jm.msg = $"设置成功,共设置 {successCount} 个房间的节假日价格"; } else { jm.msg = errorMsg ?? "设置失败"; } } catch (Exception ex) { jm.msg = "设置失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "设置节假日价格", "DoSetHolidayPricing", ex); } return jm; } // POST: Api/SQRoomPricing/DoCancelHolidayPricing /// /// 取消节假日价格(删除该日期的特殊价格) /// /// [HttpPost] [Description("取消节假日价格")] public async Task DoCancelHolidayPricing([FromBody] CancelHolidayPricingRequest request) { var jm = new AdminUiCallBack(); try { // 参数验证 if (string.IsNullOrEmpty(request.date)) { jm.msg = "请选择日期"; return jm; } if (!DateTime.TryParse(request.date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } if (request.roomIds == null || request.roomIds.Length == 0) { jm.msg = "请选择房间"; return jm; } var successCount = 0; // 遍历房间,删除节假日价格 foreach (var roomId in request.roomIds) { var result = await _SQRoomPricingServices.DeleteHolidayPricingAsync(roomId, dateValue); if (result) { successCount++; } } if (successCount > 0) { jm.code = 0; jm.msg = $"取消成功,共取消 {successCount} 个房间的节假日价格"; } else { jm.msg = "取消失败或该日期没有节假日价格"; } } catch (Exception ex) { jm.msg = "取消失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "取消节假日价格", "DoCancelHolidayPricing", ex); } return jm; } // GET: Api/SQRoomPricing/HasHolidayPricing /// /// 查询某日期是否设置了节假日价格(用于右键菜单显示) /// /// 日期 /// 房间ID /// [HttpGet] [Description("检查是否有节假日价格")] public async Task HasHolidayPricing([FromQuery] string date, [FromQuery] int roomId) { var jm = new AdminUiCallBack(); try { if (roomId <= 0 || string.IsNullOrEmpty(date)) { jm.msg = "参数错误"; return jm; } if (!DateTime.TryParse(date, out DateTime dateValue)) { jm.msg = "日期格式不正确"; return jm; } var hasHolidayPrice = await _SQRoomPricingServices.HasHolidayPricingAsync(roomId, dateValue); jm.code = 0; jm.msg = "查询成功"; jm.data = new { has_holiday_price = hasHolidayPrice }; } catch (Exception ex) { jm.msg = "查询失败:" + ex.Message; NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "检查节假日价格", "HasHolidayPricing", ex); } return jm; } #endregion } #region 请求参数类 /// /// 设置房间不可用请求参数 /// public class SetRoomUnavailableRequest { /// /// 房间ID /// public int roomId { get; set; } /// /// 日期 (YYYY-MM-DD) /// public string date { get; set; } /// /// 时段类型(0=凌晨,1=上午,2=下午,3=晚上) /// public int timeSlotType { get; set; } /// /// 不可用类型(1=禁用/维护,2=后台预约,3=线下预约) /// public int type { get; set; } /// /// 原因/备注 /// public string reason { get; set; } } /// /// 取消房间不可用请求参数 /// public class CancelRoomUnavailableRequest { /// /// 不可用记录ID数组 /// public int[] ids { get; set; } } /// /// 设置房间整天不可用请求参数 /// public class SetRoomUnavailableAllDayRequest { /// /// 房间ID /// public int roomId { get; set; } /// /// 日期 (YYYY-MM-DD) /// public string date { get; set; } } /// /// 取消房间整天不可用请求参数 /// public class CancelRoomUnavailableAllDayRequest { /// /// 房间ID /// public int roomId { get; set; } /// /// 日期 (YYYY-MM-DD) /// public string date { get; set; } } /// /// 设置节假日价格请求参数 /// public class SetHolidayPricingRequest { /// /// 日期 (YYYY-MM-DD) /// public string date { get; set; } /// /// 房间ID数组 /// public int[] roomIds { get; set; } /// /// 时段价格列表 /// public HolidaySlotPrice[] slots { get; set; } } /// /// 节假日时段价格 /// public class HolidaySlotPrice { /// /// 时段类型(0=凌晨,1=上午,2=下午,3=晚上) /// public int time_slot_type { get; set; } /// /// 是否启用该时段节假日价格 /// public bool enabled { get; set; } /// /// 标准价格描述(文本,如:"150元/时段") /// public string price_desc_standard { get; set; } /// /// 会员价格描述(文本,如:"120元/时段") /// public string price_desc_member { get; set; } } /// /// 取消节假日价格请求参数 /// public class CancelHolidayPricingRequest { /// /// 日期 (YYYY-MM-DD) /// public string date { get; set; } /// /// 房间ID数组 /// public int[] roomIds { get; set; } } #endregion }