修改挂单功能
This commit is contained in:
57
web/App_Code/Model/Partial/GuaDanOrderGuest.cs
Normal file
57
web/App_Code/Model/Partial/GuaDanOrderGuest.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
/// <summary>
|
||||
/// GuaDanOrderGuest 的摘要描述
|
||||
/// </summary>
|
||||
namespace Model
|
||||
{
|
||||
public partial class GuaDanOrderGuest
|
||||
{
|
||||
// 状态常量定义
|
||||
public const string STATUS_BOOKED = "401"; // 预订成功
|
||||
public const string STATUS_CHECKED_IN = "402"; // 已入住
|
||||
public const string STATUS_CHECKED_OUT = "403"; // 已退房
|
||||
public const string STATUS_CANCELLED = "404"; // 已取消
|
||||
|
||||
public static bool IsStatusTransitionValid(ezEntities db, string targetStatus, Guid guestId)
|
||||
{
|
||||
// 获取当前客人对象
|
||||
GuaDanOrderGuest currentGuest = db.GuaDanOrderGuest.Find(guestId);
|
||||
if (currentGuest == null)
|
||||
{
|
||||
// 如果没有客人对象,只能创建新的预订
|
||||
return targetStatus == STATUS_BOOKED;
|
||||
}
|
||||
|
||||
// 安全获取当前状态(处理null情况)
|
||||
string currentStatus = currentGuest.RegionRoomBedStatus?.Code;
|
||||
|
||||
// 如果当前状态为空,只能进入预订成功状态
|
||||
if (string.IsNullOrEmpty(currentStatus))
|
||||
{
|
||||
return targetStatus == STATUS_BOOKED;
|
||||
}
|
||||
|
||||
// 定义有效的状态转换规则
|
||||
var validTransitions = new Dictionary<string, List<string>>
|
||||
{
|
||||
{ STATUS_BOOKED, new List<string> { STATUS_CHECKED_IN, STATUS_CANCELLED } },
|
||||
{ STATUS_CHECKED_IN, new List<string> { STATUS_CHECKED_OUT } },
|
||||
{ STATUS_CHECKED_OUT, new List<string> { } }, // 终态,不能再转换
|
||||
{ STATUS_CANCELLED, new List<string> { } } // 终态,不能再转换
|
||||
};
|
||||
|
||||
// 检查转换是否有效
|
||||
if (validTransitions.ContainsKey(currentStatus))
|
||||
{
|
||||
return validTransitions[currentStatus].Contains(targetStatus);
|
||||
}
|
||||
|
||||
return false; // 未知的当前状态
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace Model
|
||||
|
||||
// 找出在日期範圍內被占用的床位 Uuid(包括長期占用 ScheduleDate = null)
|
||||
var busyBedUuidsQuery = db.RegionAndRoomAndBedSchedule
|
||||
.Where(s => s.IsDeleted == false && s.IsActive
|
||||
.Where(s => s.IsDeleted == false && !s.IsCancel
|
||||
&& (s.ScheduleDate == null
|
||||
|| (end.HasValue
|
||||
&& s.ScheduleDate >= start
|
||||
@@ -79,25 +79,28 @@ namespace Model
|
||||
public static async Task<bool> IsBedAvailableAsync(ezEntities db, Guid targetUuid, DateTime start, DateTime? end)
|
||||
{
|
||||
// 如果 end 為 null,表示長期占用,直接判斷是否已有長期占用
|
||||
//不包含结束时间那一天
|
||||
if (end == null)
|
||||
{
|
||||
var hasLongTerm = await db.RegionAndRoomAndBedSchedule
|
||||
.AnyAsync(s => s.IsDeleted == false
|
||||
&& s.IsActive
|
||||
&& !s.IsCancel
|
||||
&& s.TargetUuid == targetUuid
|
||||
&& s.ScheduleDate == null);
|
||||
return !hasLongTerm;
|
||||
}
|
||||
|
||||
// 短期占用,查詢每日排程中有無衝突
|
||||
var totalDays = (end.Value.Date - start.Date).Days + 1;
|
||||
var totalDays = (end.Value.Date - start.Date).Days;
|
||||
for (int i = 0; i < totalDays; i++)
|
||||
{
|
||||
var date = start.Date.AddDays(i);
|
||||
|
||||
var conflict = await db.RegionAndRoomAndBedSchedule
|
||||
.Where(s => s.GuaDanOrderGuest.StatusCode != GuaDanOrderGuest.STATUS_CANCELLED)
|
||||
.Where(s => s.GuaDanOrderGuest.StatusCode != GuaDanOrderGuest.STATUS_CHECKED_OUT)
|
||||
.AnyAsync(s => s.IsDeleted == false
|
||||
&& s.IsActive
|
||||
&& !s.IsCancel
|
||||
&& s.TargetUuid == targetUuid
|
||||
&& s.ScheduleDate == date);
|
||||
|
||||
@@ -114,7 +117,10 @@ namespace Model
|
||||
|
||||
// 找出所有在日期範圍內被占用的床位
|
||||
var busyBedUuids = await db.RegionAndRoomAndBedSchedule
|
||||
.Where(s => s.IsDeleted == false && s.IsActive
|
||||
.Where(s => s.GuaDanOrderGuest.StatusCode != "403")
|
||||
.Where(s => s.GuaDanOrderGuest.StatusCode != "404")
|
||||
.Where(a => a.IsCancel == false)
|
||||
.Where(s => s.IsDeleted == false
|
||||
&& (s.ScheduleDate == null // 長期占用
|
||||
|| (s.ScheduleDate >= start && s.ScheduleDate <= end)))
|
||||
.Select(s => s.TargetUuid)
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Model
|
||||
{
|
||||
public partial class RegionRoomBed
|
||||
{
|
||||
public const string STATUS_BED_FREE = "101"; // 空閒,可使用
|
||||
public const string STATUS_BED_OCCUPIED = "102"; // 已佔用
|
||||
public const string STATUS_BED_MAINTENANCE = "103"; // 維護中,不可使用
|
||||
public bool IsAvailable()
|
||||
{
|
||||
//判断床位是否可用:自身是否启用
|
||||
@@ -34,7 +37,9 @@ namespace Model
|
||||
// 如果資料庫 ScheduleDate 是 date 型別,本身沒有時間部分,可以直接比較
|
||||
var conflict = _db.RegionAndRoomAndBedSchedule.Any(s =>
|
||||
s.TargetUuid == this.Uuid &&
|
||||
s.IsActive &&
|
||||
s.GuaDanOrderGuest.StatusCode != "403" &&
|
||||
s.GuaDanOrderGuest.StatusCode != "404" &&
|
||||
!s.IsCancel &&
|
||||
!s.IsDeleted &&
|
||||
(
|
||||
s.ScheduleDate == null || // 長期占用
|
||||
@@ -46,5 +51,6 @@ namespace Model
|
||||
|
||||
return !conflict;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,5 +19,6 @@ public class GuaDanOrderView
|
||||
public string bookerName { get; set; }
|
||||
public string bookerPhone { get; set; }
|
||||
public int? bookerFollowerNum { get; set; }
|
||||
public int? activityNum { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user