From fda60dd56911c03330eb7330ebabd5d46e9d7622 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期五, 15 十二月 2023 16:14:03 +0800 Subject: [PATCH] 库存盘点列表bug --- controllers/product_controller.go | 70 +++++++++++++++++++++++++++++------ 1 files changed, 58 insertions(+), 12 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index fa65e70..449e97b 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -14,8 +14,8 @@ "wms/extend/util" "wms/models" "wms/pkg/logx" + "wms/pkg/mysqlx" "wms/request" - "wms/utils" ) type ProductController struct { @@ -34,6 +34,10 @@ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") return } + if params.ID == "" { + util.ResponseFormat(c, code.RequestParamError, "浜у搧缂栫爜涓嶈兘涓虹┖") + return + } if params.Name == "" { util.ResponseFormat(c, code.RequestParamError, "浜у搧鍚嶇О涓嶈兘涓虹┖") return @@ -46,7 +50,7 @@ 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, "浜у搧淇℃伅淇濆瓨澶辫触") @@ -125,8 +129,7 @@ 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}). @@ -146,6 +149,16 @@ 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)) } @@ -200,6 +213,22 @@ 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{} @@ -306,7 +335,7 @@ 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 @@ -331,7 +360,7 @@ 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 @@ -352,7 +381,7 @@ 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 @@ -419,12 +448,28 @@ util.ResponseFormat(c, code.RequestParamError, "璇疯緭鍏ユ簮鍗曟嵁") return } + if params.Number == "" { + util.ResponseFormat(c, code.RequestParamError, "璇疯緭鍏ュ崟鍙�") + return + } + + var numberNum int64 + if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + if numberNum > 0 { + util.ResponseFormat(c, code.RequestParamError, "鍗曞彿宸插瓨鍦�") + return + } + detail := &models.OperationDetails{ ProductId: params.ProductId, Amount: params.Amount, } operation := models.Operation{ - Number: strconv.FormatInt(time.Now().Unix(), 10), + //Number: strconv.FormatInt(time.Now().Unix(), 10), + Number: params.Number, SourceNumber: params.SourceNumber, OperationTypeId: 0, Status: constvar.OperationStatus_Ready, @@ -460,7 +505,7 @@ return } - db := models.NewOperationSearch().Orm.Table("wms_operation").Select("wms_operation.id,wms_operation.number,wms_operation.source_number,wms_operation.status,wms_operation.from_location_id,wms_operation.to_location_id,wms_operation.operation_date,wms_operation.contacter_id,wms_operation.contacter_name,wms_operation.company_id,wms_operation.company_name,wms_operation.comment,wms_operation_details.product_id,material.name as product_name,material.unit,wms_operation_details.amount").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").InnerJoins("inner join material on material.id=wms_operation_details.product_id").Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeDisuse) + db := models.NewOperationSearch().Orm.Table("wms_operation").Select("wms_operation.id,wms_operation.number,wms_operation.source_number,wms_operation.status,wms_operation.from_location_id,wms_operation.to_location_id,wms_operation.operation_date,wms_operation.contacter_id,wms_operation.contacter_name,wms_operation.company_id,wms_operation.company_name,wms_operation.comment,wms_operation_details.product_id,material.name as product_name,material.unit,wms_operation_details.amount,wms_operation.base_operation_type").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").InnerJoins("inner join material on material.id=wms_operation_details.product_id").Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeDisuse) if params.Number != "" { db = db.Where("wms_operation.number like ? or wms_operation.source_number like ? or material.name like ?", fmt.Sprintf("%%%v%%", params.Number), fmt.Sprintf("%%%v%%", params.Number), fmt.Sprintf("%%%v%%", params.Number)) @@ -516,7 +561,7 @@ 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 @@ -563,7 +608,7 @@ locAmount, res := models.NewLocationProductAmountSearch(). SetProductId(v.ID). - SetLocationId(operation.ToLocationID). + SetLocationId(operation.FromLocationID). FirstRes() if res.Error != nil { return err @@ -680,7 +725,7 @@ 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 @@ -717,6 +762,7 @@ 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 -- Gitblit v1.8.0