新增出库接口,优化发现的缺陷
This commit is contained in:
parent
e156b3d7d5
commit
b95911437f
|
@ -10,7 +10,6 @@ import (
|
|||
"go-admin/tools/app"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CommodityCreateRequest struct {
|
||||
|
@ -22,7 +21,7 @@ type CommodityCreateRequest struct {
|
|||
MinRetailPrice uint32 `json:"min_retail_price" binding:"required"` // 最低零售价
|
||||
StaffCostPrice uint32 `json:"staff_cost_price" binding:"required"` // 员工成本价加价
|
||||
WholesalePrice uint32 `json:"wholesale_price" binding:"required"` // 指导采购价
|
||||
Brokerage1 string `json:"brokerage_1" binding:"required"` // 销售毛利提成
|
||||
Brokerage1 string `json:"brokerage_1"` // 销售毛利提成
|
||||
Brokerage2 string `json:"brokerage_2"` // 员工毛利提成
|
||||
MemberDiscount string `json:"member_discount"` // 会员优惠
|
||||
Origin string `json:"origin"` // 产地
|
||||
|
@ -44,27 +43,31 @@ func CommodityCreate(c *gin.Context) {
|
|||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
//logger.Error(err)
|
||||
fmt.Println(err.Error())
|
||||
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||||
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||||
return
|
||||
}
|
||||
brokerage1Float, err := strconv.ParseFloat(req.Brokerage1, 64)
|
||||
|
||||
brokerage1Float, err := models.StringToFloat(req.Brokerage1)
|
||||
if err != nil {
|
||||
//logger.Error("brokerage1 err:", err)
|
||||
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||||
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||||
return
|
||||
}
|
||||
brokerage2Float, err := strconv.ParseFloat(req.Brokerage2, 64)
|
||||
|
||||
brokerage2Float, err := models.StringToFloat(req.Brokerage2)
|
||||
if err != nil {
|
||||
//logger.Error("brokerage2 err:", err)
|
||||
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||||
//logger.Error("brokerage1 err:", err)
|
||||
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||||
return
|
||||
}
|
||||
memberDiscountFloat, err := strconv.ParseFloat(req.MemberDiscount, 64)
|
||||
|
||||
memberDiscountFloat, err := models.StringToFloat(req.MemberDiscount)
|
||||
if err != nil {
|
||||
//logger.Error("member discount err:", err)
|
||||
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||||
//logger.Error("brokerage1 err:", err)
|
||||
app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
commodity := &models.ErpCommodity{
|
||||
Number: 1,
|
||||
Name: req.Name,
|
||||
|
@ -104,7 +107,7 @@ func CommodityCreate(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
app.OK(c, commodity, "")
|
||||
app.OK(c, commodity, "OK")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
package inventory
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/tools/app"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// InventoryList 查询库存列表
|
||||
// @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
|
||||
}
|
||||
|
||||
// InventoryDetail 查询库存详情
|
||||
// @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
|
||||
}
|
133
app/admin/apis/inventorymanage/Inventory.go
Normal file
133
app/admin/apis/inventorymanage/Inventory.go
Normal file
|
@ -0,0 +1,133 @@
|
|||
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
|
||||
}
|
|
@ -939,10 +939,10 @@ func (m *StockImporter) ErpInventoryStockCreate(gdb *gorm.DB, list []ErpStockFil
|
|||
|
||||
inventoryStockIdMap := make(map[string]uint32, 0)
|
||||
for _, inventory := range m.Inventories {
|
||||
//err := gdb.Create(inventory).Error
|
||||
//err := gdb.Create(inventorymanage).Error
|
||||
err := orm.Eloquent.Create(inventory).Error
|
||||
if err != nil {
|
||||
//logger.Error("create erp inventory stock err:", err)
|
||||
//logger.Error("create erp inventorymanage stock err:", err)
|
||||
return err
|
||||
}
|
||||
inventoryStockIdMap[fmt.Sprintf("%d_%d", inventory.StoreId, inventory.ErpCommodityId)] = inventory.ID
|
||||
|
@ -993,14 +993,14 @@ func (m *StockImporter) ErpInventoryStockCreate(gdb *gorm.DB, list []ErpStockFil
|
|||
|
||||
//go func() {
|
||||
// //inventoryStockIdMap := make(map[string]uint32, 0)
|
||||
// //for _, inventory := range m.Inventories {
|
||||
// // //err := gdb.Create(inventory).Error
|
||||
// // err := orm.Eloquent.Create(inventory).Error
|
||||
// //for _, inventorymanage := range m.Inventories {
|
||||
// // //err := gdb.Create(inventorymanage).Error
|
||||
// // err := orm.Eloquent.Create(inventorymanage).Error
|
||||
// // if err != nil {
|
||||
// // logger.Error("create erp inventory stock err:", err)
|
||||
// // logger.Error("create erp inventorymanage stock err:", err)
|
||||
// // return
|
||||
// // }
|
||||
// // inventoryStockIdMap[fmt.Sprintf("%d_%d", inventory.StoreId, inventory.ErpCommodityId)] = inventory.ID
|
||||
// // inventoryStockIdMap[fmt.Sprintf("%d_%d", inventorymanage.StoreId, inventorymanage.ErpCommodityId)] = inventorymanage.ID
|
||||
// //}
|
||||
//
|
||||
// //stock := ErpStockFileExcel{}
|
||||
|
@ -1027,7 +1027,7 @@ func (m *StockImporter) ErpInventoryStockCreate(gdb *gorm.DB, list []ErpStockFil
|
|||
// //err := gdb.Create(inventoryCommodity).Error
|
||||
// err := orm.Eloquent.Create(inventoryCommodity).Error
|
||||
// if err != nil {
|
||||
// logger.Error("create erp inventory stock commodity err:", err)
|
||||
// logger.Error("create erp inventorymanage stock commodity err:", err)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
@ -1062,7 +1062,7 @@ func ErpStockCommodityToInventory(inventoryStockIdMap map[string]uint32, list []
|
|||
inventoryList = append(inventoryList, inventoryCommodity)
|
||||
//err := orm.Eloquent.Create(inventoryCommodity).Error
|
||||
//if err != nil {
|
||||
// logger.Error("create erp inventory stock commodity err:", err)
|
||||
// logger.Error("create erp inventorymanage stock commodity err:", err)
|
||||
// return inventoryList
|
||||
//}
|
||||
}
|
||||
|
@ -1191,7 +1191,7 @@ func (m *ErpStockListReq) List() (*ErpStockListResp, error) {
|
|||
qs = qs.Where("commodity_serial_number=?", m.SerialNumber)
|
||||
}
|
||||
if m.CommodityName != "" {
|
||||
qs = qs.Where("name Like %" + m.CommodityName + "%")
|
||||
qs = qs.Where("erp_commodity_name LIKE ?", "%"+m.CommodityName+"%")
|
||||
}
|
||||
if m.ErpCategoryId != 0 {
|
||||
qs = qs.Where("erp_category_id=?", m.ErpCategoryId)
|
||||
|
@ -1389,3 +1389,38 @@ func (m *ErpStockCommodityListReq) buildQueryConditions(qs *gorm.DB) {
|
|||
qs = qs.Where("first_stock_time<?", time.Now().AddDate(0, 0, int(m.AllAge)*(-1)))
|
||||
}
|
||||
}
|
||||
|
||||
func SetStockCommodityState(id, state uint32) error {
|
||||
if state != 4 {
|
||||
state = 4
|
||||
}
|
||||
if err := orm.Eloquent.Model(&ErpStockCommodity{}).Where("id=?", id).Updates(map[string]interface{}{
|
||||
"state": state}).Error; err != nil {
|
||||
return fmt.Errorf("[update err]:%v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type BatchPrintInfo struct {
|
||||
ErpCommodityName string `json:"erp_commodity_name" binding:"required"` // 商品名称
|
||||
RetailPrice uint32 `json:"retail_price" binding:"required"` // 指导零售价
|
||||
IMEI string `json:"imei" binding:"required"` // 商品串码
|
||||
}
|
||||
|
||||
type BatchPrintInfoReq struct {
|
||||
PrintListInfo []*BatchPrintInfo `json:"print_list_info" binding:"required"`
|
||||
}
|
||||
|
||||
func BatchPrint(req *BatchPrintInfoReq) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func StringToFloat(req string) (float64, error) {
|
||||
if req == "" {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return strconv.ParseFloat(req, 64)
|
||||
}
|
||||
|
|
|
@ -2,13 +2,15 @@ package router
|
|||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/app/admin/apis/inventory"
|
||||
"go-admin/app/admin/apis/inventorymanage"
|
||||
"go-admin/app/admin/middleware"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
func registerInventoryManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
r := v1.Group("/inventory").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
r.POST("list", inventory.GetInventoryList)
|
||||
r.POST("detail", inventory.GetInventoryDetail)
|
||||
r.POST("list", inventorymanage.GetInventoryList)
|
||||
r.POST("detail", inventorymanage.GetInventoryDetail)
|
||||
r.POST("delivery", inventorymanage.DeliveryCargo) // 出库
|
||||
r.POST("print", inventorymanage.BatchPrint) // 出库
|
||||
}
|
||||
|
|
|
@ -1473,10 +1473,10 @@ const docTemplate = `{
|
|||
"tags": [
|
||||
"库存管理"
|
||||
],
|
||||
"summary": "查询库存详情",
|
||||
"summary": "出库",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "查询库存详情模型",
|
||||
"description": "出库模型",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
|
|
|
@ -1462,10 +1462,10 @@
|
|||
"tags": [
|
||||
"库存管理"
|
||||
],
|
||||
"summary": "查询库存详情",
|
||||
"summary": "出库",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "查询库存详情模型",
|
||||
"description": "出库模型",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
|
|
|
@ -2774,7 +2774,7 @@ paths:
|
|||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 查询库存详情模型
|
||||
- description: 出库模型
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
|
@ -2787,7 +2787,7 @@ paths:
|
|||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/models.ErpStockCommodityListResp'
|
||||
summary: 查询库存详情
|
||||
summary: 出库
|
||||
tags:
|
||||
- 库存管理
|
||||
/api/v1/inventory/list:
|
||||
|
|
Loading…
Reference in New Issue
Block a user