refactor: 重构状态更新接口,新增商品管理与勋章规则配置
1. 重构用户、宠物模板、勋章、管理员状态更新接口,移除冗余参数改为自动切换状态 2. 重命名宠物背景枚举为宠物皮肤,调整商品状态字段为枚举类型 3. 新增商品上下架状态管理接口与对应逻辑 4. 新增勋章规则配置系统,支持动态加载可用表和字段 5. 优化商品查询与展示逻辑,适配新的状态字段
This commit is contained in:
@ -44,7 +44,7 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
ImageUrl = input.ImageUrl,
|
||||
Price = input.Price,
|
||||
Type = Enum.Parse<ProductTypeEnum>(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<Product> productRepository, ILogger<P
|
||||
ImageUrl = product.ImageUrl,
|
||||
Price = product.Price,
|
||||
Type = product.Type.ToString(),
|
||||
SaleStatus = product.SaleStatus,
|
||||
Status = product.Status.ToString(),
|
||||
MetaData = product.MetaData,
|
||||
IsActive = product.IsActive,
|
||||
Stock = product.Stock,
|
||||
@ -117,7 +117,7 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
product.ImageUrl = input.ImageUrl;
|
||||
product.Price = input.Price;
|
||||
product.Type = Enum.Parse<ProductTypeEnum>(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<Product> productRepository, ILogger<P
|
||||
ImageUrl = product.ImageUrl,
|
||||
Price = product.Price,
|
||||
Type = product.Type.ToString(),
|
||||
SaleStatus = product.SaleStatus,
|
||||
Status = product.Status.ToString(),
|
||||
MetaData = product.MetaData,
|
||||
IsActive = product.IsActive,
|
||||
Stock = product.Stock,
|
||||
@ -198,7 +198,7 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
ImageUrl = product.ImageUrl,
|
||||
Price = product.Price,
|
||||
Type = product.Type.ToString(),
|
||||
SaleStatus = product.SaleStatus,
|
||||
Status = product.Status.ToString(),
|
||||
MetaData = product.MetaData,
|
||||
IsActive = product.IsActive,
|
||||
Stock = product.Stock,
|
||||
@ -230,7 +230,7 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
var pageResult = await productRepository.Queryable()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), p => 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<Product> productRepository, ILogger<P
|
||||
ImageUrl = p.ImageUrl,
|
||||
Price = p.Price,
|
||||
Type = p.Type.ToString(),
|
||||
SaleStatus = p.SaleStatus,
|
||||
Status = p.Status.ToString(),
|
||||
MetaData = p.MetaData,
|
||||
IsActive = p.IsActive,
|
||||
Stock = p.Stock,
|
||||
@ -254,4 +254,34 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
|
||||
return new PageListModel<ProductOutput>(pageResult, input.PageIndex, input.PageSize, totalNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新商品上架/下架状态(取反)
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user