This commit is contained in:
zpc 2025-09-17 12:39:48 +08:00
parent 5b2b9b7de8
commit 24b6e43b4e
3 changed files with 151 additions and 2 deletions

View File

@ -146,4 +146,22 @@ namespace CoreCms.Net.Model.ViewModels.SQ
public string important_data { get; set; }
}
/// <summary>
/// 取消预约DTO
/// </summary>
public class SQReservationCancelDto
{
/// <summary>
/// 预约ID
/// </summary>
[Required(ErrorMessage = "请输入预约ID")]
public int reservation_id { get; set; }
/// <summary>
/// 取消原因
/// </summary>
[StringLength(maximumLength: 255, ErrorMessage = "取消原因不能超过{1}字")]
public string cancel_reason { get; set; }
}
}

View File

@ -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 = "加入预约成功"
};
}
/// <summary>
/// 取消预约接口
/// </summary>
/// <param name="dto">取消预约参数</param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiDto> 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 = "取消预约成功"
};
}
}

View File

@ -842,6 +842,13 @@
<param name="dto">预约</param>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.CancelReservation(CoreCms.Net.Model.ViewModels.SQ.SQReservationCancelDto)">
<summary>
取消预约接口
</summary>
<param name="dto">取消预约参数</param>
<returns></returns>
</member>
<member name="T:CoreCms.Net.Web.WebApi.Controllers.StoreController">
<summary>
门店调用接口数据