feat: 完成多模块功能迭代与优化
1. 新增宠物皮肤初始枚举值、下拉列表接口及相关DTO 2. 完善商品实体与DTO,新增虚拟商品标记和类型ID字段 3. 重构用户认证体系,支持多用户切换并重新生成JWT令牌 4. 新增签到配置管理全套功能,包括增删改查和状态管理 5. 优化模型验证过滤器和基础响应类的命名规范 6. 新增补签功能,完善签到服务逻辑 7. 拆分用户详情DTO,新增各子数据分页查询接口 8. 重构微信控制器的用户ID获取逻辑,统一使用激活用户ID 9. 修复背包服务中补签卡的扣减逻辑 10. 新增家长姓名修改接口和相关服务实现
This commit is contained in:
@ -0,0 +1,177 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.CheckIn;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 签到配置管理控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
||||
public class CheckInConfigController : BaseController
|
||||
{
|
||||
private readonly ICheckInConfigService _checkInConfigService;
|
||||
private readonly ILogger<CheckInConfigController> _logger;
|
||||
|
||||
public CheckInConfigController(ICheckInConfigService checkInConfigService, ILogger<CheckInConfigController> logger)
|
||||
{
|
||||
_checkInConfigService = checkInConfigService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建签到配置
|
||||
/// </summary>
|
||||
/// <param name="input">签到配置信息</param>
|
||||
/// <returns>创建的签到配置信息</returns>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<CheckInConfigOutput>> CreateAsync([FromBody] CheckInConfigInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _checkInConfigService.CreateAsync(input);
|
||||
return Success(result, "创建签到配置成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "创建签到配置业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<CheckInConfigOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "创建签到配置系统异常,参数:{Input}", input);
|
||||
return BaseResponse<CheckInConfigOutput>.Fail("创建签到配置失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新签到配置
|
||||
/// </summary>
|
||||
/// <param name="id">签到配置ID</param>
|
||||
/// <param name="input">签到配置信息</param>
|
||||
/// <returns>更新后的签到配置信息</returns>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<BaseResponse<CheckInConfigOutput>> UpdateAsync(long id, [FromBody] CheckInConfigInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _checkInConfigService.UpdateAsync(id, input);
|
||||
return Success(result, "更新签到配置成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "更新签到配置业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<CheckInConfigOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "更新签到配置系统异常,ID:{Id},参数:{Input}", id, input);
|
||||
return BaseResponse<CheckInConfigOutput>.Fail("更新签到配置失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除签到配置(软删除)
|
||||
/// </summary>
|
||||
/// <param name="id">签到配置ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _checkInConfigService.DeleteAsync(id);
|
||||
return Success(new object(), "删除签到配置成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "删除签到配置业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "删除签到配置系统异常,ID:{Id}", id);
|
||||
return BaseResponse<object>.Fail("删除签到配置失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取签到配置
|
||||
/// </summary>
|
||||
/// <param name="id">签到配置ID</param>
|
||||
/// <returns>签到配置信息</returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<BaseResponse<CheckInConfigOutput>> GetByIdAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _checkInConfigService.GetByIdAsync(id);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "获取签到配置业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<CheckInConfigOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取签到配置系统异常,ID:{Id}", id);
|
||||
return BaseResponse<CheckInConfigOutput>.Fail("获取签到配置信息失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询签到配置列表
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <returns>分页结果</returns>
|
||||
[HttpPost("list")]
|
||||
public async Task<BaseResponse<PageListModel<CheckInConfigOutput>>> GetListAsync([FromBody] CheckInConfigQueryInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _checkInConfigService.GetListAsync(input);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "查询签到配置列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<PageListModel<CheckInConfigOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "查询签到配置列表系统异常,参数:{Input}", input);
|
||||
return BaseResponse<PageListModel<CheckInConfigOutput>>.Fail("查询签到配置列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新签到配置启用/禁用状态
|
||||
/// </summary>
|
||||
/// <param name="id">签到配置ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = await _checkInConfigService.UpdateStatusAsync(id);
|
||||
return Success(res, "更新签到配置状态成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "更新签到配置状态业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<bool>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "更新签到配置状态系统异常,ID:{Id}", id);
|
||||
return BaseResponse<bool>.Fail("更新签到配置状态失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -562,4 +562,23 @@ public class PetManageController : BaseController
|
||||
return BaseResponse<List<SkinEvolutionStageOutput>>.Fail("获取分组皮肤图片失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有皮肤下拉列表
|
||||
/// </summary>
|
||||
/// <param name="types">皮肤类型列表(可选)</param>
|
||||
[HttpGet("skins/select")]
|
||||
public async Task<BaseResponse<List<SelectOptionDto>>> GetAllSkinsForSelectAsync([FromQuery] List<string>? types = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _petService.GetAllSkinsForSelectAsync(types);
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取皮肤下拉列表系统异常");
|
||||
return BaseResponse<List<SelectOptionDto>>.Fail("获取皮肤下拉列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ using QYZH.InteractiveMagazine.IService;
|
||||
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.CheckIn;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.Compensation;
|
||||
using QYZH.InteractiveMagazine.Models.Dto.Points;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||
@ -33,7 +35,7 @@ public class UsersController : BaseController
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户详情(包含积分记录、签到记录、补偿任务、期刊列表)
|
||||
/// 获取用户详情(仅基本信息)
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<BaseResponse<UserDetailOutput>> GetDetail(long id)
|
||||
@ -41,6 +43,42 @@ public class UsersController : BaseController
|
||||
return await _usersService.GetDetailAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询用户积分记录
|
||||
/// </summary>
|
||||
[HttpGet("{id}/pointsRecords")]
|
||||
public async Task<BaseResponse<PageListModel<PointsRecordOutput>>> GetUserPointsRecords(long id, [FromQuery] PointsRecordQueryInput input)
|
||||
{
|
||||
return await _usersService.GetUserPointsRecordsAsync(id, input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询用户签到记录
|
||||
/// </summary>
|
||||
[HttpGet("{id}/checkInRecords")]
|
||||
public async Task<BaseResponse<PageListModel<CheckInRecordOutput>>> GetUserCheckInRecords(long id, [FromQuery] PageQueryModel input)
|
||||
{
|
||||
return await _usersService.GetUserCheckInRecordsAsync(id, input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询用户补偿任务
|
||||
/// </summary>
|
||||
[HttpGet("{id}/compensationTasks")]
|
||||
public async Task<BaseResponse<PageListModel<CompensationTaskOutput>>> GetUserCompensationTasks(long id, [FromQuery] CompensationTaskQueryInput input)
|
||||
{
|
||||
return await _usersService.GetUserCompensationTasksAsync(id, input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询用户期刊列表
|
||||
/// </summary>
|
||||
[HttpGet("{id}/journals")]
|
||||
public async Task<BaseResponse<PageListModel<UserJournalItemOutput>>> GetUserJournals(long id, [FromQuery] UserJournalQueryInput input)
|
||||
{
|
||||
return await _usersService.GetUserJournalsAsync(id, input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户状态
|
||||
/// </summary>
|
||||
|
||||
@ -17,10 +17,10 @@ public class BagController(IWxMallService mallService, ILogger<BagController> lo
|
||||
[HttpGet("items")]
|
||||
public async Task<BaseResponse<List<UserBagOutput>>> GetBagItems([FromQuery] string? itemType = null)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
var items = await mallService.GetBagItemsAsync(userId.Value, itemType);
|
||||
var items = await mallService.GetBagItemsAsync(userId, itemType);
|
||||
return Success(items);
|
||||
}
|
||||
|
||||
@ -30,10 +30,10 @@ public class BagController(IWxMallService mallService, ILogger<BagController> lo
|
||||
[HttpPost("useItem")]
|
||||
public async Task<BaseResponse<UseItemOutput>> UseItem([FromBody] UseItemInput input)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
var result = await mallService.UseItemAsync(userId.Value, input);
|
||||
var result = await mallService.UseItemAsync(userId, input);
|
||||
return Success(result);
|
||||
}
|
||||
|
||||
@ -43,10 +43,10 @@ public class BagController(IWxMallService mallService, ILogger<BagController> lo
|
||||
[HttpPost("equipSkin")]
|
||||
public async Task<BaseResponse<object>> EquipSkin([FromBody] EquipSkinInput input)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
await mallService.EquipSkinAsync(userId.Value, input);
|
||||
await mallService.EquipSkinAsync(userId, input);
|
||||
return Success<object>(null!, input.SkinId == 0 ? "已恢复默认皮肤" : "换肤成功");
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,13 +29,13 @@ public class CheckInController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<CheckInOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _checkInService.CheckInAsync(userId.Value);
|
||||
var result = await _checkInService.CheckInAsync(userId);
|
||||
return Success(result, "签到成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -59,13 +59,13 @@ public class CheckInController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<CheckInInfoOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _checkInService.GetCheckInInfoAsync(userId.Value);
|
||||
var result = await _checkInService.GetCheckInInfoAsync(userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -79,4 +79,66 @@ public class CheckInController : WeChatBaseController
|
||||
return BaseResponse<CheckInInfoOutput>.Fail("获取签到信息失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 补签(消耗补签卡,补签历史漏签日期)
|
||||
/// </summary>
|
||||
/// <param name="input">补签输入(目标日期)</param>
|
||||
/// <returns>补签结果(含奖励详情和余额)</returns>
|
||||
[HttpPost("makeUp")]
|
||||
public async Task<BaseResponse<CheckInOutput>> MakeUpCheckInAsync([FromBody] MakeUpCheckInInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<CheckInOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _checkInService.MakeUpCheckInAsync(userId, input.TargetDate);
|
||||
return Success(result, "补签成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "补签业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<CheckInOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "补签系统异常");
|
||||
return BaseResponse<CheckInOutput>.Fail("补签失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可补签的日期列表(历史漏签日期)
|
||||
/// </summary>
|
||||
/// <param name="days">往前查看天数(默认30天)</param>
|
||||
/// <returns>漏签日期列表</returns>
|
||||
[HttpGet("missedDates")]
|
||||
public async Task<BaseResponse<List<DateTime>>> GetMissedDatesAsync([FromQuery] int days = 30)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<List<DateTime>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _checkInService.GetMissedDatesAsync(userId, days);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "获取可补签日期业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<List<DateTime>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取可补签日期系统异常");
|
||||
return BaseResponse<List<DateTime>>.Fail("获取可补签日期失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,13 +19,13 @@ public class CommunityController(IWeChatCommunityService communityService, ILogg
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<WxFeedOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.GetFeedAsync(userId.Value, cursor);
|
||||
var result = await communityService.GetFeedAsync(userId, cursor);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -48,13 +48,13 @@ public class CommunityController(IWeChatCommunityService communityService, ILogg
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<WxFeedOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.RefreshFeedAsync(userId.Value);
|
||||
var result = await communityService.RefreshFeedAsync(userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -77,13 +77,13 @@ public class CommunityController(IWeChatCommunityService communityService, ILogg
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<WxLikeOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.LikeAsync(userId.Value, input);
|
||||
var result = await communityService.LikeAsync(userId, input);
|
||||
return Success(result, "点赞成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -106,13 +106,13 @@ public class CommunityController(IWeChatCommunityService communityService, ILogg
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<WxLikeOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await communityService.UnlikeAsync(userId.Value, input.MessageId);
|
||||
var result = await communityService.UnlikeAsync(userId, input.MessageId);
|
||||
return Success(result, "已取消点赞");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
|
||||
@ -29,13 +29,13 @@ public class JournalController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<BindJournalOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _userJournalService.BindJournalAsync(userId.Value, input);
|
||||
var result = await _userJournalService.BindJournalAsync(userId, input);
|
||||
return Success(result, "绑定期刊成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -60,13 +60,13 @@ public class JournalController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<PageListModel<BindJournalOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _userJournalService.GetUserJournalsAsync(userId.Value, input);
|
||||
var result = await _userJournalService.GetUserJournalsAsync(userId, input);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
|
||||
@ -17,10 +17,10 @@ public class MallController(IWxMallService mallService, ILogger<MallController>
|
||||
[HttpGet("products")]
|
||||
public async Task<BaseResponse<List<WxProductOutput>>> GetProducts([FromQuery] string? type = null)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
var products = await mallService.GetProductsAsync(userId.Value, type);
|
||||
var products = await mallService.GetProductsAsync(userId, type);
|
||||
return Success(products);
|
||||
}
|
||||
|
||||
@ -31,10 +31,10 @@ public class MallController(IWxMallService mallService, ILogger<MallController>
|
||||
[HttpGet("product/{id}")]
|
||||
public async Task<BaseResponse<WxProductOutput>> GetProductDetail(long id)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
var product = await mallService.GetProductDetailAsync(userId.Value, id);
|
||||
var product = await mallService.GetProductDetailAsync(userId, id);
|
||||
if (product == null)
|
||||
return BaseResponse<WxProductOutput>.Fail(ResultCode.DENY, "商品不存在或已下架");
|
||||
|
||||
@ -47,10 +47,10 @@ public class MallController(IWxMallService mallService, ILogger<MallController>
|
||||
[HttpPost("exchange")]
|
||||
public async Task<BaseResponse<ExchangeOutput>> Exchange([FromBody] ExchangeInput input)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
var result = await mallService.ExchangeAsync(userId.Value, input);
|
||||
var result = await mallService.ExchangeAsync(userId, input);
|
||||
return Success(result);
|
||||
}
|
||||
|
||||
@ -61,10 +61,10 @@ public class MallController(IWxMallService mallService, ILogger<MallController>
|
||||
[HttpGet("exchangeRecords")]
|
||||
public async Task<BaseResponse<List<ExchangeRecordOutput>>> GetExchangeRecords([FromQuery] int limit = 20)
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null) return Fail("未获取到用户信息") as dynamic;
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0) return Fail("未获取到用户信息") as dynamic;
|
||||
|
||||
var records = await mallService.GetExchangeRecordsAsync(userId.Value, limit);
|
||||
var records = await mallService.GetExchangeRecordsAsync(userId, limit);
|
||||
return Success(records);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,13 +18,13 @@ public class MedalController(IMedalService medalService, ILogger<MedalController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await medalService.GetAllMedalsAsync(userId.Value);
|
||||
var result = await medalService.GetAllMedalsAsync(userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -47,13 +47,13 @@ public class MedalController(IMedalService medalService, ILogger<MedalController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await medalService.GetUserMedalsAsync(userId.Value);
|
||||
var result = await medalService.GetUserMedalsAsync(userId);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -76,13 +76,13 @@ public class MedalController(IMedalService medalService, ILogger<MedalController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<object>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
await medalService.ActivateMedalAsync(userId.Value, input);
|
||||
await medalService.ActivateMedalAsync(userId, input);
|
||||
return Success<object>(null!, "勋章激活成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
|
||||
@ -28,13 +28,13 @@ public class PetController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<PetOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var pet = await _petService.GetPetByUserIdAsync(userId.Value);
|
||||
var pet = await _petService.GetPetByUserIdAsync(userId);
|
||||
if (pet == null)
|
||||
{
|
||||
return BaseResponse<PetOutput>.Fail("未找到宠物信息");
|
||||
@ -62,13 +62,13 @@ public class PetController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<FeedPetOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _petService.FeedPetAsync(userId.Value, input);
|
||||
var result = await _petService.FeedPetAsync(userId, input);
|
||||
return Success(result, "喂养成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -91,13 +91,13 @@ public class PetController : WeChatBaseController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentWxUserId();
|
||||
if (userId == null)
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == 0)
|
||||
{
|
||||
return BaseResponse<PageListModel<FeedingRecordOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await _petService.GetFeedingRecordsAsync(userId.Value, petId, pageQuery);
|
||||
var result = await _petService.GetFeedingRecordsAsync(userId, petId, pageQuery);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
|
||||
@ -86,7 +86,8 @@ public class WeChatAuthController : WeChatBaseController
|
||||
if (wxUserId == null)
|
||||
return BaseResponse<WeChatSwitchUserOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
|
||||
var result = await _weChatAuthService.SwitchUserAsync(wxUserId.Value, input);
|
||||
var currentUserId = GetCurrentUserId();
|
||||
var result = await _weChatAuthService.SwitchUserAsync(wxUserId.Value, currentUserId, input);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
@ -154,4 +155,31 @@ public class WeChatAuthController : WeChatBaseController
|
||||
return BaseResponse<WxUserOutput>.Fail("新增用户失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改家长名字(WxUser.Name)
|
||||
/// </summary>
|
||||
[HttpPost("updateName")]
|
||||
public async Task<BaseResponse<WxUserInfoOutput>> UpdateWxUserNameAsync([FromBody] UpdateWxUserNameInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var wxUserId = GetCurrentWxUserId();
|
||||
if (wxUserId == null)
|
||||
return BaseResponse<WxUserInfoOutput>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
|
||||
var result = await _weChatAuthService.UpdateWxUserNameAsync(wxUserId.Value, input);
|
||||
return Success(result, "修改成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "修改家长名字业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<WxUserInfoOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "修改家长名字系统异常");
|
||||
return BaseResponse<WxUserInfoOutput>.Fail("修改家长名字失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Auth;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
using System.Security.Claims;
|
||||
@ -16,16 +17,30 @@ namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
|
||||
public abstract class WeChatBaseController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当前微信用户ID(WxUser.Id,来自 JWT)
|
||||
/// 获取当前激活用户ID(Users.Id,来自 JWT NameIdentifier)
|
||||
/// </summary>
|
||||
/// <returns>WxUser ID</returns>
|
||||
protected long? GetCurrentWxUserId()
|
||||
/// <returns>User ID(无激活用户时为 0)</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 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前微信用户ID(WxUser.Id,来自 JWT WxUserId claim)
|
||||
/// </summary>
|
||||
/// <returns>WxUser ID</returns>
|
||||
protected long? GetCurrentWxUserId()
|
||||
{
|
||||
var wxUserIdClaim = User.Claims.FirstOrDefault(c => c.Type == JwtHelper.WxUserIdClaimType);
|
||||
if (wxUserIdClaim != null && long.TryParse(wxUserIdClaim.Value, out var wxUserId))
|
||||
{
|
||||
return wxUserId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user