Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 39s
refactor(service): 修改banner和guild删除逻辑为软删除 fix(service): 修复删除操作使用软删除而非物理删除 build: 添加SQLite测试仓库实现 docs: 新增奖励管理字段拆分和批量抽奖UI改造文档 ci: 更新CI忽略文件 style: 清理无用资源文件
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
)
|
|
|
|
type batchUpdateProductsRequest struct {
|
|
IDs []int64 `json:"ids" binding:"required"`
|
|
Stock *int64 `json:"stock"`
|
|
Status *int32 `json:"status"`
|
|
}
|
|
|
|
type batchUpdateProductsResponse struct {
|
|
UpdatedCount int64 `json:"updated_count"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// BatchUpdateProducts 批量更新商品
|
|
// @Summary 批量更新商品(库存/上下架)
|
|
// @Tags 管理端.商品
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param RequestBody body batchUpdateProductsRequest true "请求参数"
|
|
// @Success 200 {object} batchUpdateProductsResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/admin/products/batch [put]
|
|
// @Security LoginVerifyToken
|
|
func (h *handler) BatchUpdateProducts() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
req := new(batchUpdateProductsRequest)
|
|
res := new(batchUpdateProductsResponse)
|
|
if err := ctx.ShouldBindJSON(req); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
|
return
|
|
}
|
|
if ctx.SessionUserInfo().IsSuper != 1 {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.CreateAdminError, "禁止操作"))
|
|
return
|
|
}
|
|
if len(req.IDs) == 0 || (req.Stock == nil && req.Status == nil) {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "参数错误"))
|
|
return
|
|
}
|
|
if len(req.IDs) > 1000 {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "最多支持1000个ID"))
|
|
return
|
|
}
|
|
|
|
updated, err := h.product.BatchUpdate(ctx.RequestContext(), req.IDs, req.Stock, req.Status)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.CreateAdminError, err.Error()))
|
|
return
|
|
}
|
|
res.UpdatedCount = updated
|
|
res.Message = "操作成功"
|
|
ctx.Payload(res)
|
|
}
|
|
} |