Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.WebApi/Controllers/WeChat/WeChatBaseController.cs
glz 028e3dfb34 refactor: 重构用户与勋章体系,统一状态管理与数据结构
1.  新增通用默认状态枚举 DefaultStatusEnum,替换原有分散的状态枚举
2.  重构用户体系:拆分 WxUser 独立表存储微信身份,Users 表改为角色子用户表并关联 WxUser
3.  重构勋章模块:新增系统/期刊勋章类型,调整 JournalId 为可空,新增勋章状态字段
4.  重构微信认证流程:基于 WxUser 生成 Token,支持多子用户管理
5.  清理冗余枚举文件,重构多处业务逻辑适配新的数据结构
6.  修复用户手机号关联逻辑,迁移手机号字段至 WxUser 表
2026-06-10 13:47:13 +08:00

64 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Enum;
using System.Security.Claims;
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
/// <summary>
/// 小程序基础控制器
/// </summary>
[Authorize]
[ApiController]
[Route("wechat/api/[controller]")]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Wechat))]
public abstract class WeChatBaseController : ControllerBase
{
/// <summary>
/// 获取当前微信用户IDWxUser.Id来自 JWT
/// </summary>
/// <returns>WxUser ID</returns>
protected long? GetCurrentWxUserId()
{
var userIdClaim = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);
if (userIdClaim != null && long.TryParse(userIdClaim.Value, out var userId))
{
return userId;
}
return null;
}
/// <summary>
/// 获取当前用户名
/// </summary>
/// <returns>用户名</returns>
protected string? GetCurrentUserName()
{
return User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
}
/// <summary>
/// 成功响应
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="data">数据</param>
/// <param name="message">提示信息</param>
/// <returns>统一响应对象</returns>
protected BaseResponse<T> Success<T>(T data, string message = "操作成功")
{
return BaseResponse<T>.Success(data, message);
}
/// <summary>
/// 失败响应
/// </summary>
/// <param name="message">提示信息</param>
/// <param name="code">状态码</param>
/// <returns>统一响应对象</returns>
protected BaseResponse<object> Fail(string message, int code = 500)
{
return BaseResponse<object>.Fail(ResultCode.GLOBAL_ERROR, message);
}
}