package controllers
|
|
import (
|
"github.com/gin-gonic/gin"
|
"wms/extend/code"
|
"wms/extend/util"
|
"wms/models"
|
"wms/request"
|
)
|
|
type ProductController struct {
|
}
|
|
// AddProduct
|
// @Tags 产品
|
// @Summary 添加产品
|
// @Produce application/json
|
// @Param object body models.Product true "产品信息"
|
// @Success 200 {object} util.Response "成功"
|
// @Router /api-wms/v1/product/addProduct [post]
|
func (slf ProductController) AddProduct(c *gin.Context) {
|
var params models.Product
|
if err := c.BindJSON(¶ms); err != nil {
|
util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
|
return
|
}
|
if params.Name == "" {
|
util.ResponseFormat(c, code.RequestParamError, "产品名称不能为空")
|
return
|
}
|
if params.SalePrice.IntPart() <= 0 {
|
util.ResponseFormat(c, code.RequestParamError, "产品售价不能小于等于零")
|
return
|
}
|
err := models.NewProductSearch().Create(¶ms)
|
if err != nil {
|
util.ResponseFormat(c, code.RequestParamError, "产品信息保存失败")
|
return
|
}
|
util.ResponseFormat(c, code.Success, "保存成功")
|
}
|
|
// GetProductList
|
// @Tags 产品
|
// @Summary 获取产品列表
|
// @Produce application/json
|
// @Param object body request.GetProductList true "查询参数"
|
// @Success 200 {object} util.ResponseList{data=[]models.Product} "成功"
|
// @Router /api-wms/v1/product/getProductList [post]
|
func (slf ProductController) GetProductList(c *gin.Context) {
|
var params request.GetProductList
|
if err := c.BindJSON(¶ms); err != nil {
|
util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
|
return
|
}
|
search := models.NewProductSearch()
|
if params.PageInfo.Check() {
|
search.SetPage(params.Page, params.PageSize)
|
}
|
products, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
|
if err != nil {
|
util.ResponseFormat(c, code.RequestParamError, "查找失败")
|
return
|
}
|
|
util.ResponseFormatList(c, code.Success, products, int(total))
|
}
|
|
// GetProductDetails
|
// @Tags 产品
|
// @Summary 获取产品详情
|
// @Produce application/json
|
// @Param object body request.GetProductList true "查询参数"
|
// @Success 200 {object} util.ResponseList{data=[]models.Product} "成功"
|
// @Router /api-wms/v1/product/getProductList [post]
|
func (slf ProductController) GetProductDetails(c *gin.Context) {
|
|
}
|