feat: 完成多模块功能迭代与优化
1. 新增宠物皮肤初始枚举值、下拉列表接口及相关DTO 2. 完善商品实体与DTO,新增虚拟商品标记和类型ID字段 3. 重构用户认证体系,支持多用户切换并重新生成JWT令牌 4. 新增签到配置管理全套功能,包括增删改查和状态管理 5. 优化模型验证过滤器和基础响应类的命名规范 6. 新增补签功能,完善签到服务逻辑 7. 拆分用户详情DTO,新增各子数据分页查询接口 8. 重构微信控制器的用户ID获取逻辑,统一使用激活用户ID 9. 修复背包服务中补签卡的扣减逻辑 10. 新增家长姓名修改接口和相关服务实现
This commit is contained in:
@ -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