This commit is contained in:
zpc 2025-09-15 17:11:33 +08:00
parent 9a67d1705f
commit c961b35fd8
2 changed files with 84 additions and 5 deletions

View File

@ -102,7 +102,26 @@ namespace CoreCms.Net.Model.ViewModels.SQ
[StringLength(maximumLength: 255, ErrorMessage = "{0}不能超过{1}字")]
public new System.String remarks { get; set; }
/// <summary>
/// 重要信息
/// </summary>
public string important_data { get; set; }
}
public class SQReservationParticipantsAddDto
{
/// <summary>
/// 预约ID
/// </summary>
public new System.Int32 ReservationsId { get; set; }
/// <summary>
/// 重要信息
/// </summary>
public string important_data { get; set; }
}
}

View File

@ -29,6 +29,7 @@ using CoreCms.Net.Utility.Extensions;
using ToolGood.Words.internals;
using NPOI.SS.Formula.PTG;
using NPOI.OpenXmlFormats.Dml;
using Humanizer;
namespace CoreCms.Net.Web.WebApi.Controllers;
/// <summary>
@ -544,6 +545,7 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
role = 1,
status = 0,
is_refund = dto.deposit_fee > 0 ? 1 : 0,
important_data = dto.important_data
};
await _SQReservationParticipantsServices.InsertAsync(participant);
@ -554,17 +556,18 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
Msg = "预约成功"
};
}
/// <summary>
/// 用户加入预约接口
/// </summary>
/// <param name="reservationId">预约ID</param>
/// <param name="dto">预约</param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiDto> JoinReservation([FromBody] int reservationId)
public async Task<WebApiDto> JoinReservation([FromBody] SQReservationParticipantsAddDto dto)
{
var userId = _user.ID;
var reservationId = dto.ReservationsId;
// 1. 校验预约是否存在且未结束
var reservation = await _SQReservationsServices.QueryByClauseAsync(
r => r.id == reservationId && r.end_time > DateTime.Now && r.status < 2,
@ -593,6 +596,61 @@ 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 < reservation.end_time && r.end_time > reservation.start_time // 时间有重叠
);
if (hasConflict != null && hasConflict.Count > 0)
{
return new WebApiDto
{
Code = 402,
Data = null,
Msg = "您有其它预约时间冲突,无法加入该预约"
};
}
//// 查询用户所有未结束的预约参与记录
//var userReservations = await _SQReservationParticipantsServices.QueryListByClauseAsync(
// p => p.user_id == userId && p.status == 0, // 只查未退出的
// p => p.id, OrderByType.Asc);
//if (userReservations != null && userReservations.Count > 0)
//{
// // 获取这些预约的ID
// var reservationIds = userReservations.Select(p => p.reservation_id).ToList();
// // 查询这些预约的时间段
// var reservations = await _SQReservationsServices.QueryListByClauseAsync(
// r => reservationIds.Contains(r.id) && r.status < 2 && r.end_time > DateTime.Now,
// r => r.id, OrderByType.Asc);
// // 检查时间是否有重叠
// foreach (var r in reservations)
// {
// if (r.start_time < reservation.end_time && r.end_time > reservation.start_time)
// {
// return new WebApiDto
// {
// Code = 402,
// Data = null,
// Msg = "您有其它预约时间冲突,无法加入该预约"
// };
// }
// }
//}
//3.校验预约是否已满(如有容量限制,可补充)
var participantsCount = await _SQReservationParticipantsServices.QueryListByClauseAsync(
p => p.reservation_id == reservationId, p => p.id, OrderByType.Asc);
@ -613,7 +671,9 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
user_id = userId,
join_time = DateTime.Now,
role = 0, // 0为参与者
status = 0
status = 0,
is_refund = reservation.deposit_fee > 0 ? 1 : 0,
important_data = dto.important_data
};
await _SQReservationParticipantsServices.InsertAsync(participant);