| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "errors" |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择位置") |
| | | return |
| | | } |
| | | if params.ProductId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | |
| | | if params.RuleType != constvar.RuleType_Product && params.RuleType != constvar.RuleType_ProductCategory { |
| | | util.ResponseFormat(c, code.RequestParamError, "ruleType异常") |
| | | return |
| | | } |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | |
| | | if params.RuleType == constvar.RuleType_Product { |
| | | if params.ProductId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | return |
| | | } |
| | | if _, err := models.NewLocationProductSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil { |
| | | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } else { |
| | | util.ResponseFormat(c, code.RequestParamError, "已存在该上家规则,请勿重复添加") |
| | | return |
| | | } |
| | | } |
| | | |
| | | if params.RuleType == constvar.RuleType_ProductCategory { |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | } |
| | | if _, err := models.NewLocationProductSearch().SetProductCategoryId(params.ProductCategoryID).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil { |
| | | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } else { |
| | | util.ResponseFormat(c, code.RequestParamError, "已存在该上家规则,请勿重复添加") |
| | | return |
| | | } |
| | | } |
| | | |
| | | if err := models.NewLocationProductSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("Operation create err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) |
| | |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/list [post] |
| | | func (slf LocationProductController) List(c *gin.Context) { |
| | | var params request.PageInfo |
| | | var params request.QueryLocationProductConditon |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if params.Check() { |
| | | if !params.Check() { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数异常") |
| | | return |
| | | } |
| | | |
| | | search := models.NewLocationProductSearch() |
| | | search.SetPage(params.Page, params.PageSize) |
| | | |
| | | if params.ProductId != "" { |
| | | search = search.SetProductId(params.ProductId) |
| | | } |
| | | |
| | | if params.ProductCategoryId != 0 { |
| | | search = search.SetProductCategoryId(params.ProductCategoryId) |
| | | } |
| | | list, total, err := search.SetPreload(true).SetOrder("created_at desc").FindByPage() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error()) |
| | |
| | | // @Tags 上架规则 |
| | | // @Summary 修改上架规则 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateLocationProduct true "入库信息" |
| | | // @Param object body request.UpdateLocationProduct true "修改参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/locationProduct/update [post] |
| | | func (slf LocationProductController) Update(c *gin.Context) { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择位置") |
| | | return |
| | | } |
| | | if params.ProductId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | |
| | | if params.RuleType != constvar.RuleType_Product && params.RuleType != constvar.RuleType_ProductCategory { |
| | | util.ResponseFormat(c, code.RequestParamError, "ruleType异常") |
| | | return |
| | | } |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | |
| | | if params.RuleType == constvar.RuleType_Product { |
| | | if params.ProductId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品") |
| | | return |
| | | } |
| | | if rule, err := models.NewLocationProductSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil { |
| | | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } else if params.Id != rule.Id { |
| | | util.ResponseFormat(c, code.RequestParamError, "已存在该上家规则,请勿重复添加") |
| | | return |
| | | } |
| | | } |
| | | |
| | | if params.RuleType == constvar.RuleType_ProductCategory { |
| | | if params.ProductCategoryID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "请选择产品类别") |
| | | return |
| | | } |
| | | if rule, err := models.NewLocationProductSearch().SetProductCategoryId(params.ProductCategoryID).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil { |
| | | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } else if params.Id != rule.Id { |
| | | util.ResponseFormat(c, code.RequestParamError, "已存在该上家规则,请勿重复添加") |
| | | return |
| | | } |
| | | } |
| | | |
| | | if err := models.NewLocationProductSearch().SetID(params.Id).Update(¶ms); err != nil { |
| | | logx.Errorf("LocationProduct update err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "修改失败:"+err.Error()) |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "id为0") |
| | | return |
| | | } |
| | | //TODO:此处可能需要增加限制,如果该上架规则如果已经产生了库存数量,删除会造成库存查不到的影响 |
| | | if err := models.NewLocationProductSearch().SetID(id).Delete(); err != nil { |
| | | logx.Errorf("LocationProduct delete err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "删除失败:"+err.Error()) |