新增修改商品状态(上/下架)
This commit is contained in:
@@ -229,3 +229,42 @@ func (r *Product) PutProduct(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutProductStatus 修改商品状态(上/下架)
|
||||
func (r *Product) PutProductStatus(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.PutProductStatus
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("product_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
productId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
_, err = productService.PutProductStatus(productId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user