本次提交完成了多个核心业务模块的开发与优化: 1. 宠物模块:新增宠物实体、服务接口与实现,支持创建默认宠物、激活、喂养、进化以及喂养记录查询 2. 签到模块:新增签到实体、服务接口、控制器以及相关DTO,支持用户签到和签到信息查询,新增成长值奖励字段 3. 期刊绑定模块:新增用户期刊关联实体、服务接口与控制器,支持扫码绑定期刊、解绑和查询绑定列表 4. 补偿任务模块:新增补偿任务实体、服务接口与实现,用于处理业务失败后的异步重试补偿 5. 优化微信登录流程:拆分登录与快捷登录接口,支持手机号获取,新增首次登录自动创建默认宠物逻辑 6. 调整基础路由与实体状态:修改微信控制器路由前缀,更新宠物状态枚举与默认值
84 lines
3.1 KiB
C#
84 lines
3.1 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 JournalController : WeChatBaseController
|
||
{
|
||
private readonly IUserJournalService _userJournalService;
|
||
private readonly ILogger<JournalController> _logger;
|
||
|
||
public JournalController(IUserJournalService userJournalService, ILogger<JournalController> logger)
|
||
{
|
||
_userJournalService = userJournalService;
|
||
_logger = logger;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户扫码绑定期刊
|
||
/// </summary>
|
||
/// <param name="input">绑定输入(JournalId、JournalInstanceId 从扫码内容解析,Type 默认 Subscribe)</param>
|
||
/// <returns>绑定结果</returns>
|
||
[HttpPost("bind")]
|
||
public async Task<BaseResponse<BindJournalOutput>> BindAsync([FromBody] BindJournalInput input)
|
||
{
|
||
try
|
||
{
|
||
var userId = GetCurrentUserId();
|
||
if (userId == null)
|
||
{
|
||
return BaseResponse<BindJournalOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||
}
|
||
|
||
var result = await _userJournalService.BindJournalAsync(userId.Value, input);
|
||
return Success(result, "绑定期刊成功");
|
||
}
|
||
catch (BusinessException ex)
|
||
{
|
||
_logger.LogWarning(ex, "绑定期刊业务异常: {Message}", ex.Message);
|
||
return BaseResponse<BindJournalOutput>.Fail(ex.Message);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "绑定期刊系统异常,参数:{Input}", input);
|
||
return BaseResponse<BindJournalOutput>.Fail("绑定期刊失败,请稍后重试");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前用户的期刊绑定列表
|
||
/// </summary>
|
||
/// <param name="input">查询条件(期刊Id、实例Id、关联类型)</param>
|
||
/// <returns>分页结果</returns>
|
||
[HttpPost("list")]
|
||
public async Task<BaseResponse<PageListModel<BindJournalOutput>>> GetListAsync([FromBody] UserJournalQueryInput input)
|
||
{
|
||
try
|
||
{
|
||
var userId = GetCurrentUserId();
|
||
if (userId == null)
|
||
{
|
||
return BaseResponse<PageListModel<BindJournalOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||
}
|
||
|
||
var result = await _userJournalService.GetUserJournalsAsync(userId.Value, input);
|
||
return Success(result);
|
||
}
|
||
catch (BusinessException ex)
|
||
{
|
||
_logger.LogWarning(ex, "查询期刊绑定列表业务异常: {Message}", ex.Message);
|
||
return BaseResponse<PageListModel<BindJournalOutput>>.Fail(ex.Message);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "查询期刊绑定列表系统异常");
|
||
return BaseResponse<PageListModel<BindJournalOutput>>.Fail("查询期刊绑定列表失败,请稍后重试");
|
||
}
|
||
}
|
||
}
|