1. 新增通用默认状态枚举 DefaultStatusEnum,替换原有分散的状态枚举 2. 重构用户体系:拆分 WxUser 独立表存储微信身份,Users 表改为角色子用户表并关联 WxUser 3. 重构勋章模块:新增系统/期刊勋章类型,调整 JournalId 为可空,新增勋章状态字段 4. 重构微信认证流程:基于 WxUser 生成 Token,支持多子用户管理 5. 清理冗余枚举文件,重构多处业务逻辑适配新的数据结构 6. 修复用户手机号关联逻辑,迁移手机号字段至 WxUser 表
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 = GetCurrentWxUserId();
|
||
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 = GetCurrentWxUserId();
|
||
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("查询期刊绑定列表失败,请稍后重试");
|
||
}
|
||
}
|
||
}
|