diff --git a/QYZH.InteractiveMagazine.IService/IAdminUserService.cs b/QYZH.InteractiveMagazine.IService/IAdminUserService.cs index 89ee70d..f49e4ed 100644 --- a/QYZH.InteractiveMagazine.IService/IAdminUserService.cs +++ b/QYZH.InteractiveMagazine.IService/IAdminUserService.cs @@ -43,4 +43,11 @@ public interface IAdminUserService : IBaseService /// 查询条件 /// 分页结果 Task> GetListAsync(AdminUserQueryInput input); + + /// + /// 切换管理员状态(激活/冻结) + /// + /// 管理员ID + /// 目标状态:1=激活,0=冻结 + Task ToggleStatusAsync(long id); } diff --git a/QYZH.InteractiveMagazine.IService/IMedalService.cs b/QYZH.InteractiveMagazine.IService/IMedalService.cs index 8bbe9f5..94d3961 100644 --- a/QYZH.InteractiveMagazine.IService/IMedalService.cs +++ b/QYZH.InteractiveMagazine.IService/IMedalService.cs @@ -48,7 +48,7 @@ public interface IMedalService : IBaseService /// /// 勋章ID /// 状态: 0=禁用, 1=启用 - Task UpdateStatusAsync(long id, int status); + Task UpdateStatusAsync(long id); /// /// 获取勋章的规则列表 @@ -77,4 +77,15 @@ public interface IMedalService : IBaseService /// 用户ID /// 激活输入 Task ActivateMedalAsync(long userId, WxMedalActivateInput input); + + /// + /// 获取规则配置中可用的目标表列表 + /// + Task> GetAvailableTablesAsync(); + + /// + /// 获取指定表的可用字段列表 + /// + /// 表名 + Task> GetTableFieldsAsync(string tableName); } diff --git a/QYZH.InteractiveMagazine.IService/IPetService.cs b/QYZH.InteractiveMagazine.IService/IPetService.cs index a7e192f..c982f4c 100644 --- a/QYZH.InteractiveMagazine.IService/IPetService.cs +++ b/QYZH.InteractiveMagazine.IService/IPetService.cs @@ -75,7 +75,7 @@ public interface IPetService : IBaseService /// /// 更新模板状态(启用/禁用) /// - Task UpdateTemplateStatusAsync(long id, int status); + Task UpdateTemplateStatusAsync(long id); // ==================== 后台管理:进化链 ==================== diff --git a/QYZH.InteractiveMagazine.IService/IProductService.cs b/QYZH.InteractiveMagazine.IService/IProductService.cs index 142059b..05cba12 100644 --- a/QYZH.InteractiveMagazine.IService/IProductService.cs +++ b/QYZH.InteractiveMagazine.IService/IProductService.cs @@ -42,4 +42,10 @@ public interface IProductService : IBaseService /// 查询条件 /// 分页结果 Task> GetListAsync(ProductQueryInput input); + + /// + /// 更新商品上架/下架状态(取反) + /// + /// 商品ID + Task UpdateSaleStatusAsync(long id); } diff --git a/QYZH.InteractiveMagazine.IService/IUsersService.cs b/QYZH.InteractiveMagazine.IService/IUsersService.cs index 483587e..6a1c47b 100644 --- a/QYZH.InteractiveMagazine.IService/IUsersService.cs +++ b/QYZH.InteractiveMagazine.IService/IUsersService.cs @@ -19,7 +19,7 @@ public interface IUsersService : IBaseService /// /// 更新用户状态 /// - Task UpdateStatusAsync(long id, UpdateUserStatusInput input); + Task UpdateStatusAsync(long id); /// /// 手动增加用户积分 diff --git a/QYZH.InteractiveMagazine.Models/Dto/Mall/ProductDto.cs b/QYZH.InteractiveMagazine.Models/Dto/Mall/ProductDto.cs index d2c5588..989260d 100644 --- a/QYZH.InteractiveMagazine.Models/Dto/Mall/ProductDto.cs +++ b/QYZH.InteractiveMagazine.Models/Dto/Mall/ProductDto.cs @@ -36,7 +36,7 @@ public class ProductInput /// /// 售卖状态: OnSale, OffSale /// - public string SaleStatus { get; set; } = "OnSale"; + public ProductStatusEnum Status { get; set; } = ProductStatusEnum.OnSale; /// /// 扩展数据 @@ -90,9 +90,9 @@ public class ProductOutput public string Type { get; set; } = string.Empty; /// - /// 售卖状态 + /// 状态 /// - public string SaleStatus { get; set; } = string.Empty; + public string Status { get; set; } = string.Empty; /// /// 扩展数据 @@ -146,9 +146,9 @@ public class ProductQueryInput : PageQueryModel public string? Type { get; set; } /// - /// 售卖状态: OnSale, OffSale + /// 售卖状态 /// - public string? SaleStatus { get; set; } + public ProductStatusEnum? Status { get; set; } /// /// 是否上架 diff --git a/QYZH.InteractiveMagazine.Models/Dto/Medal/MedalDto.cs b/QYZH.InteractiveMagazine.Models/Dto/Medal/MedalDto.cs index ca1fd77..7be7b72 100644 --- a/QYZH.InteractiveMagazine.Models/Dto/Medal/MedalDto.cs +++ b/QYZH.InteractiveMagazine.Models/Dto/Medal/MedalDto.cs @@ -364,3 +364,35 @@ public class WxMedalActivateInput /// public long MedalId { get; set; } } + +/// +/// 勋章规则目标表下拉输出 +/// +public class MedalRuleTableOptionOutput +{ + /// + /// 表名 + /// + public string TableName { get; set; } = string.Empty; + + /// + /// 显示名称 + /// + public string DisplayName { get; set; } = string.Empty; +} + +/// +/// 勋章规则字段下拉输出 +/// +public class MedalRuleFieldOptionOutput +{ + /// + /// 字段名 + /// + public string FieldName { get; set; } = string.Empty; + + /// + /// 显示名称 + /// + public string DisplayName { get; set; } = string.Empty; +} diff --git a/QYZH.InteractiveMagazine.Models/Entity/Product.cs b/QYZH.InteractiveMagazine.Models/Entity/Product.cs index 4b8f912..6d97640 100644 --- a/QYZH.InteractiveMagazine.Models/Entity/Product.cs +++ b/QYZH.InteractiveMagazine.Models/Entity/Product.cs @@ -49,14 +49,6 @@ namespace QYZH.InteractiveMagazine.Models.Entity /// public ProductTypeEnum Type {get;set;} - /// - /// Desc:售卖状态: OnSale, OffSale - /// Default:OnSale - /// Nullable:False - /// - [SugarColumn(ColumnName = "SaleStatus")] - public string SaleStatus {get;set;} - /// /// Desc:扩展数据 /// Default: diff --git a/QYZH.InteractiveMagazine.Models/Enum/ProductStatusEnum.cs b/QYZH.InteractiveMagazine.Models/Enum/ProductStatusEnum.cs new file mode 100644 index 0000000..23ba2a6 --- /dev/null +++ b/QYZH.InteractiveMagazine.Models/Enum/ProductStatusEnum.cs @@ -0,0 +1,21 @@ +using System.ComponentModel; + +namespace QYZH.InteractiveMagazine.Models.Enum; + +/// +/// 商品上架/下架状态枚举 +/// +public enum ProductStatusEnum +{ + /// + /// 上架 + /// + [Description("上架")] + OnSale = 1, + + /// + /// 下架 + /// + [Description("下架")] + OffSale = 0 +} diff --git a/QYZH.InteractiveMagazine.Models/Enum/ProductTypeEnum.cs b/QYZH.InteractiveMagazine.Models/Enum/ProductTypeEnum.cs index d62551e..2605acf 100644 --- a/QYZH.InteractiveMagazine.Models/Enum/ProductTypeEnum.cs +++ b/QYZH.InteractiveMagazine.Models/Enum/ProductTypeEnum.cs @@ -15,6 +15,6 @@ public enum ProductTypeEnum /// /// 宠物背景 /// - [Description("宠物背景")] - PetBg = 2 + [Description("宠物皮肤")] + PetSkin = 2 } diff --git a/QYZH.InteractiveMagazine.Models/Settings/MedalRuleConfigSettings.cs b/QYZH.InteractiveMagazine.Models/Settings/MedalRuleConfigSettings.cs new file mode 100644 index 0000000..91a1838 --- /dev/null +++ b/QYZH.InteractiveMagazine.Models/Settings/MedalRuleConfigSettings.cs @@ -0,0 +1,49 @@ +namespace QYZH.InteractiveMagazine.Models.Settings; + +/// +/// 勋章规则配置(可配置的目标表和字段) +/// +public class MedalRuleConfigSettings +{ + /// + /// 可用的目标表列表 + /// + public List Tables { get; set; } = new(); +} + +/// +/// 勋章规则目标表配置 +/// +public class MedalRuleTableConfig +{ + /// + /// 表名 + /// + public string TableName { get; set; } = string.Empty; + + /// + /// 显示名称 + /// + public string DisplayName { get; set; } = string.Empty; + + /// + /// 可用字段列表 + /// + public List Fields { get; set; } = new(); +} + +/// +/// 勋章规则字段配置 +/// +public class MedalRuleFieldConfig +{ + /// + /// 字段名 + /// + public string FieldName { get; set; } = string.Empty; + + /// + /// 显示名称 + /// + public string DisplayName { get; set; } = string.Empty; +} diff --git a/QYZH.InteractiveMagazine.Service/AdminUserService.cs b/QYZH.InteractiveMagazine.Service/AdminUserService.cs index 71a260f..f7f7e2e 100644 --- a/QYZH.InteractiveMagazine.Service/AdminUserService.cs +++ b/QYZH.InteractiveMagazine.Service/AdminUserService.cs @@ -203,4 +203,32 @@ public class AdminUserService(BaseRepository adminUserRepository, ILo .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber); return new PageListModel(pageResult, input.PageIndex, input.PageSize, totalNumber); } + + /// + /// 切换管理员状态(激活/冻结) + /// + public async Task ToggleStatusAsync(long id) + { + logger.LogInformation("正在切换管理员状态,ID: {Id}", id); + + var adminUser = await adminUserRepository.GetByIdAsync(id); + if (adminUser == null) + { + logger.LogWarning("未找到要更新状态的管理员,ID: {Id}", id); + throw new BusinessException("管理员不存在", 404); + } + + adminUser.Status = adminUser.Status==(int)AdminUserStatusEnum.Active?(int)AdminUserStatusEnum.Inactive:(int)AdminUserStatusEnum.Active; + adminUser.UpdatedBy = "System"; + adminUser.UpdatedAt = DateTime.Now; + + var result = await adminUserRepository.UpdateAsync(adminUser); + if (!result) + { + logger.LogError("管理员状态更新失败,ID: {Id}", id); + throw new BusinessException("更新管理员状态失败", 500); + } + + logger.LogInformation("管理员状态更新成功,ID: {Id}", id); + } } diff --git a/QYZH.InteractiveMagazine.Service/MedalService.cs b/QYZH.InteractiveMagazine.Service/MedalService.cs index 8d149f4..7e5fda0 100644 --- a/QYZH.InteractiveMagazine.Service/MedalService.cs +++ b/QYZH.InteractiveMagazine.Service/MedalService.cs @@ -1,10 +1,12 @@ using System.Text.Json; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using QYZH.InteractiveMagazine.IService; using QYZH.InteractiveMagazine.Models.Common; using QYZH.InteractiveMagazine.Models.Dto; using QYZH.InteractiveMagazine.Models.Entity; using QYZH.InteractiveMagazine.Models.Enum; +using QYZH.InteractiveMagazine.Models.Settings; using QYZH.InteractiveMagazine.Repository; using SqlSugar; @@ -13,7 +15,7 @@ namespace QYZH.InteractiveMagazine.Service; /// /// 勋章服务实现 /// -public class MedalService(BaseRepository medalRepository, ILogger logger) : BaseRepository, IMedalService +public class MedalService(BaseRepository medalRepository, IOptions medalRuleConfig, ILogger logger) : BaseRepository, IMedalService { /// @@ -257,15 +259,8 @@ public class MedalService(BaseRepository medalRepository, ILogger /// 更新勋章启用/禁用状态 /// - public async Task UpdateStatusAsync(long id, int status) + public async Task UpdateStatusAsync(long id) { - logger.LogInformation("正在更新勋章状态,ID: {Id}, Status: {Status}", id, status); - - if (status != 0 && status != 1) - { - throw new BusinessException("状态值无效,只能为0(禁用)或1(启用)", 400); - } - var medal = await medalRepository.GetByIdAsync(id); if (medal == null) { @@ -273,7 +268,7 @@ public class MedalService(BaseRepository medalRepository, ILogger medalRepository, ILogger @@ -423,6 +419,40 @@ public class MedalService(BaseRepository medalRepository, ILogger + /// 获取规则配置中可用的目标表列表 + /// + public Task> GetAvailableTablesAsync() + { + var tables = medalRuleConfig.Value.Tables?.Select(t => new MedalRuleTableOptionOutput + { + TableName = t.TableName, + DisplayName = t.DisplayName + }).ToList() ?? new List(); + + return Task.FromResult(tables); + } + + /// + /// 获取指定表的可用字段列表 + /// + public Task> GetTableFieldsAsync(string tableName) + { + var table = medalRuleConfig.Value.Tables?.FirstOrDefault(t => t.TableName == tableName); + if (table == null) + { + return Task.FromResult(new List()); + } + + var fields = table.Fields.Select(f => new MedalRuleFieldOptionOutput + { + FieldName = f.FieldName, + DisplayName = f.DisplayName + }).ToList(); + + return Task.FromResult(fields); + } + #region 私有辅助方法 /// diff --git a/QYZH.InteractiveMagazine.Service/PetService.cs b/QYZH.InteractiveMagazine.Service/PetService.cs index 628df74..8ca3e22 100644 --- a/QYZH.InteractiveMagazine.Service/PetService.cs +++ b/QYZH.InteractiveMagazine.Service/PetService.cs @@ -484,18 +484,20 @@ public class PetService( /// /// 更新模板状态(启用/禁用) /// - public async Task UpdateTemplateStatusAsync(long id, int status) + public async Task UpdateTemplateStatusAsync(long id) { var template = await petTemplateRepository.GetByIdAsync(id); if (template == null || template.IsDeleted) throw new BusinessException("宠物模板不存在", 404); - - template.Status = status; + + template.Status = template.Status == (int)PetTemplateStatusEnum.Active + ? (int)PetTemplateStatusEnum.Inactive + : (int)PetTemplateStatusEnum.Active; template.UpdatedBy = "System"; template.UpdatedAt = DateTime.Now; await petTemplateRepository.UpdateAsync(template); - logger.LogInformation("更新模板状态成功,Id: {Id}, Status: {Status}", id, status); + logger.LogInformation("更新模板状态成功,Id: {Id}, Status: {Status}", id, template.Status); } private static PetTemplateOutput BuildTemplateOutput(PetTemplate t) diff --git a/QYZH.InteractiveMagazine.Service/ProductService.cs b/QYZH.InteractiveMagazine.Service/ProductService.cs index 77eca9c..b006abe 100644 --- a/QYZH.InteractiveMagazine.Service/ProductService.cs +++ b/QYZH.InteractiveMagazine.Service/ProductService.cs @@ -44,7 +44,7 @@ public class ProductService(BaseRepository productRepository, ILogger

(input.Type, true), - SaleStatus = input.SaleStatus, + Status = (int)input.Status, MetaData = input.MetaData, IsActive = input.IsActive, Stock = input.Stock, @@ -72,7 +72,7 @@ public class ProductService(BaseRepository productRepository, ILogger

productRepository, ILogger

(input.Type, true); - product.SaleStatus = input.SaleStatus; + product.Status = (int)input.Status; product.MetaData = input.MetaData; product.IsActive = input.IsActive; product.Stock = input.Stock; @@ -141,7 +141,7 @@ public class ProductService(BaseRepository productRepository, ILogger

productRepository, ILogger

productRepository, ILogger

p.Name.Contains(input.Name)) .WhereIF(!string.IsNullOrWhiteSpace(input.Type), p => p.Type.ToString() == input.Type) - .WhereIF(!string.IsNullOrWhiteSpace(input.SaleStatus), p => p.SaleStatus == input.SaleStatus) + .WhereIF(input.Status.HasValue, p => p.Status == (int)input.Status) .WhereIF(input.IsActive.HasValue, p => p.IsActive == input.IsActive.Value) .OrderByDescending(p => p.CreatedAt) .Select(p => new ProductOutput @@ -241,7 +241,7 @@ public class ProductService(BaseRepository productRepository, ILogger

productRepository, ILogger

(pageResult, input.PageIndex, input.PageSize, totalNumber); } + + ///

+ /// 更新商品上架/下架状态(取反) + /// + public async Task UpdateSaleStatusAsync(long id) + { + logger.LogInformation("正在更新商品上下架状态,ID: {Id}", id); + + var product = await productRepository.GetByIdAsync(id); + if (product == null) + { + logger.LogWarning("未找到要更新状态的商品,ID: {Id}", id); + throw new BusinessException("商品不存在", 404); + } + + product.Status = product.Status == (int)ProductStatusEnum.OnSale + ? (int)ProductStatusEnum.OffSale + : (int)ProductStatusEnum.OnSale; + product.UpdatedBy = "System"; + product.UpdatedAt = DateTime.Now; + + var result = await productRepository.UpdateAsync(product); + if (!result) + { + logger.LogError("商品状态更新失败,ID: {Id}", id); + throw new BusinessException("更新商品状态失败", 500); + } + + logger.LogInformation("商品上下架状态更新成功,ID: {Id}, SaleStatus: {SaleStatus}", id, product.Status); + } } diff --git a/QYZH.InteractiveMagazine.Service/UsersService.cs b/QYZH.InteractiveMagazine.Service/UsersService.cs index c6e3764..51bb4cc 100644 --- a/QYZH.InteractiveMagazine.Service/UsersService.cs +++ b/QYZH.InteractiveMagazine.Service/UsersService.cs @@ -170,15 +170,14 @@ public class UsersService( /// /// 更新用户状态 /// - public async Task UpdateStatusAsync(long id, UpdateUserStatusInput input) + public async Task UpdateStatusAsync(long id) { - var exists = await Queryable().AnyAsync(u => u.Id == id); - if (!exists) + var exists = await usersRepository.GetByIdAsync(id); + if (exists == null) { return BaseResponse.Fail("用户不存在"); } - - var statusValue = input.Status == 1 ? UserStatusEnum.Active : UserStatusEnum.Disabled; + var statusValue = exists.Status == (int)UserStatusEnum.Active ? UserStatusEnum.Disabled : UserStatusEnum.Active; var result = await UpdateAsync( u => new Users { Status = (int)statusValue }, u => u.Id == id diff --git a/QYZH.InteractiveMagazine.Service/WxMallService.cs b/QYZH.InteractiveMagazine.Service/WxMallService.cs index 445c76b..bdf3dd4 100644 --- a/QYZH.InteractiveMagazine.Service/WxMallService.cs +++ b/QYZH.InteractiveMagazine.Service/WxMallService.cs @@ -45,7 +45,7 @@ public class WxMallService( public async Task> GetProductsAsync(long userId, string? type = null) { var query = exchangeRecordRepository.Context.Queryable() - .Where(p => !p.IsDeleted && p.IsActive && p.SaleStatus == "OnSale") + .Where(p => !p.IsDeleted && p.IsActive && p.Status == (int)ProductStatusEnum.OnSale) .WhereIF(!string.IsNullOrEmpty(type), p => p.Type.ToString() == type) .OrderByDescending(p => p.CreatedAt); @@ -53,7 +53,7 @@ public class WxMallService( // 批量提取 PetBg 商品的 SkinId var skinProductMap = products - .Where(p => p.Type == ProductTypeEnum.PetBg) + .Where(p => p.Type == ProductTypeEnum.PetSkin) .Select(p => new { ProductId = p.Id, SkinId = GetSkinIdFromMetaData(p.MetaData) }) .Where(x => x.SkinId > 0) .ToList(); @@ -122,13 +122,13 @@ public class WxMallService( public async Task GetProductDetailAsync(long userId, long productId) { var product = await exchangeRecordRepository.Context.Queryable() - .Where(p => p.Id == productId && !p.IsDeleted && p.IsActive && p.SaleStatus == "OnSale") + .Where(p => p.Id == productId && !p.IsDeleted && p.IsActive && p.Status == (int)ProductStatusEnum.OnSale) .FirstAsync(); if (product == null) return null; PetSkinBrief? skinBrief = null; - if (product.Type == ProductTypeEnum.PetBg) + if (product.Type == ProductTypeEnum.PetSkin) { var skinId = GetSkinIdFromMetaData(product.MetaData); if (skinId > 0) @@ -190,7 +190,7 @@ public class WxMallService( // 查询商品 var product = await exchangeRecordRepository.Context.Queryable() - .Where(p => p.Id == input.ProductId && !p.IsDeleted && p.IsActive && p.SaleStatus == "OnSale") + .Where(p => p.Id == input.ProductId && !p.IsDeleted && p.IsActive && p.Status == (int)ProductStatusEnum.OnSale) .FirstAsync(); if (product == null) diff --git a/QYZH.InteractiveMagazine.WebApi/Controllers/AdminController.cs b/QYZH.InteractiveMagazine.WebApi/Controllers/AdminController.cs index c17e3ec..b6ce435 100644 --- a/QYZH.InteractiveMagazine.WebApi/Controllers/AdminController.cs +++ b/QYZH.InteractiveMagazine.WebApi/Controllers/AdminController.cs @@ -214,6 +214,31 @@ public class AdminController : BaseController return BaseResponse>.Fail("查询管理员列表失败,请稍后重试"); } } + + /// + /// 切换管理员状态(激活/冻结) + /// + /// 管理员ID + /// 操作结果 + [HttpPut("users/{id}/status")] + public async Task> ToggleUserStatusAsync(long id) + { + try + { + await _adminUserService.ToggleStatusAsync(id); + return Success(new object(), "切换管理员状态成功"); + } + catch (BusinessException ex) + { + _logger.LogWarning(ex, "切换管理员状态业务异常: {Message}", ex.Message); + return BaseResponse.Fail(ex.Message); + } + catch (Exception ex) + { + _logger.LogError(ex, "切换管理员状态系统异常,ID:{Id}", id); + return BaseResponse.Fail("切换状态失败,请稍后重试"); + } + } } public class ChangePasswordInput diff --git a/QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs b/QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs index 7d9eaa1..b4a2c21 100644 --- a/QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs +++ b/QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs @@ -156,22 +156,59 @@ public class MedalController : BaseController /// 状态: 0=禁用, 1=启用 /// 操作结果 [HttpPut("{id}/status")] - public async Task> UpdateStatusAsync(long id, [FromBody] int status) + public async Task> UpdateStatusAsync(long id) { try { - await _medalService.UpdateStatusAsync(id, status); - return Success(new object(), status == 1 ? "启用勋章成功" : "禁用勋章成功"); + var res = await _medalService.UpdateStatusAsync(id); + return Success(res, "更新勋章状态成功"); } catch (BusinessException ex) { _logger.LogWarning(ex, "更新勋章状态业务异常: {Message}", ex.Message); - return BaseResponse.Fail(ex.Message); + return BaseResponse.Fail(ex.Message); } catch (Exception ex) { - _logger.LogError(ex, "更新勋章状态系统异常,ID:{Id},Status:{Status}", id, status); - return BaseResponse.Fail("更新勋章状态失败,请稍后重试"); + _logger.LogError(ex, "更新勋章状态系统异常,ID:{Id}", id); + return BaseResponse.Fail("更新勋章状态失败,请稍后重试"); + } + } + + /// + /// 获取规则配置中可用的目标表列表 + /// + [HttpGet("rule-config/tables")] + public async Task>> GetAvailableTables() + { + try + { + var result = await _medalService.GetAvailableTablesAsync(); + return Success(result); + } + catch (Exception ex) + { + _logger.LogError(ex, "获取可用目标表列表系统异常"); + return BaseResponse>.Fail("获取可用目标表列表失败,请稍后重试"); + } + } + + /// + /// 获取指定表的可用字段列表 + /// + /// 表名 + [HttpGet("rule-config/tables/{tableName}/fields")] + public async Task>> GetTableFields(string tableName) + { + try + { + var result = await _medalService.GetTableFieldsAsync(tableName); + return Success(result); + } + catch (Exception ex) + { + _logger.LogError(ex, "获取可用字段列表系统异常,表名:{TableName}", tableName); + return BaseResponse>.Fail("获取可用字段列表失败,请稍后重试"); } } } diff --git a/QYZH.InteractiveMagazine.WebApi/Controllers/PetManageController.cs b/QYZH.InteractiveMagazine.WebApi/Controllers/PetManageController.cs index 41a1ce5..830c4dc 100644 --- a/QYZH.InteractiveMagazine.WebApi/Controllers/PetManageController.cs +++ b/QYZH.InteractiveMagazine.WebApi/Controllers/PetManageController.cs @@ -145,11 +145,11 @@ public class PetManageController : BaseController /// 更新宠物模板状态(启用/禁用) /// [HttpPut("{id}/status")] - public async Task> UpdateTemplateStatusAsync(long id, [FromBody] int status) + public async Task> UpdateTemplateStatusAsync(long id) { try { - await _petService.UpdateTemplateStatusAsync(id, status); + await _petService.UpdateTemplateStatusAsync(id); return Success(new object(), "更新状态成功"); } catch (BusinessException ex) diff --git a/QYZH.InteractiveMagazine.WebApi/Controllers/ProductController.cs b/QYZH.InteractiveMagazine.WebApi/Controllers/ProductController.cs index a3d5beb..ae56d51 100644 --- a/QYZH.InteractiveMagazine.WebApi/Controllers/ProductController.cs +++ b/QYZH.InteractiveMagazine.WebApi/Controllers/ProductController.cs @@ -148,4 +148,29 @@ public class ProductController : BaseController return BaseResponse>.Fail("查询商品列表失败,请稍后重试"); } } + + /// + /// 更新商品上架/下架状态 + /// + /// 商品ID + /// 操作结果 + [HttpPut("{id}/status")] + public async Task> UpdateSaleStatusAsync(long id) + { + try + { + await _productService.UpdateSaleStatusAsync(id); + return Success(new object(), "更新商品状态成功"); + } + catch (BusinessException ex) + { + _logger.LogWarning(ex, "更新商品状态业务异常: {Message}", ex.Message); + return BaseResponse.Fail(ex.Message); + } + catch (Exception ex) + { + _logger.LogError(ex, "更新商品状态系统异常,ID:{Id}", id); + return BaseResponse.Fail("更新商品状态失败,请稍后重试"); + } + } } diff --git a/QYZH.InteractiveMagazine.WebApi/Controllers/UsersController.cs b/QYZH.InteractiveMagazine.WebApi/Controllers/UsersController.cs index 164d783..4dfc148 100644 --- a/QYZH.InteractiveMagazine.WebApi/Controllers/UsersController.cs +++ b/QYZH.InteractiveMagazine.WebApi/Controllers/UsersController.cs @@ -45,9 +45,9 @@ public class UsersController : BaseController /// 更新用户状态 /// [HttpPut("{id}/status")] - public async Task UpdateStatus(long id, [FromBody] UpdateUserStatusInput input) + public async Task UpdateStatus(long id) { - return await _usersService.UpdateStatusAsync(id, input); + return await _usersService.UpdateStatusAsync(id); } /// diff --git a/QYZH.InteractiveMagazine.WebApi/Program.cs b/QYZH.InteractiveMagazine.WebApi/Program.cs index b0db13c..f74ac79 100644 --- a/QYZH.InteractiveMagazine.WebApi/Program.cs +++ b/QYZH.InteractiveMagazine.WebApi/Program.cs @@ -14,6 +14,7 @@ using QYZH.InteractiveMagazine.Infrastructure.Extensions; using QYZH.InteractiveMagazine.Infrastructure.Middleware; using QYZH.InteractiveMagazine.Models.Entity; using QYZH.InteractiveMagazine.Models.Enum; +using QYZH.InteractiveMagazine.Models.Settings; using QYZH.InteractiveMagazine.Repository; using QYZH.InteractiveMagazine.Repository.Core; using Serilog; @@ -25,6 +26,9 @@ using Yitter.IdGenerator; var builder = WebApplication.CreateBuilder(args); +// 加载勋章规则独立配置文件 +builder.Configuration.AddJsonFile("medal-rule-config.json", optional: false, reloadOnChange: true); + // 初始化雪花ID生成器 YitIdHelper.SetIdGenerator(new IdGeneratorOptions() { WorkerId = 1 }); // autofac注入 允许使用autofac作为DI容器 @@ -141,6 +145,9 @@ builder.Services.AddInfrastructureServices(builder.Configuration, builder.Enviro builder.Services.AddHttpContextAccessor(); builder.Services.AddScoped(typeof(BaseRepository<>)); +// 注册勋章规则配置 +builder.Services.Configure(builder.Configuration.GetSection("MedalRuleConfig")); + // 添加CORS builder.Services.AddCors(options => { diff --git a/QYZH.InteractiveMagazine.WebApi/medal-rule-config.json b/QYZH.InteractiveMagazine.WebApi/medal-rule-config.json new file mode 100644 index 0000000..bc290ad --- /dev/null +++ b/QYZH.InteractiveMagazine.WebApi/medal-rule-config.json @@ -0,0 +1,43 @@ +{ + "MedalRuleConfig": { + "Tables": [ + { + "TableName": "CheckInRecord", + "DisplayName": "签到记录", + "Fields": [ + { "FieldName": "ContinuousDays", "DisplayName": "连续天数" } + ] + }, + { + "TableName": "UserPet", + "DisplayName": "宠物", + "Fields": [ + { + "FieldName": "GrowthPoints", + "DisplayName": "成长值" + }, + { + "FieldName": "FeedingCount", + "DisplayName": "喂养次数" + }, + { + "FieldName": "Comprehension", + "DisplayName": "理解力" + }, + { + "FieldName": "Judgment", + "DisplayName": "判断力" + }, + { + "FieldName": "Expression", + "DisplayName": "表达力" + }, + { + "FieldName": "Persuasiveness", + "DisplayName": "说服力" + } + ] + } + ] + } +}