liujiandao
2023-09-18 40eb578f79a0f0dcf0bbfa2c267478d159f0f58c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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(&params); 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(&params)
    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(&params); 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) {
 
}