Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.WebApi/Controllers/WeChat/MedalController.cs
glz 8291b82362 feat: 完成宠物模块重构与社区功能开发
本次提交包含多项核心更新:
1.  重构宠物模块数据结构:拆分皮肤图片为独立表,优化Pet、PetEvolution实体,调整字段类型与冗余字段
2.  新增宠物皮肤图片管理表,支持多进化阶段多图片展示
3.  完善宠物DTO,新增当前形态名称、皮肤信息与图片序列返回
4.  新增社区功能模块:
    - 微信端社区Feed流、点赞/取消点赞接口
    - 后台社区消息管理接口与服务实现
5.  优化商城与背包模块,替换皮肤图片获取逻辑为从新表读取预览图
6.  重构勋章服务,新增规则校验逻辑
7.  调整命名规范,修复原有控制器命名问题
2026-06-05 17:15:30 +08:00

100 lines
3.4 KiB
C#

using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
/// <summary>
/// 小程序勋章控制器
/// </summary>
public class MedalController(IMedalService medalService, ILogger<MedalController> logger) : WeChatBaseController
{
/// <summary>
/// 获取所有勋章列表(含当前用户拥有状态)
/// </summary>
[HttpGet("all")]
public async Task<BaseResponse<List<WxMedalListOutput>>> GetAllMedals()
{
try
{
var userId = GetCurrentUserId();
if (userId == null)
{
return BaseResponse<List<WxMedalListOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
}
var result = await medalService.GetAllMedalsAsync(userId.Value);
return Success(result);
}
catch (BusinessException ex)
{
logger.LogWarning(ex, "获取勋章列表业务异常: {Message}", ex.Message);
return BaseResponse<List<WxMedalListOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
logger.LogError(ex, "获取勋章列表系统异常");
return BaseResponse<List<WxMedalListOutput>>.Fail("获取勋章列表失败,请稍后重试");
}
}
/// <summary>
/// 获取用户已拥有的勋章列表
/// </summary>
[HttpGet("my")]
public async Task<BaseResponse<List<WxUserMedalOutput>>> GetUserMedals()
{
try
{
var userId = GetCurrentUserId();
if (userId == null)
{
return BaseResponse<List<WxUserMedalOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
}
var result = await medalService.GetUserMedalsAsync(userId.Value);
return Success(result);
}
catch (BusinessException ex)
{
logger.LogWarning(ex, "获取用户勋章列表业务异常: {Message}", ex.Message);
return BaseResponse<List<WxUserMedalOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
logger.LogError(ex, "获取用户勋章列表系统异常");
return BaseResponse<List<WxUserMedalOutput>>.Fail("获取用户勋章列表失败,请稍后重试");
}
}
/// <summary>
/// 激活/获得勋章
/// </summary>
[HttpPost("activate")]
public async Task<BaseResponse<object>> ActivateMedal([FromBody] WxMedalActivateInput input)
{
try
{
var userId = GetCurrentUserId();
if (userId == null)
{
return BaseResponse<object>.Fail(ResultCode.DENY, "未获取到用户信息");
}
await medalService.ActivateMedalAsync(userId.Value, input);
return Success<object>(null!, "勋章激活成功");
}
catch (BusinessException ex)
{
logger.LogWarning(ex, "激活勋章业务异常: {Message}", ex.Message);
return BaseResponse<object>.Fail(ex.Message);
}
catch (Exception ex)
{
logger.LogError(ex, "激活勋章系统异常,参数:{Input}", input);
return BaseResponse<object>.Fail("激活勋章失败,请稍后重试");
}
}
}