This commit is contained in:
zpc 2025-09-11 16:50:02 +08:00
parent 8c1e46b591
commit 8381a2cbab
8 changed files with 272 additions and 80 deletions

View File

@ -113,6 +113,6 @@ namespace CoreCms.Net.IServices
/// <param name="toUserId"></param>
/// <param name="type"></param>
/// <returns></returns>
Task<bool> UserBlackUser(int userId, int toUserId, int type);
Task<bool> UserBlackUser(int userId, int toUserId, int type, string reason = "");
}
}

View File

@ -18,16 +18,19 @@ namespace CoreCms.Net.Model.ViewModels.SQ
}
[AutoMap(typeof(SQReservations))]
public class SQReservationsApiDto : SQReservations
public class SQReservationsApiDto : SQReservationsBaseDto
{
public List<SQReservationParticipantsApiDto> Participants { get; set; }
}
/// <summary>
///
/// </summary>
[AutoMap(typeof(SQReservations))]
public class SQReservationsMyDto : SQReservations
public class SQReservationsMyDto : SQReservationsBaseDto
{
/// <summary>
///
/// </summary>
public int pid { get; set; }
/// <summary>
/// 加入时间
/// </summary>
@ -53,6 +56,19 @@ namespace CoreCms.Net.Model.ViewModels.SQ
public System.Int32 pstatus { get; set; }
}
/// <summary>
/// 基类
/// </summary>
public class SQReservationsBaseDto : SQReservations
{
/// <summary>
/// 参与人员
/// </summary>
public List<SQReservationParticipantsApiDto> Participants { get; set; }
}

View File

@ -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
{
/// <summary>
/// 昵称
/// </summary>
public string BlockedNickName { get; set; }
/// <summary>
/// 头像
/// </summary>
public string BlockedAvatarImage { get; set; }
}
}

View File

@ -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
{
/// <summary>
///
/// </summary>
/// <param name="sQReservationParticipants"></param>
/// <returns></returns>
public static async Task<List<SQReservationParticipantsApiDto>> LoadSQReservationParticipantsApiDtoId(List<int> rIds, int userId, SqlSugarScope _dbBase, ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices)
{
if (rIds != null && rIds.Count > 0)
{
string sqlWhere = string.Join(",", rIds);
var participants = await _dbBase.Ado.SqlQueryAsync<SQReservationParticipantsApiDto>($"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<int>();
//如果用户登录了
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<SQReservationParticipantsApiDto>();
}
/// <summary>
/// 加载组局参与者信息
/// </summary>
/// <param name="list">预约信息</param>
/// <param name="userId">当前用户</param>
/// <param name="_dbBase"></param>
/// <param name="_coreCmsUserBlacklistServices"></param>
/// <param name="_mapper"></param>
/// <returns></returns>
public static async Task<bool> LoadSQReservationParticipantsApiDto(this List<SQReservationsBaseDto> 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<SQReservationParticipantsApiDto>($"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<int>();
//如果用户登录了
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<List<SQReservationParticipantsApiDto>>(temp);
item.Participants = dto;
}
}
}
return true;
}
}
}

View File

@ -167,7 +167,7 @@ namespace CoreCms.Net.Services
return list;
}
public async Task<bool> UserBlackUser(int userId, int toUserId, int type)
public async Task<bool> 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);
}

View File

@ -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;
/// <summary>
@ -71,20 +76,27 @@ public class SQController : ControllerBase
_coreCmsUserBlacklistServices = coreCmsUserBlacklistServices;
}
/// <summary>
///
/// 我的预约记录
/// </summary>
/// <param name="type">1发起者0参与者</param>
/// <param name="type">0 参与者1发起者</param>
/// <param name="index">起始页</param>
/// <param name="size">页大小</param>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<WebApiDto> GetMyReservation([FromQuery] int type = 0)
public async Task<WebApiDto> 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<SQReservationsMyDto>($"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<SQReservationsMyDto>($"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<SQReservationsBaseDto>().ToList();
await baseList.LoadSQReservationParticipantsApiDto(userId, _dbBase, _coreCmsUserBlacklistServices, _mapper);
}
return new WebApiDto()
{
Data = list,
@ -93,7 +105,31 @@ public class SQController : ControllerBase
}
/// <summary>
///
/// 获取正在进行的预约
/// </summary>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<WebApiDto> GetMyUseReservation()
{
var userId = _user.ID;
var list = await _dbBase.Ado.SqlQueryAsync<SQReservationsApiDto>($"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<SQReservationsBaseDto>().ToList();
await baseList.LoadSQReservationParticipantsApiDto(userId, _dbBase, _coreCmsUserBlacklistServices, _mapper);
}
return new WebApiDto()
{
Data = list,
Code = 0,
};
}
/// <summary>
/// 首页预约列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
@ -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<SQReservationsApiDto>>(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<SQReservationParticipantsApiDto>($"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<int>();
//如果用户登录了
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<List<SQReservationParticipantsApiDto>>(temp);
item.Participants = dto;
}
}
//var participants = await _SQReservationParticipantsServices.QueryListByClauseAsync(it => rIds.Contains(it.reservation_id), "", true);
//List<CoreCmsUser> userList = new List<CoreCmsUser>();
//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<List<SQReservationParticipantsDto>>(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<SQReservationsBaseDto>().ToList();
await baseList.LoadSQReservationParticipantsApiDto(userId, _dbBase, _coreCmsUserBlacklistServices, _mapper);
}
return new WebApiDto()
{

View File

@ -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();
/// <summary>
@ -123,7 +125,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
, ICoreCmsSettingServices settingServices
, ICoreCmsServicesServices servicesServices
, IOptions<WeChatOptions> 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;
}
/// <summary>
/// wx.login登陆成功之后发送的请求
@ -2287,5 +2291,61 @@ namespace CoreCms.Net.Web.WebApi.Controllers
#endregion
/// <summary>
/// 获取黑名单列表
/// </summary>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<WebApiDto> GetMyBlackList()
{
var userId = _user.ID;
var list = await _dbBase.Ado.SqlQueryAsync<CoreCmsUserBlacklistDto>($"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
};
}
/// <summary>
/// 添加黑名单
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiDto> 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 ? "已添加黑名单" : "已在黑名单中"
};
}
/// <summary>
/// 取消拉黑名单
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<WebApiDto> CancelUserBlack([FromBody] FMIntId entity)
{
var userId = _user.ID;
var toUserId = entity.id;
await _coreCmsUserBlacklistServices.UserBlackUser(userId, toUserId, 1);
return new WebApiDto()
{
Code = 0,
Msg = "已取消拉黑"
};
}
//
}
}

View File

@ -767,11 +767,13 @@
构造函数
</summary>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.GetMyReservation(System.Int32)">
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.GetMyReservation(System.Int32,System.Int32,System.Int32)">
<summary>
我的预约记录
</summary>
<param name="type">1发起者0参与者</param>
<param name="type">0 参与者1发起者</param>
<param name="index">起始页</param>
<param name="size">页大小</param>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.GetReservationList(System.Int32,System.Int32)">
@ -908,6 +910,12 @@
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.AnonymousLogin">
<summary>
匿名登录
</summary>
<returns></returns>
</member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.OnLogin(CoreCms.Net.Model.FromBody.FMWxPost)">
<summary>
wx.login登陆成功之后发送的请求