1. 重构用户、宠物模板、勋章、管理员状态更新接口,移除冗余参数改为自动切换状态 2. 重命名宠物背景枚举为宠物皮肤,调整商品状态字段为枚举类型 3. 新增商品上下架状态管理接口与对应逻辑 4. 新增勋章规则配置系统,支持动态加载可用表和字段 5. 优化商品查询与展示逻辑,适配新的状态字段
107 lines
3.6 KiB
C#
107 lines
3.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using QYZH.InteractiveMagazine.IService;
|
||
|
||
using QYZH.InteractiveMagazine.Models.Common;
|
||
using QYZH.InteractiveMagazine.Models.Dto;
|
||
using QYZH.InteractiveMagazine.Models.Dto.Points;
|
||
|
||
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>
|
||
[HttpGet]
|
||
public async Task<BaseResponse<PageListModel<UsersOutput>>> GetList([FromQuery] UsersQueryInput input)
|
||
{
|
||
return await _usersService.GetListAsync(input);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取用户详情(包含积分记录、签到记录、补偿任务、期刊列表)
|
||
/// </summary>
|
||
[HttpGet("{id}")]
|
||
public async Task<BaseResponse<UserDetailOutput>> GetDetail(long id)
|
||
{
|
||
return await _usersService.GetDetailAsync(id);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新用户状态
|
||
/// </summary>
|
||
[HttpPut("{id}/status")]
|
||
public async Task<BaseResponse> UpdateStatus(long id)
|
||
{
|
||
return await _usersService.UpdateStatusAsync(id);
|
||
}
|
||
|
||
/// <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("手动扣除积分失败,请稍后重试");
|
||
}
|
||
}
|
||
}
|