From 4a7111fe4c006c094851f44ed26af04f7f02074c Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 3 Sep 2025 04:08:16 +0800 Subject: [PATCH] 333 --- .../FromBody/FMAddParticipant.cs | 34 +++ .../FromBody/FMBecomeInitiator.cs | 41 ++++ .../SQ/SQReservationsController.cs | 209 ++++++++++++++++++ CoreCms.Net.Web.Admin/Doc.xml | 18 ++ .../views/sq/sqreservations/index.html | 165 ++++++++++++-- 5 files changed, 454 insertions(+), 13 deletions(-) create mode 100644 CoreCms.Net.Model/FromBody/FMAddParticipant.cs create mode 100644 CoreCms.Net.Model/FromBody/FMBecomeInitiator.cs diff --git a/CoreCms.Net.Model/FromBody/FMAddParticipant.cs b/CoreCms.Net.Model/FromBody/FMAddParticipant.cs new file mode 100644 index 0000000..681da5b --- /dev/null +++ b/CoreCms.Net.Model/FromBody/FMAddParticipant.cs @@ -0,0 +1,34 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2025/1/15 10:00:00 + * Description: 添加参与者请求模型 + ***********************************************************************/ + +using System.ComponentModel.DataAnnotations; + +namespace CoreCms.Net.Model.FromBody +{ + /// + /// 添加参与者请求模型 + /// + public class FMAddParticipant + { + /// + /// 预约ID + /// + [Display(Name = "预约ID")] + [Required(ErrorMessage = "请输入预约ID")] + public int reservationId { get; set; } + + /// + /// 用户ID + /// + [Display(Name = "用户ID")] + [Required(ErrorMessage = "请输入用户ID")] + public int userId { get; set; } + } +} diff --git a/CoreCms.Net.Model/FromBody/FMBecomeInitiator.cs b/CoreCms.Net.Model/FromBody/FMBecomeInitiator.cs new file mode 100644 index 0000000..6df33e0 --- /dev/null +++ b/CoreCms.Net.Model/FromBody/FMBecomeInitiator.cs @@ -0,0 +1,41 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2025/1/15 10:00:00 + * Description: 设置发起者请求模型 + ***********************************************************************/ + +using System.ComponentModel.DataAnnotations; + +namespace CoreCms.Net.Model.FromBody +{ + /// + /// 设置发起者请求模型 + /// + public class FMBecomeInitiator + { + /// + /// 预约ID + /// + [Display(Name = "预约ID")] + [Required(ErrorMessage = "请输入预约ID")] + public int reservationId { get; set; } + + /// + /// 参与者ID + /// + [Display(Name = "参与者ID")] + [Required(ErrorMessage = "请输入参与者ID")] + public int participantId { get; set; } + + /// + /// 用户ID + /// + [Display(Name = "用户ID")] + [Required(ErrorMessage = "请输入用户ID")] + public int userId { get; set; } + } +} diff --git a/CoreCms.Net.Web.Admin/Controllers/SQ/SQReservationsController.cs b/CoreCms.Net.Web.Admin/Controllers/SQ/SQReservationsController.cs index 2d8e510..e9add25 100644 --- a/CoreCms.Net.Web.Admin/Controllers/SQ/SQReservationsController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/SQ/SQReservationsController.cs @@ -1194,5 +1194,214 @@ ICoreCmsUserServices userServices } #endregion + + #region SearchUsers + // POST: Api/SQReservations/SearchUsers + /// + /// 搜索用户 + /// + /// + [HttpPost] + [Description("搜索用户")] + public async Task SearchUsers() + { + var jm = new AdminUiCallBack(); + var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1); + var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(10); + var searchText = Request.Form["searchText"].FirstOrDefault(); + + var where = PredicateBuilder.True(); + + // 搜索条件 + if (!string.IsNullOrEmpty(searchText)) + { + // 支持按用户名、昵称、手机号搜索 + where = where.And(p => p.userName.Contains(searchText) || + p.nickName.Contains(searchText) || + p.mobile.Contains(searchText) || + p.id.ToString().Contains(searchText)); + } + + // 只查询正常状态的用户 + where = where.And(p => p.isDelete == false); + + var list = await _userServices.QueryPageAsync(where, p => p.id, OrderByType.Desc, pageCurrent, pageSize); + + jm.code = 0; + jm.count = list.TotalCount; + jm.msg = "查询成功"; + jm.data = list.Select(p => new + { + id = p.id, + userName = p.userName, + nickName = p.nickName, + mobile = p.mobile + }).ToList(); + + return jm; + } + + // POST: Api/SQReservations/AddParticipant + /// + /// 添加参与者 + /// + /// + [HttpPost] + [Description("添加参与者")] + public async Task AddParticipant([FromBody] FMAddParticipant entity) + { + var jm = new AdminUiCallBack(); + + try + { + // 验证参数 + if (entity.reservationId <= 0 || entity.userId <= 0) + { + jm.msg = "参数错误"; + return jm; + } + + // 检查预约是否存在 + var reservation = await _SQReservationsServices.QueryByIdAsync(entity.reservationId); + if (reservation == null) + { + jm.msg = "预约不存在"; + return jm; + } + + // 检查用户是否存在 + var user = await _userServices.QueryByIdAsync(entity.userId); + if (user == null) + { + jm.msg = "用户不存在"; + return jm; + } + + // 检查用户是否已经是参与者 + var existingParticipant = await _SQReservationParticipantsServices.QueryListByClauseAsync(p => + p.reservation_id == entity.reservationId && + p.user_id == entity.userId); + + if (existingParticipant.Any()) + { + jm.msg = "该用户已经是参与者"; + return jm; + } + + // 创建新的参与者记录 + var participant = new SQReservationParticipants + { + reservation_id = entity.reservationId, + user_id = entity.userId, + role = 0, // 0=参与者 + join_time = DateTime.Now, + status = 0, // 0=正常 + is_refund = 0, // 0=无需退款 + remarks = $"后台于{DateTime.Now:yyyy-MM-dd HH:mm:ss}添加" + }; + + var result = await _SQReservationParticipantsServices.InsertAsync(participant); + + if (result.code == 0) + { + jm.code = 0; + jm.msg = "添加参与者成功"; + } + else + { + jm.msg = "添加参与者失败"; + } + } + catch (Exception ex) + { + jm.msg = "添加参与者时发生错误:" + ex.Message; + } + + return jm; + } + + // POST: Api/SQReservations/BecomeInitiator + /// + /// 设置发起者 + /// + /// + [HttpPost] + [Description("设置发起者")] + public async Task BecomeInitiator([FromBody] FMBecomeInitiator entity) + { + var jm = new AdminUiCallBack(); + + try + { + // 验证参数 + if (entity.reservationId <= 0 || entity.participantId <= 0 || entity.userId <= 0) + { + jm.msg = "参数错误"; + return jm; + } + + // 检查预约是否存在 + var reservation = await _SQReservationsServices.QueryByIdAsync(entity.reservationId); + if (reservation == null) + { + jm.msg = "预约不存在"; + return jm; + } + + // 检查参与者是否存在 + var participant = await _SQReservationParticipantsServices.QueryByIdAsync(entity.participantId); + if (participant == null) + { + jm.msg = "参与者不存在"; + return jm; + } + + // 检查用户是否存在 + var user = await _userServices.QueryByIdAsync(entity.userId); + if (user == null) + { + jm.msg = "用户不存在"; + return jm; + } + + // 检查该预约是否已有发起者 + var existingInitiator = await _SQReservationParticipantsServices.QueryListByClauseAsync(p => + p.reservation_id == entity.reservationId && + p.role == 1); // 1=发起者 + + if (existingInitiator.Any()) + { + // 如果已有发起者,将其改为参与者 + var oldInitiator = existingInitiator.First(); + oldInitiator.role = 0; // 0=参与者 + oldInitiator.remarks = $"后台于{DateTime.Now:yyyy-MM-dd HH:mm:ss}将原发起者改为参与者"; + await _SQReservationParticipantsServices.UpdateAsync(oldInitiator); + } + + // 将指定参与者设置为发起者 + participant.role = 1; // 1=发起者 + participant.remarks = $"后台于{DateTime.Now:yyyy-MM-dd HH:mm:ss}设置为发起者"; + var result = await _SQReservationParticipantsServices.UpdateAsync(participant); + + if (result.code == 0) + { + jm.code = 0; + jm.msg = "设置发起者成功"; + } + else + { + jm.msg = "设置发起者失败"; + } + } + catch (Exception ex) + { + jm.msg = "设置发起者时发生错误:" + ex.Message; + } + + return jm; + } + #endregion + + } } diff --git a/CoreCms.Net.Web.Admin/Doc.xml b/CoreCms.Net.Web.Admin/Doc.xml index 336fced..9c07e23 100644 --- a/CoreCms.Net.Web.Admin/Doc.xml +++ b/CoreCms.Net.Web.Admin/Doc.xml @@ -3824,6 +3824,24 @@ + + + 搜索用户 + + + + + + 添加参与者 + + + + + + 设置发起者 + + + 房间表 diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/sq/sqreservations/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/sq/sqreservations/index.html index d20bb51..95af389 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/sq/sqreservations/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/sq/sqreservations/index.html @@ -204,7 +204,12 @@ { title: '参与人员', sort: false, width: 300, templet: function (d) { if (!d.participants || d.participants.length === 0) { - return '
暂无参与人员
'; + return '
' + + '参与者' + + '(0人)' + + '添加参与者' + + '
' + + '
暂无参与人员
'; } var html = '
'; @@ -239,17 +244,20 @@ html += '
'; } - // 显示参与者 - if (participants.length > 0) { - // 统计正常状态的参与者数量 - var normalParticipantsCount = participants.filter(function (it) { - return it.status == 0; - }).length; + // 显示参与者标签(无论是否有参与者都要显示) + // 统计正常状态的参与者数量 + var normalParticipantsCount = participants.filter(function (it) { + return it.status == 0; + }).length; - html += '
'; - html += '参与者'; - html += '(' + normalParticipantsCount + '人)'; - html += '
'; + html += '
'; + html += '参与者'; + html += '(' + normalParticipantsCount + '人)'; + html += '添加参与者'; + html += '
'; + + // 显示参与者列表 + if (participants.length > 0) { participants.forEach(function (it, index) { var statusText = ''; @@ -264,14 +272,15 @@ html += '
'; html += '
'; - html += '' + (it.UserName || '用户' + it.user_id) + ''; + html += '' + (it.userName || '用户' + it.user_id) + ''; html += '(ID: ' + it.user_id + ')'; if (statusText) { html += '' + statusText + ''; } - // 当用户状态为正常时,显示强制退出按钮 + // 当用户状态为正常时,显示强制退出按钮和成为发起者按钮 if (it.status == 0) { html += '强制退出'; + html += '成为发起者'; } html += '
'; @@ -326,6 +335,9 @@ html += '
'; }); + } else { + // 如果没有参与者,显示提示信息 + html += '
暂无参与人员
'; } html += ''; @@ -724,4 +736,131 @@ }); }); } + + // 添加参与者函数 + function addParticipant(reservationId) { + // 弹出添加参与者窗口 + layer.open({ + type: 1, + title: '添加参与者', + area: ['800px', '600px'], + content: ` +
+
+
+ +
+ + +
+
+
+
+
+
+
+ `, + success: function(layero, index) { + // 初始化用户表格 + layui.use(['table'], function() { + var table = layui.table; + table.render({ + elem: '#userTable', + url: layui.setter.apiUrl + 'Api/SQReservations/SearchUsers', + method: 'POST', + page: true, + limit: 10, + limits: [10, 20, 50], + cols: [[ + {type: 'radio', fixed: 'left'}, + {field: 'id', title: '用户ID', width: 80}, + {field: 'userName', title: '用户名', width: 150}, + {field: 'nickName', title: '昵称', width: 150}, + {field: 'mobile', title: '手机号', width: 120}, + {field: 'email', title: '邮箱', width: 200} + ]], + done: function() { + // 监听行选择 + table.on('radio(userTable)', function(obj) { + // 存储选中的用户 + window.selectedUser = obj.data; + }); + } + }); + }); + }, + btn: ['确定', '取消'], + yes: function(index, layero) { + if (!window.selectedUser) { + layer.msg('请先选择一个用户', {icon: 2}); + return; + } + + // 确认添加参与者 + layer.confirm('确定要添加用户 "' + window.selectedUser.userName + '" 为参与者吗?', { + icon: 3, + title: '确认添加' + }, function(confirmIndex) { + layer.close(confirmIndex); + + // 调用API添加参与者 + coreHelper.Post("Api/SQReservations/AddParticipant", { + reservationId: reservationId, + userId: window.selectedUser.id + }, function(e) { + if (e.code === 0) { + layer.msg('添加参与者成功', {icon: 1}); + layer.close(index); + // 重新加载表格数据 + layui.table.reloadData('LAY-app-SQReservations-tableBox'); + } else { + layer.msg(e.msg || '添加失败', {icon: 2}); + } + }); + }); + } + }); + } + + // 搜索用户函数 + function searchUsers() { + var searchText = document.getElementById('searchUserInput').value.trim(); + if (!searchText) { + layer.msg('请输入搜索内容', {icon: 2}); + return; + } + + // 重新加载用户表格 + layui.table.reloadData('userTable', { + where: { + searchText: searchText + } + }); + } + + // 成为发起者函数 + function becomeInitiator(participant, reservationId) { + layer.confirm('确定要将用户 "' + (participant.UserName || '用户' + participant.user_id) + '" 设置为发起者吗?', { + icon: 3, + title: '确认操作' + }, function(index) { + // 关闭确认框 + layer.close(index); + + // 调用API设置发起者 + coreHelper.Post("Api/SQReservations/BecomeInitiator", { + reservationId: reservationId, + participantId: participant.id, + userId: participant.user_id + }, function(e) { + if (e.code === 0) { + layer.msg('设置发起者成功', {icon: 1}); + // 重新加载表格数据 + layui.table.reloadData('LAY-app-SQReservations-tableBox'); + } else { + layer.msg(e.msg || '操作失败', {icon: 2}); + } + }); + }); + } \ No newline at end of file