134 lines
3.4 KiB
Go
134 lines
3.4 KiB
Go
|
package inventorymanage
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"go-admin/app/admin/models"
|
||
|
"go-admin/tools"
|
||
|
"go-admin/tools/app"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
// GetInventoryList 查询库存列表
|
||
|
// @Summary 查询库存列表
|
||
|
// @Tags 库存管理
|
||
|
// @Produce json
|
||
|
// @Accept json
|
||
|
// @Param request body models.ErpStockListReq true "查询库存列表模型"
|
||
|
// @Success 200 {object} models.ErpStockListResp
|
||
|
// @Router /api/v1/inventory/list [post]
|
||
|
func GetInventoryList(c *gin.Context) {
|
||
|
req := &models.ErpStockListReq{}
|
||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||
|
//logger.Error(err)
|
||
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
resp, err := req.List()
|
||
|
if err != nil {
|
||
|
//logger.Error("erp commodity list err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "获取失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
app.OK(c, resp, "OK")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// GetInventoryDetail 查询库存详情
|
||
|
// @Summary 查询库存详情
|
||
|
// @Tags 库存管理
|
||
|
// @Produce json
|
||
|
// @Accept json
|
||
|
// @Param request body models.ErpStockCommodityListReq true "查询库存详情模型"
|
||
|
// @Success 200 {object} models.ErpStockCommodityListResp
|
||
|
// @Router /api/v1/inventory/detail [post]
|
||
|
func GetInventoryDetail(c *gin.Context) {
|
||
|
req := &models.ErpStockCommodityListReq{}
|
||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||
|
//logger.Error(err)
|
||
|
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
list, err := req.GetDetailList()
|
||
|
if err != nil {
|
||
|
//logger.Error("erp stock err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "获取失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
app.OK(c, list, "OK")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
type DeliveryCargoReq struct {
|
||
|
Id uint32 `json:"id" binding:"required"` // 商品库存列表id
|
||
|
State uint32 `json:"state" binding:"required"` // 库存状态:4-出库
|
||
|
}
|
||
|
|
||
|
// DeliveryCargo 出库
|
||
|
// @Summary 出库
|
||
|
// @Tags 库存管理
|
||
|
// @Produce json
|
||
|
// @Accept json
|
||
|
// @Param request body DeliveryCargoReq true "出库模型"
|
||
|
// @Success 200 {object} app.Response
|
||
|
// @Router /api/v1/inventory/delivery [post]
|
||
|
func DeliveryCargo(c *gin.Context) {
|
||
|
req := &DeliveryCargoReq{}
|
||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||
|
//logger.Error(err)
|
||
|
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if err := tools.Validate(req); err != nil {
|
||
|
app.Error(c, http.StatusBadRequest, err, err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := models.SetStockCommodityState(req.Id, req.State)
|
||
|
if err != nil {
|
||
|
//logger.Error("erp stock err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "获取失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
app.OK(c, nil, "OK")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// BatchPrint 批量打印
|
||
|
// @Summary 批量打印
|
||
|
// @Tags 库存管理
|
||
|
// @Produce json
|
||
|
// @Accept json
|
||
|
// @Param request body models.BatchPrintInfoReq true "批量打印模型"
|
||
|
// @Success 200 {object} app.Response
|
||
|
// @Router /api/v1/inventory/print [post]
|
||
|
func BatchPrint(c *gin.Context) {
|
||
|
req := &models.BatchPrintInfoReq{}
|
||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||
|
//logger.Error(err)
|
||
|
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if err := tools.Validate(req); err != nil {
|
||
|
app.Error(c, http.StatusBadRequest, err, err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := models.BatchPrint(req)
|
||
|
if err != nil {
|
||
|
//logger.Error("erp stock err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "打印失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
app.OK(c, nil, "OK")
|
||
|
return
|
||
|
}
|