Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.WebApi/Controllers/WeChat/MallController.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

71 lines
2.4 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.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Dto.Mall;
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
/// <summary>
/// 小程序商城控制器
/// </summary>
public class MallController(IWxMallService mallService, ILogger<MallController> logger) : WeChatBaseController
{
/// <summary>
/// 获取商城商品列表
/// </summary>
/// <param name="type">商品类型筛选(可选): MakeUpCard, PetBg</param>
[HttpGet("products")]
public async Task<BaseResponse<List<WxProductOutput>>> GetProducts([FromQuery] string? type = null)
{
var userId = GetCurrentWxUserId();
if (userId == null) return Fail("未获取到用户信息") as dynamic;
var products = await mallService.GetProductsAsync(userId.Value, type);
return Success(products);
}
/// <summary>
/// 获取商品详情
/// </summary>
/// <param name="id">商品Id</param>
[HttpGet("product/{id}")]
public async Task<BaseResponse<WxProductOutput>> GetProductDetail(long id)
{
var userId = GetCurrentWxUserId();
if (userId == null) return Fail("未获取到用户信息") as dynamic;
var product = await mallService.GetProductDetailAsync(userId.Value, id);
if (product == null)
return BaseResponse<WxProductOutput>.Fail(ResultCode.DENY, "商品不存在或已下架");
return Success(product);
}
/// <summary>
/// 积分兑换商品
/// </summary>
[HttpPost("exchange")]
public async Task<BaseResponse<ExchangeOutput>> Exchange([FromBody] ExchangeInput input)
{
var userId = GetCurrentWxUserId();
if (userId == null) return Fail("未获取到用户信息") as dynamic;
var result = await mallService.ExchangeAsync(userId.Value, input);
return Success(result);
}
/// <summary>
/// 获取我的兑换记录
/// </summary>
/// <param name="limit">返回数量默认20</param>
[HttpGet("exchangeRecords")]
public async Task<BaseResponse<List<ExchangeRecordOutput>>> GetExchangeRecords([FromQuery] int limit = 20)
{
var userId = GetCurrentWxUserId();
if (userId == null) return Fail("未获取到用户信息") as dynamic;
var records = await mallService.GetExchangeRecordsAsync(userId.Value, limit);
return Success(records);
}
}