From 1444c7c800fc042cd99213e901d6ad3722d0f03f Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期三, 27 九月 2023 16:13:53 +0800 Subject: [PATCH] 1.二期一部分代码 --- controllers/product_controller.go | 53 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 35 insertions(+), 18 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index ca6f24e..c1f3d00 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -76,12 +76,28 @@ if params.PageInfo.Check() { search.SetPage(params.Page, params.PageSize) } - products, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find() + products, total, err := search.SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") return } + ids := make([]int, 0) + for _, product := range products { + ids = append(ids, product.CategoryId) + } + categories, err := models.NewProductCategorySearch().SetIds(ids).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鏌ユ壘澶辫触") + return + } + for _, product := range products { + for _, category := range categories { + if product.CategoryId == int(category.ID) { + product.CategoryName = category.Name + } + } + } util.ResponseFormatList(c, code.Success, products, int(total)) } @@ -343,20 +359,19 @@ return } detail := &models.OperationDetails{ - ProductId: params.ProductId, - ProductName: params.ProductName, - Amount: params.Amount, - Unit: params.Unit, + ProductId: params.ProductId, + Amount: params.Amount, } operation := models.Operation{ - Number: strconv.FormatInt(time.Now().Unix(), 10), - SourceNumber: params.SourceNumber, - OperationTypeId: 0, - Status: constvar.OperationStatus_Ready, - FromLocationID: params.FromLocationId, - ToLocationID: params.ToLocationId, - OperationDate: time.Now().Format("2006-01-02 15:04:05"), - Details: []*models.OperationDetails{detail}, + Number: strconv.FormatInt(time.Now().Unix(), 10), + SourceNumber: params.SourceNumber, + OperationTypeId: 0, + Status: constvar.OperationStatus_Ready, + FromLocationID: params.FromLocationId, + ToLocationID: params.ToLocationId, + OperationDate: time.Now().Format("2006-01-02 15:04:05"), + Details: []*models.OperationDetails{detail}, + BaseOperationType: constvar.BaseOperationTypeDisuse, } if err := models.NewOperationSearch().Create(&operation); err != nil { logx.Errorf("Operation create err: %v", err) @@ -384,7 +399,9 @@ 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,wms_operation_details.product_name,wms_operation_details.unit,wms_operation_details.amount").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id") + //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,wms_operation_details.product_name,wms_operation_details.unit,wms_operation_details.amount").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id") + + 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") if params.SourceNumber != "" { db = db.Where("wms_operation.source_number like ?", fmt.Sprintf("%%%v%%", params.SourceNumber)) @@ -515,10 +532,10 @@ return } detail := &models.OperationDetails{ - ProductId: params.ProductId, - ProductName: params.ProductName, - Amount: params.Amount, - Unit: params.Unit, + ProductId: params.ProductId, + //ProductName: params.ProductName, + Amount: params.Amount, + //Unit: params.Unit, } operation := models.Operation{ Id: params.Id, -- Gitblit v1.8.0