feat: 完成宠物模块重构与社区功能开发
本次提交包含多项核心更新:
1. 重构宠物模块数据结构:拆分皮肤图片为独立表,优化Pet、PetEvolution实体,调整字段类型与冗余字段
2. 新增宠物皮肤图片管理表,支持多进化阶段多图片展示
3. 完善宠物DTO,新增当前形态名称、皮肤信息与图片序列返回
4. 新增社区功能模块:
- 微信端社区Feed流、点赞/取消点赞接口
- 后台社区消息管理接口与服务实现
5. 优化商城与背包模块,替换皮肤图片获取逻辑为从新表读取预览图
6. 重构勋章服务,新增规则校验逻辑
7. 调整命名规范,修复原有控制器命名问题
This commit is contained in:
@ -0,0 +1,163 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 社区消息管理控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
||||
public class CommunityMessageController : BaseController
|
||||
{
|
||||
private readonly ICommunityMessageService _communityMessageService;
|
||||
private readonly ILogger<CommunityMessageController> _logger;
|
||||
|
||||
public CommunityMessageController(ICommunityMessageService communityMessageService, ILogger<CommunityMessageController> logger)
|
||||
{
|
||||
_communityMessageService = communityMessageService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询社区消息列表
|
||||
/// </summary>
|
||||
[HttpPost("list")]
|
||||
public async Task<BaseResponse<PageListModel<AdminMessageDetailOutput>>> GetListAsync([FromBody] AdminMessageQueryInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _communityMessageService.GetListAsync(input);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "查询社区消息列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<PageListModel<AdminMessageDetailOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "查询社区消息列表系统异常,参数:{Input}", input);
|
||||
return BaseResponse<PageListModel<AdminMessageDetailOutput>>.Fail("查询社区消息列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看消息详情
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<BaseResponse<AdminMessageDetailOutput>> GetDetailAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _communityMessageService.GetDetailAsync(id);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "获取社区消息详情业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<AdminMessageDetailOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取社区消息详情系统异常,ID:{Id}", id);
|
||||
return BaseResponse<AdminMessageDetailOutput>.Fail("获取消息详情失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除消息
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _communityMessageService.DeleteAsync(id);
|
||||
return Success(new object(), "删除消息成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "删除社区消息业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "删除社区消息系统异常,ID:{Id}", id);
|
||||
return BaseResponse<object>.Fail("删除消息失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 冻结/解冻消息
|
||||
/// </summary>
|
||||
[HttpPut("{id}/freeze")]
|
||||
public async Task<BaseResponse<object>> FreezeAsync(long id, [FromBody] AdminFreezeInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _communityMessageService.FreezeAsync(id, input.Status);
|
||||
return Success(new object(), input.Status == 2 ? "冻结消息成功" : "解冻消息成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "冻结社区消息业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "冻结社区消息系统异常,ID:{Id}", id);
|
||||
return BaseResponse<object>.Fail("操作失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置/取消精选
|
||||
/// </summary>
|
||||
[HttpPut("{id}/featured")]
|
||||
public async Task<BaseResponse<object>> SetFeaturedAsync(long id, [FromBody] AdminSetFeaturedInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _communityMessageService.SetFeaturedAsync(id, input.IsFeatured);
|
||||
return Success(new object(), input.IsFeatured == 1 ? "设置精选成功" : "取消精选成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "设置社区消息精选业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "设置社区消息精选系统异常,ID:{Id}", id);
|
||||
return BaseResponse<object>.Fail("操作失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置排序权重
|
||||
/// </summary>
|
||||
[HttpPut("{id}/sort")]
|
||||
public async Task<BaseResponse<object>> SetSortOrderAsync(long id, [FromBody] AdminSetSortOrderInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _communityMessageService.SetSortOrderAsync(id, input.SortOrder);
|
||||
return Success(new object(), "设置排序权重成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "设置社区消息排序权重业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "设置社区消息排序权重系统异常,ID:{Id}", id);
|
||||
return BaseResponse<object>.Fail("操作失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
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 CommunityController(IWeChatCommunityService communityService, ILogger<CommunityController> logger) : WeChatBaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取社区Feed流(翻页)
|
||||
/// </summary>
|
||||
/// <param name="cursor">游标(上一页最后一条消息ID,首次不传)</param>
|
||||
[HttpGet("feed")]
|
||||
public async Task<BaseResponse<WxFeedOutput>> GetFeed([FromQuery] long? cursor = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<WxFeedOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.GetFeedAsync(userId.Value, cursor);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "获取社区Feed业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<WxFeedOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取社区Feed系统异常");
|
||||
return BaseResponse<WxFeedOutput>.Fail("获取社区内容失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下拉刷新社区Feed
|
||||
/// </summary>
|
||||
[HttpGet("refresh")]
|
||||
public async Task<BaseResponse<WxFeedOutput>> RefreshFeed()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<WxFeedOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.RefreshFeedAsync(userId.Value);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "刷新社区Feed业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<WxFeedOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "刷新社区Feed系统异常");
|
||||
return BaseResponse<WxFeedOutput>.Fail("刷新社区内容失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点赞
|
||||
/// </summary>
|
||||
[HttpPost("like")]
|
||||
public async Task<BaseResponse<WxLikeOutput>> Like([FromBody] WxLikeInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<WxLikeOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.LikeAsync(userId.Value, input);
|
||||
return Success(result, "点赞成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "点赞业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<WxLikeOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "点赞系统异常,参数:{Input}", input);
|
||||
return BaseResponse<WxLikeOutput>.Fail("点赞失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消点赞
|
||||
/// </summary>
|
||||
[HttpPost("unlike")]
|
||||
public async Task<BaseResponse<WxLikeOutput>> Unlike([FromBody] WxLikeInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<WxLikeOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.UnlikeAsync(userId.Value, input.MessageId);
|
||||
return Success(result, "已取消点赞");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "取消点赞业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<WxLikeOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "取消点赞系统异常,参数:{Input}", input);
|
||||
return BaseResponse<WxLikeOutput>.Fail("取消点赞失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
|
||||
/// <summary>
|
||||
/// 小程序勋章控制器
|
||||
/// </summary>
|
||||
public class WeChatMedalController(IMedalService medalService, ILogger<WeChatMedalController> logger) : WeChatBaseController
|
||||
public class MedalController(IMedalService medalService, ILogger<MedalController> logger) : WeChatBaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有勋章列表(含当前用户拥有状态)
|
||||
Reference in New Issue
Block a user