2026-06-03 16:09:56 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-07-09 18:01:37 +08:00
|
|
|
|
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
|
2026-06-03 16:09:56 +08:00
|
|
|
|
using QYZH.InteractiveMagazine.IService;
|
2026-06-05 17:57:24 +08:00
|
|
|
|
|
2026-06-03 16:09:56 +08:00
|
|
|
|
using QYZH.InteractiveMagazine.Models.Common;
|
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto;
|
2026-06-10 17:53:38 +08:00
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto.CheckIn;
|
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto.Compensation;
|
2026-06-08 16:57:44 +08:00
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto.Points;
|
2026-06-03 16:09:56 +08:00
|
|
|
|
|
|
|
|
|
|
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用户控制器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
public class UsersController : BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IUsersService _usersService;
|
|
|
|
|
|
private readonly ILogger<UsersController> _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public UsersController(IUsersService usersService, ILogger<UsersController> logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
_usersService = usersService;
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取用户列表(分页)
|
|
|
|
|
|
/// </summary>
|
2026-07-03 11:24:28 +08:00
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<BaseResponse<PageListModel<UsersOutput>>> GetList([FromBody] UsersQueryInput input)
|
2026-06-03 16:09:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await _usersService.GetListAsync(input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-10 17:53:38 +08:00
|
|
|
|
/// 获取用户详情(仅基本信息)
|
2026-06-03 16:09:56 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpGet("{id}")]
|
2026-06-08 16:57:44 +08:00
|
|
|
|
public async Task<BaseResponse<UserDetailOutput>> GetDetail(long id)
|
2026-06-03 16:09:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await _usersService.GetDetailAsync(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-10 17:53:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分页查询用户积分记录
|
|
|
|
|
|
/// </summary>
|
2026-07-03 11:24:28 +08:00
|
|
|
|
[HttpPost("{id}/pointsRecords")]
|
|
|
|
|
|
public async Task<BaseResponse<PageListModel<PointsRecordOutput>>> GetUserPointsRecords(long id, [FromBody] PointsRecordQueryInput input)
|
2026-06-10 17:53:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await _usersService.GetUserPointsRecordsAsync(id, input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分页查询用户签到记录
|
|
|
|
|
|
/// </summary>
|
2026-07-03 11:24:28 +08:00
|
|
|
|
[HttpPost("{id}/checkInRecords")]
|
|
|
|
|
|
public async Task<BaseResponse<PageListModel<CheckInRecordOutput>>> GetUserCheckInRecords(long id, [FromBody] PageQueryModel input)
|
2026-06-10 17:53:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await _usersService.GetUserCheckInRecordsAsync(id, input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分页查询用户补偿任务
|
|
|
|
|
|
/// </summary>
|
2026-07-03 11:24:28 +08:00
|
|
|
|
[HttpPost("{id}/compensationTasks")]
|
|
|
|
|
|
public async Task<BaseResponse<PageListModel<CompensationTaskOutput>>> GetUserCompensationTasks(long id, [FromBody] CompensationTaskQueryInput input)
|
2026-06-10 17:53:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await _usersService.GetUserCompensationTasksAsync(id, input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分页查询用户期刊列表
|
|
|
|
|
|
/// </summary>
|
2026-07-03 11:24:28 +08:00
|
|
|
|
[HttpPost("{id}/journals")]
|
|
|
|
|
|
public async Task<BaseResponse<PageListModel<UserJournalItemOutput>>> GetUserJournals(long id, [FromBody] UserJournalQueryInput input)
|
2026-06-10 17:53:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
return await _usersService.GetUserJournalsAsync(id, input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-03 16:09:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新用户状态
|
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
|
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.User)]
|
2026-06-03 16:09:56 +08:00
|
|
|
|
[HttpPut("{id}/status")]
|
2026-06-09 11:41:28 +08:00
|
|
|
|
public async Task<BaseResponse> UpdateStatus(long id)
|
2026-06-03 16:09:56 +08:00
|
|
|
|
{
|
2026-06-09 11:41:28 +08:00
|
|
|
|
return await _usersService.UpdateStatusAsync(id);
|
2026-06-03 16:09:56 +08:00
|
|
|
|
}
|
2026-06-08 16:57:44 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 手动增加用户积分
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost("{userId}/points/add")]
|
|
|
|
|
|
public async Task<BaseResponse<ManualPointsOutput>> ManualAddPoints(long userId, [FromBody] ManualAddPointsInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var operatorId = GetCurrentUserId() ?? 0;
|
|
|
|
|
|
var operatorName = GetCurrentUserName() ?? "Unknown";
|
|
|
|
|
|
var ipAddress = HttpContext.Connection.RemoteIpAddress?.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
var result = await _usersService.ManualAddPointsAsync(userId, input, operatorId, operatorName, ipAddress);
|
|
|
|
|
|
return Success(result, "手动增加积分成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (BusinessException ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogWarning(ex, "手动增加积分业务异常: {Message}", ex.Message);
|
|
|
|
|
|
return BaseResponse<ManualPointsOutput>.Fail(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "手动增加积分系统异常,UserId: {UserId}", userId);
|
|
|
|
|
|
return BaseResponse<ManualPointsOutput>.Fail("手动增加积分失败,请稍后重试");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 手动扣除用户积分
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost("{userId}/points/deduct")]
|
|
|
|
|
|
public async Task<BaseResponse<ManualPointsOutput>> ManualDeductPoints(long userId, [FromBody] ManualDeductPointsInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var operatorId = GetCurrentUserId() ?? 0;
|
|
|
|
|
|
var operatorName = GetCurrentUserName() ?? "Unknown";
|
|
|
|
|
|
var ipAddress = HttpContext.Connection.RemoteIpAddress?.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
var result = await _usersService.ManualDeductPointsAsync(userId, input, operatorId, operatorName, ipAddress);
|
|
|
|
|
|
return Success(result, "手动扣除积分成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (BusinessException ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogWarning(ex, "手动扣除积分业务异常: {Message}", ex.Message);
|
|
|
|
|
|
return BaseResponse<ManualPointsOutput>.Fail(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "手动扣除积分系统异常,UserId: {UserId}", userId);
|
|
|
|
|
|
return BaseResponse<ManualPointsOutput>.Fail("手动扣除积分失败,请稍后重试");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-03 16:09:56 +08:00
|
|
|
|
}
|