新增系统商品
This commit is contained in:
@@ -155,3 +155,38 @@ func (r *Product) GetProduct(c *gin.Context) {
|
||||
|
||||
responses.OkWithData(getPlatformProductResponses, c)
|
||||
}
|
||||
|
||||
// AddProduct 新增商品
|
||||
func (r *Product) AddProduct(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.AddProduct
|
||||
if err := c.ShouldBindJSON(&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
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId == 0 {
|
||||
responses.FailWithMessage("角色错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
userIdStr := strconv.FormatInt(userId, 10)
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
_, err := productService.AddProduct(userIdStr, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user