From 504f3e9bc274bcd6c7221e738802e0e5d4aef36f Mon Sep 17 00:00:00 2001 From: lishihai <dslsh@dscom> Date: 星期四, 20 六月 2024 17:07:02 +0800 Subject: [PATCH] 查询属性值和对象 通过主键ID查询 --- controllers/location_product_amount.go | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/controllers/location_product_amount.go b/controllers/location_product_amount.go index f0a4ec6..5a62cb9 100644 --- a/controllers/location_product_amount.go +++ b/controllers/location_product_amount.go @@ -57,7 +57,7 @@ //wms_operation_details.amount as adjust_amount,wms_operation.id as operation_id,wms_operation.status search.Orm = search.Orm. Table("wms_location_product_amount"). - Select(`wms_location_product_amount.id as location_product_amount_id,wms_location.id as location_id,wms_location.name as location_name, + Select(`wms_location_product_amount.id as location_product_amount_id,wms_location.id as location_id,wms_location.joint_name as location_name, material.id as product_id,material.name as product_name,wms_location_product_amount.amount,material.unit, wms_location_product_amount.create_date,material.weight`). InnerJoins("inner join material on material.id=wms_location_product_amount.product_id"). @@ -113,6 +113,32 @@ } records[k].BaseOperationType = constvar.BaseOperationTypeAdjust } + + productIds = make([]string, 0) + for _, record := range records { + productIds = append(productIds, record.ProductId) + } + + products, err := models.NewMaterialSearch().SetIDs(productIds).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestError, "鏌ヨ浜у搧澶辫触") + return + } + + productMap := models.MaterialMap(products) + + for k, v := range records { + product := productMap[v.ProductId] + if product == nil { + continue + } + + moreUnit := product.MoreUnit + if moreUnit != nil && *moreUnit { + records[k].AmountMoreUnits = service.CreateMoreUnit(v.Amount, product.MoreUnitList) + } + } + util.ResponseFormatListWithPage(c, code.Success, records, int(total), params.Page, params.PageSize) } -- Gitblit v1.8.0