refactor: 重构用户与商品模块,统一业务模型与服务

1.  新增用户状态枚举UserStatusEnum,统一用户状态定义
2.  重构用户体系:合并WxUser与User实体为Users实体,统一用户管理
3.  新增微信小程序认证相关服务与控制器,实现一键登录功能
4.  新增商品管理完整服务与控制器,修复商品表字段映射问题
5.  删除冗余的WxUser相关服务与控制器代码
6.  新增Newtonsoft.Json依赖用于微信接口响应解析
7.  清理无用的文件夹引用配置
This commit is contained in:
glz
2026-06-03 16:09:56 +08:00
parent 0a32754740
commit 32989e1fa0
22 changed files with 1200 additions and 491 deletions

View File

@ -0,0 +1,49 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.IService.Dto;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
/// <summary>
/// 微信小程序认证控制器
/// </summary>
public class WeChatAuthController : WeChatBaseController
{
private readonly IWeChatAuthService _weChatAuthService;
private readonly ILogger<WeChatAuthController> _logger;
public WeChatAuthController(IWeChatAuthService weChatAuthService, ILogger<WeChatAuthController> logger)
{
_weChatAuthService = weChatAuthService;
_logger = logger;
}
/// <summary>
/// 微信小程序一键登录
/// </summary>
/// <param name="input">登录输入(含微信 code</param>
/// <returns>登录结果(含 Token 和用户信息)</returns>
[AllowAnonymous]
[HttpPost("login")]
public async Task<BaseResponse<WeChatLoginOutput>> LoginAsync([FromBody] WeChatLoginInput input)
{
try
{
var result = await _weChatAuthService.LoginAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "微信登录业务异常: {Message}", ex.Message);
return BaseResponse<WeChatLoginOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "微信登录系统异常");
return BaseResponse<WeChatLoginOutput>.Fail("微信登录失败,请稍后重试");
}
}
}

View File

@ -0,0 +1,63 @@
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("api/[controller]")]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Wechat))]
public abstract class WeChatBaseController : ControllerBase
{
/// <summary>
/// 获取当前用户ID
/// </summary>
/// <returns>用户ID</returns>
protected long? GetCurrentUserId()
{
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);
}
}