| | |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "sort" |
| | | "strconv" |
| | | "time" |
| | | "wms/constvar" |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if CheckDetailsRepeat(params.Details) { |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | func CheckDetailsRepeat(details []*models.OperationDetails) bool { |
| | | detailIDs := []string{} |
| | | var tempID string |
| | | for _, v := range details { |
| | | detailIDs = append(detailIDs, v.ProductId) |
| | | } |
| | | sort.Strings(detailIDs) |
| | | for _, v := range detailIDs { |
| | | if v != tempID { |
| | | tempID = v |
| | | } else { |
| | | return true |
| | | } |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func (slf OperationController) FormatLocation(params *models.Operation) error { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if CheckDetailsRepeat(params.Details) { |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |