diff --git a/CoreCms.Net.IServices/User/ICoreCmsUserBlacklistServices.cs b/CoreCms.Net.IServices/User/ICoreCmsUserBlacklistServices.cs index 13577df..ee31586 100644 --- a/CoreCms.Net.IServices/User/ICoreCmsUserBlacklistServices.cs +++ b/CoreCms.Net.IServices/User/ICoreCmsUserBlacklistServices.cs @@ -113,6 +113,6 @@ namespace CoreCms.Net.IServices /// /// /// - Task UserBlackUser(int userId, int toUserId, int type); + Task UserBlackUser(int userId, int toUserId, int type, string reason = ""); } } diff --git a/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs b/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs index de3da48..f33b439 100644 --- a/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs +++ b/CoreCms.Net.Model/ViewModels/SQ/SQReservationsDto.cs @@ -18,16 +18,19 @@ namespace CoreCms.Net.Model.ViewModels.SQ } [AutoMap(typeof(SQReservations))] - public class SQReservationsApiDto : SQReservations + public class SQReservationsApiDto : SQReservationsBaseDto { - public List Participants { get; set; } } /// /// /// [AutoMap(typeof(SQReservations))] - public class SQReservationsMyDto : SQReservations + public class SQReservationsMyDto : SQReservationsBaseDto { + /// + /// + /// + public int pid { get; set; } /// /// 加入时间 /// @@ -53,6 +56,19 @@ namespace CoreCms.Net.Model.ViewModels.SQ public System.Int32 pstatus { get; set; } + + } + + /// + /// 基类 + /// + public class SQReservationsBaseDto : SQReservations + { + /// + /// 参与人员 + /// + + public List Participants { get; set; } } diff --git a/CoreCms.Net.Model/ViewModels/User/CoreCmsUserBlacklistDto.cs b/CoreCms.Net.Model/ViewModels/User/CoreCmsUserBlacklistDto.cs new file mode 100644 index 0000000..3922ef4 --- /dev/null +++ b/CoreCms.Net.Model/ViewModels/User/CoreCmsUserBlacklistDto.cs @@ -0,0 +1,25 @@ +using AutoMapper; + +using CoreCms.Net.Model.Entities; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreCms.Net.Model.ViewModels.User +{ + [AutoMap(typeof(CoreCmsUserBlacklist))] + public class CoreCmsUserBlacklistDto : CoreCmsUserBlacklist + { + /// + /// 昵称 + /// + public string BlockedNickName { get; set; } + /// + /// 头像 + /// + public string BlockedAvatarImage { get; set; } + } +} diff --git a/CoreCms.Net.Services/SQ/SQServices.cs b/CoreCms.Net.Services/SQ/SQServices.cs new file mode 100644 index 0000000..39d8a8d --- /dev/null +++ b/CoreCms.Net.Services/SQ/SQServices.cs @@ -0,0 +1,99 @@ +using AutoMapper; + +using CoreCms.Net.IServices; +using CoreCms.Net.Model.ViewModels.SQ; + +using Kdbndp.KingbaseTypes; + +using SqlSugar; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinUserInfoBatchGetRequest.Types; + +namespace CoreCms.Net.Services.SQ +{ + public static class SQServices + { + /// + /// + /// + /// + /// + public static async Task> LoadSQReservationParticipantsApiDtoId(List rIds, int userId, SqlSugarScope _dbBase, ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices) + { + if (rIds != null && rIds.Count > 0) + { + string sqlWhere = string.Join(",", rIds); + var participants = await _dbBase.Ado.SqlQueryAsync($"select p.id,p.reservation_id,p.status,p.join_time,p.user_id, p.role,u.nickName UserName,u.avatarImage AvatarImage from SQReservationParticipants p inner join CoreCmsUser u on p.user_id=u.id where p.status=0 and p.reservation_id in ({sqlWhere})"); + if (participants != null && participants.Count > 0) + { + var userBlacklist = new List(); + //如果用户登录了 + userBlacklist = await _coreCmsUserBlacklistServices.GetUserBlacklists(userId); + //并且用户有黑名单数据 + if (userBlacklist.Count > 0) + { + //查找并修改黑名单用户 + foreach (var participant in participants.Where(it => userBlacklist.Contains(it.user_id))) + { + participant.UserBlackStatus = 1; + } + } + + } + return participants; + } + return new List(); + } + + /// + /// 加载组局参与者信息 + /// + /// 预约信息 + /// 当前用户 + /// + /// + /// + /// + public static async Task LoadSQReservationParticipantsApiDto(this List list, int userId, SqlSugarScope _dbBase, ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices, IMapper _mapper) + { + var rIds = list.Select(it => it.id).ToList(); + if (rIds != null && rIds.Count > 0) + { + string sqlWhere = string.Join(",", rIds); + var participants = await _dbBase.Ado.SqlQueryAsync($"select p.id,p.reservation_id,p.status,p.join_time,p.user_id, p.role,u.nickName UserName,u.avatarImage AvatarImage from SQReservationParticipants p inner join CoreCmsUser u on p.user_id=u.id where p.status=0 and p.reservation_id in ({sqlWhere})"); + if (participants != null && participants.Count > 0) + { + + if (userId > 0) + { + var userBlacklist = new List(); + //如果用户登录了 + userBlacklist = await _coreCmsUserBlacklistServices.GetUserBlacklists(userId); + //并且用户有黑名单数据 + if (userBlacklist.Count > 0) + { + //查找并修改黑名单用户 + foreach (var participant in participants.Where(it => userBlacklist.Contains(it.user_id))) + { + participant.UserBlackStatus = 1; + } + } + } + foreach (var item in list) + { + var temp = participants.Where(it => it.reservation_id == item.id).OrderBy(it => it.role).ThenBy(it => it.status).ToList(); + var dto = _mapper.Map>(temp); + item.Participants = dto; + } + } + } + return true; + } + } +} diff --git a/CoreCms.Net.Services/User/CoreCmsUserBlacklistServices.cs b/CoreCms.Net.Services/User/CoreCmsUserBlacklistServices.cs index 19d6b35..cfb83d3 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserBlacklistServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserBlacklistServices.cs @@ -167,7 +167,7 @@ namespace CoreCms.Net.Services return list; } - public async Task UserBlackUser(int userId, int toUserId, int type) + public async Task UserBlackUser(int userId, int toUserId, int type, string reason = "") { if (userId == 0) { @@ -176,12 +176,17 @@ namespace CoreCms.Net.Services if (type == 0) { + var black = await _dal.QueryByClauseAsync(it => it.UserId == userId && it.BlockedUserId == toUserId); + if (black != null) + { + return false; + } CoreCmsUserBlacklist coreCmsUserBlacklist = new CoreCmsUserBlacklist() { UserId = userId, CreatedTime = DateTime.Now, BlockedUserId = toUserId, - Reason = "", + Reason = reason, }; await _dal.InsertAsync(coreCmsUserBlacklist); } diff --git a/CoreCms.Net.Web.WebApi/Controllers/SQController.cs b/CoreCms.Net.Web.WebApi/Controllers/SQController.cs index 5700061..65a2b88 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/SQController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/SQController.cs @@ -5,22 +5,27 @@ using CoreCms.Net.IRepository.UnitOfWork; using CoreCms.Net.IServices; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities.Expression; +using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.SQ; using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Services; +using CoreCms.Net.Services.SQ; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; + using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - +using CoreCms.Net.Services.SQ; +using CoreCms.Net.Utility.Extensions; namespace CoreCms.Net.Web.WebApi.Controllers; /// @@ -71,20 +76,27 @@ public class SQController : ControllerBase _coreCmsUserBlacklistServices = coreCmsUserBlacklistServices; } + /// - /// + /// 我的预约记录 /// - /// 1发起者,0参与者 + /// 0 参与者,1发起者 + /// 起始页 + /// 页大小 /// [HttpGet] [Authorize] - public async Task GetMyReservation([FromQuery] int type = 0) + public async Task GetMyReservation([FromQuery] int type = 0, [FromQuery] int index = 1, [FromQuery] int size = 10) { var userId = _user.ID; - //var list = await _SQReservationsServices.GetMyReservation(userId); - var list = await _dbBase.Ado.SqlQueryAsync($"select r.*, p.status pstatus,p.join_time, p.quit_time ,p.is_refund from SQReservationParticipants p inner join SQReservations r on p.reservation_id=r.id where p.user_id={userId} and p.role={type}"); - //SQReservationsMyDto + var list = await _dbBase.Ado.SqlQueryAsync($"select top r.*,p.id pid, p.status pstatus,p.join_time, p.quit_time ,p.is_refund from SQReservationParticipants p inner join SQReservations r on p.reservation_id=r.id where p.user_id={userId} and p.role={type} order by p.id desc OFFSET {(index - 1) * size} ROWS FETCH NEXT {size} ROWS ONLY"); + if (list != null && list.Count > 0) + { + // 转为基类列表 + var baseList = list.Cast().ToList(); + await baseList.LoadSQReservationParticipantsApiDto(userId, _dbBase, _coreCmsUserBlacklistServices, _mapper); + } return new WebApiDto() { Data = list, @@ -93,7 +105,31 @@ public class SQController : ControllerBase } /// - /// + /// 获取正在进行的预约 + /// + /// + [HttpGet] + [Authorize] + public async Task GetMyUseReservation() + { + var userId = _user.ID; + + var list = await _dbBase.Ado.SqlQueryAsync($"select top 3 r.* from SQReservations r left join SQReservationParticipants p on r.id=p.reservation_id where r.status<2 and p.user_id={userId} and p.status=0 order by r.start_time "); + if (list != null && list.Count > 0) + { + // 转为基类列表 + var baseList = list.Cast().ToList(); + await baseList.LoadSQReservationParticipantsApiDto(userId, _dbBase, _coreCmsUserBlacklistServices, _mapper); + } + return new WebApiDto() + { + Data = list, + Code = 0, + }; + } + + /// + /// 首页预约列表 /// /// /// @@ -109,68 +145,11 @@ public class SQController : ControllerBase where = where.And(it => it.status < 2); var list = await _SQReservationsServices.QueryPageAsync(where, it => it.start_time, OrderByType.Asc, pageIndex, pageSize, true); var pageList = _mapper.Map>(list); - var rIds = list.Select(it => it.id).ToList(); - if (rIds != null && rIds.Count > 0) + if (pageList != null && pageList.Count > 0) { - string sqlWhere = string.Join(",", rIds); - var participants = await _dbBase.Ado.SqlQueryAsync($"select p.id,p.reservation_id,p.status,p.join_time,p.user_id, p.role,u.nickName UserName,u.avatarImage AvatarImage from SQReservationParticipants p inner join CoreCmsUser u on p.user_id=u.id where p.status=0 and p.reservation_id in ({sqlWhere})"); - if (participants != null && participants.Count > 0) - { - var userBlacklist = new List(); - //如果用户登录了 - if (userId > 0) - { - - userBlacklist = await _coreCmsUserBlacklistServices.GetUserBlacklists(userId); - //并且用户有黑名单数据 - if (userBlacklist.Count > 0) - { - //查找并修改黑名单用户 - foreach (var participant in participants.Where(it => userBlacklist.Contains(it.user_id))) - { - participant.UserBlackStatus = 1; - } - } - } - foreach (var item in pageList) - { - var temp = participants.Where(it => it.reservation_id == item.id).OrderBy(it => it.role).ThenBy(it => it.status).ToList(); - var room = roomList.Find(it => it.id == item.room_id); - if (room != null) - { - item.room_name = $"{room.name} {room.price_per_hour.ToString("#.##")}/小时 {room.capacity}/人数"; - - } - var dto = _mapper.Map>(temp); - item.Participants = dto; - } - } - //var participants = await _SQReservationParticipantsServices.QueryListByClauseAsync(it => rIds.Contains(it.reservation_id), "", true); - //List userList = new List(); - //if (participants != null && participants.Count > 0) - //{ - // var userIds = participants.Select(it => it.user_id).ToList(); - // userList = await _userServices.QueryListByClauseAsync(it => userIds.Contains(it.id), "", true); - //} - //foreach (var item in pageList) - //{ - // var temp = participants.Where(it => it.reservation_id == item.id).OrderBy(it => it.role).ThenBy(it => it.status).ToList(); - // var dto = _mapper.Map>(temp); - // if (userList != null && userList.Count > 0) - // { - // foreach (var p in dto) - // { - // var u = userList.FirstOrDefault(it => it.id == p.user_id); - // if (u != null) - // { - // p.UserName = u.nickName; - // p.AvatarImage = u.avatarImage; - // } - // } - - // } - // item.Participants = dto; - //} + // 转为基类列表 + var baseList = pageList.Cast().ToList(); + await baseList.LoadSQReservationParticipantsApiDto(userId, _dbBase, _coreCmsUserBlacklistServices, _mapper); } return new WebApiDto() { diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 3fc3ad7..11ca8f9 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -48,6 +48,7 @@ using SqlSugar; using DotLiquid.Util; using System.IO; using System.Text.RegularExpressions; +using CoreCms.Net.Model.ViewModels.User; namespace CoreCms.Net.Web.WebApi.Controllers { @@ -91,7 +92,8 @@ namespace CoreCms.Net.Web.WebApi.Controllers private readonly IToolsServices _toolsServices; private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory; private readonly WeChatOptions _weChatOptions; - + private readonly ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices; + private readonly SqlSugarScope _dbBase; private readonly AsyncLock _mutex = new AsyncLock(); /// @@ -123,7 +125,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers , ICoreCmsSettingServices settingServices , ICoreCmsServicesServices servicesServices , IOptions weChatOptions - , ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsStoreServices storeServices, ICoreCmsCouponServices couponServices, ICoreCmsOrderServices orderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IToolsServices toolsServices) + , ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsStoreServices storeServices, ICoreCmsCouponServices couponServices, ICoreCmsOrderServices orderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IToolsServices toolsServices, ICoreCmsUserBlacklistServices coreCmsUserBlacklistServices, SqlSugarScope dbBase) { _user = user; _userWeChatInfoServices = userWeChatInfoServices; @@ -157,6 +159,8 @@ namespace CoreCms.Net.Web.WebApi.Controllers _weChatApiHttpClientFactory = weChatApiHttpClientFactory; _weChatOptions = weChatOptions.Value; _toolsServices = toolsServices; + _coreCmsUserBlacklistServices = coreCmsUserBlacklistServices; + _dbBase = dbBase; } /// /// wx.login登陆成功之后发送的请求 @@ -2287,5 +2291,61 @@ namespace CoreCms.Net.Web.WebApi.Controllers #endregion + /// + /// 获取黑名单列表 + /// + /// + [HttpGet] + [Authorize] + public async Task GetMyBlackList() + { + var userId = _user.ID; + var list = await _dbBase.Ado.SqlQueryAsync($"select b.*,u.nickName as BlockedNickName,u.avatarImage as BlockedAvatarImage from CoreCmsUserBlacklist b left join CoreCmsUser u on b.BlockedUserId=u.id where b.UserId={userId}"); + return new WebApiDto() + { + Code = 0, + Data = list + }; + } + + + /// + /// 添加黑名单 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task AddUserBlack([FromBody] FMIntId entity) + { + var userId = _user.ID; + var toUserId = entity.id; + var isSuccess = await _coreCmsUserBlacklistServices.UserBlackUser(userId, toUserId, 0, "用户主动拉黑"); + return new WebApiDto() + { + Code = 0, + Msg = isSuccess ? "已添加黑名单" : "已在黑名单中" + }; + } + + /// + /// 取消拉黑名单 + /// + /// + /// + [HttpPost] + [Authorize] + public async Task CancelUserBlack([FromBody] FMIntId entity) + { + var userId = _user.ID; + var toUserId = entity.id; + await _coreCmsUserBlacklistServices.UserBlackUser(userId, toUserId, 1); + return new WebApiDto() + { + Code = 0, + Msg = "已取消拉黑" + }; + } + // } } \ No newline at end of file diff --git a/CoreCms.Net.Web.WebApi/Doc.xml b/CoreCms.Net.Web.WebApi/Doc.xml index 3c3f97b..7439348 100644 --- a/CoreCms.Net.Web.WebApi/Doc.xml +++ b/CoreCms.Net.Web.WebApi/Doc.xml @@ -767,11 +767,13 @@ 构造函数 - + - + 我的预约记录 - 1发起者,0参与者 + 0 参与者,1发起者 + 起始页 + 页大小 @@ -908,6 +910,12 @@ + + + 匿名登录 + + + wx.login登陆成功之后发送的请求