diff --git a/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs b/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs
index 7b1913d..337d9f6 100644
--- a/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs
+++ b/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs
@@ -146,4 +146,22 @@ namespace CoreCms.Net.Model.ViewModels.SQ
public string important_data { get; set; }
}
+ ///
+ /// 取消预约DTO
+ ///
+ public class SQReservationCancelDto
+ {
+ ///
+ /// 预约ID
+ ///
+ [Required(ErrorMessage = "请输入预约ID")]
+ public int reservation_id { get; set; }
+
+ ///
+ /// 取消原因
+ ///
+ [StringLength(maximumLength: 255, ErrorMessage = "取消原因不能超过{1}字")]
+ public string cancel_reason { get; set; }
+ }
+
}
diff --git a/CoreCms.Net.Web.WebApi/Controllers/SQController.cs b/CoreCms.Net.Web.WebApi/Controllers/SQController.cs
index 953f863..753b29d 100644
--- a/CoreCms.Net.Web.WebApi/Controllers/SQController.cs
+++ b/CoreCms.Net.Web.WebApi/Controllers/SQController.cs
@@ -24,7 +24,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using CoreCms.Net.Services.SQ;
using CoreCms.Net.Utility.Extensions;
using ToolGood.Words.internals;
using NPOI.SS.Formula.PTG;
@@ -725,9 +724,134 @@ ISQRoomUnavailableTimesServices sQRoomUnavailableTimesServices
return new WebApiDto
{
Code = 0,
- Data = null,
+ Data = new { reservation_id = reservationId },
Msg = "加入预约成功"
};
}
+ ///
+ /// 取消预约接口
+ ///
+ /// 取消预约参数
+ ///
+ [HttpPost]
+ [Authorize]
+ public async Task CancelReservation([FromBody] SQReservationCancelDto dto)
+ {
+ var userId = _user.ID;
+
+ // 1. 参数校验
+ if (dto == null || dto.reservation_id <= 0)
+ {
+ return new WebApiDto()
+ {
+ Code = 500,
+ Data = null,
+ Msg = "参数错误"
+ };
+ }
+
+ // 2. 查询预约是否存在
+ var reservation = await _SQReservationsServices.QueryByClauseAsync(
+ r => r.id == dto.reservation_id,
+ r => r.id, OrderByType.Asc);
+ if (reservation == null)
+ {
+ return new WebApiDto()
+ {
+ Code = 404,
+ Data = null,
+ Msg = "预约不存在"
+ };
+ }
+
+ // 3. 检查预约状态是否允许取消
+ if (reservation.status >= 2) // 2=已结束,3=取消,4=用户取消
+ {
+ return new WebApiDto()
+ {
+ Code = 400,
+ Data = null,
+ Msg = "该预约已结束或已取消,无法再次取消"
+ };
+ }
+
+ // 4. 检查用户是否有权限取消该预约
+ var participant = await _SQReservationParticipantsServices.QueryByClauseAsync(
+ p => p.reservation_id == dto.reservation_id && p.user_id == userId,
+ p => p.id, OrderByType.Asc);
+ if (participant == null)
+ {
+ return new WebApiDto()
+ {
+ Code = 403,
+ Data = null,
+ Msg = "您没有权限取消该预约"
+ };
+ }
+
+ // 5. 检查是否已经开始(如果已经开始,只有发起者可以取消)
+ var now = DateTime.Now;
+ if (reservation.start_time <= now && participant.role != 1)
+ {
+ return new WebApiDto()
+ {
+ Code = 400,
+ Data = null,
+ Msg = "预约已开始,只有发起者可以取消"
+ };
+ }
+
+ // 6. 更新预约状态为4(用户取消)
+ var updateResult = await _SQReservationsServices.UpdateAsync(
+ it => new SQReservations
+ {
+ status = 3, // 用户取消
+ updated_at = DateTime.Now,
+ remarks = string.IsNullOrEmpty(dto.cancel_reason) ? "未支付鸽子费" : dto.cancel_reason
+ },
+ it => it.id == dto.reservation_id);
+
+ if (!updateResult)
+ {
+ return new WebApiDto()
+ {
+ Code = 500,
+ Data = null,
+ Msg = "取消预约失败"
+ };
+ }
+
+ // 7. 更新参与人状态为已退出(如果是发起者取消整个预约,所有参与人都标记为退出)
+ if (participant.role == 1) // 发起者取消
+ {
+ // 发起者取消整个预约,所有参与人都标记为退出
+ await _SQReservationParticipantsServices.UpdateAsync(
+ it => new SQReservationParticipants
+ {
+ status = 1, // 已退出
+ quit_time = DateTime.Now
+ },
+ it => it.reservation_id == dto.reservation_id);
+ }
+ else // 参与者取消
+ {
+ // 参与者只退出自己
+ await _SQReservationParticipantsServices.UpdateAsync(
+ it => new SQReservationParticipants
+ {
+ status = 1, // 已退出
+ quit_time = DateTime.Now
+ },
+ it => it.reservation_id == dto.reservation_id && it.user_id == userId);
+ }
+
+ return new WebApiDto()
+ {
+ Code = 0,
+ Data = null,
+ Msg = "取消预约成功"
+ };
+ }
+
}
diff --git a/CoreCms.Net.Web.WebApi/Doc.xml b/CoreCms.Net.Web.WebApi/Doc.xml
index 0192e06..5dcb3b7 100644
--- a/CoreCms.Net.Web.WebApi/Doc.xml
+++ b/CoreCms.Net.Web.WebApi/Doc.xml
@@ -842,6 +842,13 @@
预约
+
+
+ 取消预约接口
+
+ 取消预约参数
+
+
门店调用接口数据