| | |
| | | return |
| | | } |
| | | |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if CheckDetailsRepeat(params.Details) { |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | var operationType *models.OperationType |
| | | var err error |
| | | if params.OperationTypeId == 0 { |
| | | operationType, err = models.NewOperationTypeSearch().SetWarehouseId(params.WarehouseId).SetBaseOperationType(params.BaseOperationType).First() |
| | | if err != nil || params.WarehouseId != operationType.WarehouseId { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | } else { |
| | | operationType, err = models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | |
| | | if params.BaseOperationType != constvar.BaseOperationTypeAdjust { |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | var operationType *models.OperationType |
| | | var err error |
| | | if params.OperationTypeId == 0 { |
| | | operationType, err := models.NewOperationTypeSearch(). |
| | | SetWarehouseId(params.WarehouseId).SetBaseOperationType(params.BaseOperationType). |
| | | First() |
| | | if err != nil || params.WarehouseId != operationType.WarehouseId { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | } else { |
| | | operationType, err = models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } |
| | | params.BaseOperationType = operationType.BaseOperationType |
| | | params.WarehouseId = operationType.WarehouseId |
| | | } |
| | | |
| | | userInfo := middleware.GetUserInfo(c) |
| | | params.CreatedBy = userInfo.Username |
| | | params.Status = constvar.OperationStatus_Ready |
| | | //params.Number = strconv.FormatInt(time.Now().Unix(), 10) |
| | | params.BaseOperationType = operationType.BaseOperationType |
| | | params.WarehouseId = operationType.WarehouseId |
| | | |
| | | var numberNum int64 |
| | | if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "单号已存在") |
| | | return |
| | | } |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err := models.WithTransaction(func(db *gorm.DB) error { |
| | | if err := models.NewOperationSearch().Create(¶ms); err != nil { |
| | | return err |
| | | } |
| | |
| | | return false |
| | | } |
| | | |
| | | // FormatLocation 位置检查 |
| | | func (slf OperationController) FormatLocation(params *models.Operation) error { |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | |
| | | return errors.New("请选择安排日期") |
| | | } |
| | | |
| | | if params.LocationID == 0 { |
| | | return errors.New("请选择源位置") |
| | | } |
| | | //if params.LocationID == 0 { |
| | | // return errors.New("请选择源位置") |
| | | //} |
| | | |
| | | if len(params.Details) <= 0 { |
| | | return errors.New("请添加明细信息") |
| | |
| | | // @Summary 入库/出库列表 |
| | | // @Produce application/json |
| | | // @Param object body request.OperationList true "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.Operation} "成功" |
| | | // @Router /api-wms/v1/operation/list [post] |
| | | func (slf OperationController) List(c *gin.Context) { |
| | | var params request.OperationList |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | |
| | | if params.BaseOperationType != constvar.BaseOperationTypeAdjust { |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { |