2026-06-04 18:03:34 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using QYZH.InteractiveMagazine.IService;
|
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto;
|
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto.Mall;
|
|
|
|
|
|
|
2026-07-06 14:21:21 +08:00
|
|
|
|
namespace QYZH.InteractiveMagazine.WeChatApi.Controllers;
|
2026-06-04 18:03:34 +08:00
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var userId = GetCurrentUserId();
|
|
|
|
|
|
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
2026-06-04 18:03:34 +08:00
|
|
|
|
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var products = await mallService.GetProductsAsync(userId, type);
|
2026-06-04 18:03:34 +08:00
|
|
|
|
return Success(products);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取商品详情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">商品Id</param>
|
|
|
|
|
|
[HttpGet("product/{id}")]
|
|
|
|
|
|
public async Task<BaseResponse<WxProductOutput>> GetProductDetail(long id)
|
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var userId = GetCurrentUserId();
|
|
|
|
|
|
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
2026-06-04 18:03:34 +08:00
|
|
|
|
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var product = await mallService.GetProductDetailAsync(userId, id);
|
2026-06-04 18:03:34 +08:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var userId = GetCurrentUserId();
|
|
|
|
|
|
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
2026-06-04 18:03:34 +08:00
|
|
|
|
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var result = await mallService.ExchangeAsync(userId, input);
|
2026-06-04 18:03:34 +08:00
|
|
|
|
return Success(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取我的兑换记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="limit">返回数量(默认20)</param>
|
|
|
|
|
|
[HttpGet("exchangeRecords")]
|
|
|
|
|
|
public async Task<BaseResponse<List<ExchangeRecordOutput>>> GetExchangeRecords([FromQuery] int limit = 20)
|
|
|
|
|
|
{
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var userId = GetCurrentUserId();
|
|
|
|
|
|
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
2026-06-04 18:03:34 +08:00
|
|
|
|
|
2026-06-10 17:53:38 +08:00
|
|
|
|
var records = await mallService.GetExchangeRecordsAsync(userId, limit);
|
2026-06-04 18:03:34 +08:00
|
|
|
|
return Success(records);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|