| | |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/request" |
| | | "wms/utils" |
| | | ) |
| | | |
| | | type ProductController struct { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if params.ID == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "产品编码不能为空") |
| | | return |
| | | } |
| | | if params.Name == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "产品名称不能为空") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "单位不能为空") |
| | | return |
| | | } |
| | | params.ID = utils.GetUUID() |
| | | //params.ID = utils.GetUUID() |
| | | err := models.NewMaterialSearch().Create(¶ms) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "产品信息保存失败") |
| | |
| | | product.PredictionAmount = product.Amount.Add(reorderAmount.TotalAmount) |
| | | |
| | | var statisticsList []*request.ProductStatistics |
| | | if err := models.NewOperationSearch().Orm. |
| | | Table("wms_operation"). |
| | | if err := models.NewOperationSearch().Orm.Table("wms_operation"). |
| | | InnerJoins("INNER JOIN wms_operation_details on wms_operation_details.operation_id=wms_operation.id"). |
| | | Select("SUM(wms_operation_details.amount) as total_amount,wms_operation.base_operation_type"). |
| | | Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Finish, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}). |
| | |
| | | product.OutputAmount = product.OutputAmount.Add(v.TotalAmount) |
| | | } |
| | | } |
| | | reorderRules, rulesTotal, err := models.NewReorderRuleSearch().SetProductId(product.ID).Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "重订货规则统计失败") |
| | | return |
| | | } |
| | | if rulesTotal == 1 { |
| | | product.MinInventoryRule = reorderRules[0].MinInventory |
| | | product.MaxInventoryRule = reorderRules[0].MaxInventory |
| | | } |
| | | product.ReorderRuleNum = rulesTotal |
| | | } |
| | | util.ResponseFormatList(c, code.Success, products, int(total)) |
| | | } |
| | |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "产品信息更新失败") |
| | | return |
| | | } |
| | | |
| | | //更新在库的产品类型 |
| | | if params.CategoryId > 0 { |
| | | find, _ := models.NewLocationProductAmountSearch().SetProductId(params.ID).Find() |
| | | if len(find) > 0 { |
| | | var ids []int |
| | | for _, f := range find { |
| | | if f.ProductCategoryID != params.CategoryId { |
| | | ids = append(ids, f.Id) |
| | | } |
| | | } |
| | | m := make(map[string]interface{}) |
| | | m["productCategoryId"] = params.CategoryId |
| | | _ = models.NewLocationProductAmountSearch().SetIds(ids).UpdateByMap(m) |
| | | } |
| | | } |
| | | |
| | | materialAttachmentList := []*models.MaterialAttachment{} |
| | |
| | | return |
| | | } |
| | | |
| | | first, err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).First() |
| | | first, err := models.NewProductCategorySearch().SetID(cast.ToInt(id)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "产品类型名称不能为空") |
| | | return |
| | | } |
| | | err := models.NewProductCategorySearch().SetID(params.ID).Save(¶ms) |
| | | err := models.NewProductCategorySearch().SetID(params.Id).Save(¶ms) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "产品类型信息更新失败") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "无效id") |
| | | return |
| | | } |
| | | err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).Delete() |
| | | err := models.NewProductCategorySearch().SetID(cast.ToInt(id)).Delete() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |
| | |
| | | return |
| | | } |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish}); err != nil { |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish, AuditDate: time.Now().Format("2006-01-02 15:04:05")}); err != nil { |
| | | return err |
| | | } |
| | | var listProdtId []string |
| | |
| | | |
| | | locAmount, res := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(operation.ToLocationID). |
| | | SetLocationId(operation.FromLocationID). |
| | | FirstRes() |
| | | if res.Error != nil { |
| | | return err |
| | |
| | | search := models.NewOperationSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetOrder("created_at desc") |
| | | search.SetOrm(search.Orm.InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").Where("wms_operation_details.product_id=? and (wms_operation.from_location_id=? or wms_operation.to_location_id=?)", params.ProductId, params.LocationId, params.LocationId)) |
| | | |
| | | list, total, err := search.Find() |
| | | list, total, err := search.SetBaseOperationType(constvar.BaseOperationTypeAdjust).Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error()) |
| | | return |
| | |
| | | return |
| | | } |
| | | operation.Status = constvar.OperationStatus_Cancel |
| | | operation.AuditDate = time.Now().Format("2006-01-02 15:04:05") |
| | | if err := models.NewOperationSearch().SetID(operation.Id).Save(operation); err != nil { |
| | | util.ResponseFormat(c, code.SaveFail, err.Error()) |
| | | return |