This commit is contained in:
zpc 2025-09-15 17:48:22 +08:00
parent 1f5d6d22b9
commit 97032500cc
2 changed files with 70 additions and 4 deletions

View File

@ -461,8 +461,8 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
public async Task<WebApiDto> AddSQReservation([FromBody] SQReservationsAddDto dto)
{
var userId = _user.ID;
var start_time = DateTimeOffset.FromUnixTimeSeconds(dto.start_time).DateTime;
var end_time = DateTimeOffset.FromUnixTimeSeconds(dto.end_time).DateTime;
var start_time = DateTimeOffset.FromUnixTimeSeconds(dto.start_time).AddHours(8).DateTime;
var end_time = DateTimeOffset.FromUnixTimeSeconds(dto.end_time).AddHours(8).DateTime;
// 1. 参数校验
if (dto == null || dto.room_id <= 0 || start_time >= end_time)
{
@ -486,6 +486,9 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
};
}
// 3. 检查房间是否可预约(不可用时间段)
var hasUnavailable = await _sQRoomUnavailableTimesServices.QueryListByClauseAsync(
t => t.room_id == dto.room_id && t.start_time < end_time && t.end_time > start_time,
@ -500,6 +503,34 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
};
}
// 2.1 校验用户是否有其它预约时间冲突
// 2.1 校验用户是否有其它预约时间冲突(只查未开始或正在进行中的预约)
var now = DateTime.Now;
var hasConflict = await _SQReservationParticipantsServices.QueryMuchAsync<SQReservationParticipants, SQReservations, int>(
(p, r) => new object[]
{
JoinType.Inner, p.reservation_id == r.id
},
(p, r) => r.id,
(p, r) =>
p.user_id == userId &&
p.status == 0 && // 只查未退出
r.status < 2 && // 只查未取消/未结束
r.end_time > now && // 只查未结束
r.start_time < end_time && r.end_time > start_time // 时间有重叠
);
if (hasConflict != null && hasConflict.Count > 0)
{
return new WebApiDto
{
Code = 402,
Data = null,
Msg = "您有其它预约时间冲突,无法加入该预约"
};
}
// 4. 检查房间是否已被预约(未取消的预约,时间有重叠)
var hasReserved = await _SQReservationsServices.QueryListByClauseAsync(
r => r.room_id == dto.room_id && r.status < 2 && r.start_time < end_time && r.end_time > start_time,
@ -524,6 +555,19 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
game_type = dto.game_type,
created_at = DateTime.Now,
updated_at = DateTime.Now,
credit_limit = dto.credit_limit,
player_count = dto.player_count,
deposit_fee = dto.deposit_fee,
duration_minutes = dto.duration_minutes,
extra_info = dto.extra_info,
game_rule = dto.game_rule,
gender_limit = dto.gender_limit,
is_smoking = dto.is_smoking,
max_age = dto.max_age,
min_age = dto.min_age,
remarks = "",
status = 0,
title = dto.title,
// 其他字段可根据需要补充
};
var reservationId = await _dbBase.Insertable(reservation).ExecuteReturnIdentityAsync();

View File

@ -174,7 +174,7 @@
通用调用接口数据
</summary>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.CommonController.#ctor(CoreCms.Net.IServices.ICoreCmsSettingServices,CoreCms.Net.IServices.ICoreCmsAreaServices,Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ICoreCmsServiceDescriptionServices,CoreCms.Net.IServices.ICoreCmsSettingServices,CoreCms.Net.IServices.IToolsServices,CoreCms.Net.IServices.ISQReservationsServices,CoreCms.Net.IServices.ISQRoomsServices,CoreCms.Net.IServices.ISysDictionaryDataServices,CoreCms.Net.IServices.ISysDictionaryServices,CoreCms.Net.IServices.ISQReservationParticipantsServices)">
<member name="M:CoreCms.Net.Web.WebApi.Controllers.CommonController.#ctor(CoreCms.Net.IServices.ICoreCmsSettingServices,CoreCms.Net.IServices.ICoreCmsAreaServices,Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ICoreCmsServiceDescriptionServices,CoreCms.Net.IServices.ICoreCmsSettingServices,CoreCms.Net.IServices.IToolsServices,CoreCms.Net.IServices.ISQReservationsServices,CoreCms.Net.IServices.ISQRoomsServices,CoreCms.Net.IServices.ISysDictionaryDataServices,CoreCms.Net.IServices.ISysDictionaryServices,CoreCms.Net.IServices.ISQReservationParticipantsServices,CoreCms.Net.IServices.ICoreCmsUserWeChatMsgTemplateServices)">
<summary>
构造函数
</summary>
@ -762,7 +762,7 @@
预约接口
</summary>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.#ctor(Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ISQReservationsServices,CoreCms.Net.IServices.ISQRoomsServices,CoreCms.Net.IServices.ISysDictionaryServices,CoreCms.Net.IServices.ISysDictionaryDataServices,CoreCms.Net.IServices.ISQReservationParticipantsServices,AutoMapper.IMapper,CoreCms.Net.IServices.ICoreCmsUserServices,CoreCms.Net.Auth.HttpContextUser.IHttpContextUser,CoreCms.Net.IRepository.UnitOfWork.IUnitOfWork,CoreCms.Net.IServices.ICoreCmsUserBlacklistServices,CoreCms.Net.IServices.ISQReservationEvaluateServices,CoreCms.Net.IServices.ISQReservationReputationServices)">
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.#ctor(Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ISQReservationsServices,CoreCms.Net.IServices.ISQRoomsServices,CoreCms.Net.IServices.ISysDictionaryServices,CoreCms.Net.IServices.ISysDictionaryDataServices,CoreCms.Net.IServices.ISQReservationParticipantsServices,AutoMapper.IMapper,CoreCms.Net.IServices.ICoreCmsUserServices,CoreCms.Net.Auth.HttpContextUser.IHttpContextUser,CoreCms.Net.IRepository.UnitOfWork.IUnitOfWork,CoreCms.Net.IServices.ICoreCmsUserBlacklistServices,CoreCms.Net.IServices.ISQReservationEvaluateServices,CoreCms.Net.IServices.ISQReservationReputationServices,CoreCms.Net.IServices.ISQRoomUnavailableTimesServices)">
<summary>
构造函数
</summary>
@ -820,6 +820,28 @@
<param name="pageSize">每页数量</param>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.GetReservationRoomList(System.Int64,System.Int64)">
<summary>
获取可预约的房间列表
</summary>
<param name="startTime">开始时间 时间戳</param>
<param name="endTime">结束时间 时间戳</param>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.AddSQReservation(CoreCms.Net.Model.ViewModels.SQ.SQReservationsAddDto)">
<summary>
用户预约接口
</summary>
<param name="dto"></param>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.JoinReservation(CoreCms.Net.Model.ViewModels.SQ.SQReservationParticipantsAddDto)">
<summary>
用户加入预约接口
</summary>
<param name="dto">预约</param>
<returns></returns>
</member>
<member name="T:CoreCms.Net.Web.WebApi.Controllers.StoreController">
<summary>
门店调用接口数据