From e5a48de88081f1fe0e5250a6e147c392d22acd4b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 19 三月 2024 13:09:38 +0800
Subject: [PATCH] 发货信息字段完善

---
 conf/aps-crm.json            |    2 +-
 service/salesDetails.go      |   17 +++++++++++++++++
 model/salesDetailsProduct.go |    8 ++++++++
 api/v1/salesDetails.go       |   20 +++++++++++++++++---
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/api/v1/salesDetails.go b/api/v1/salesDetails.go
index f6c2931..9e1abda 100644
--- a/api/v1/salesDetails.go
+++ b/api/v1/salesDetails.go
@@ -254,7 +254,7 @@
 	}
 	number := c.Param("number")
 	client := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn)
-	info, err := client.GetInventoryProductInfo(ctx.GetCtx(), &product_inventory.GetInventoryProductInfoRequest{Number: number})
+	info, err := client.GetOrderInputAndOutputInfo(ctx.GetCtx(), &product_inventory.GetOrderInputAndOutputInfoRequest{Number: number})
 	if err != nil {
 		if strings.Contains(err.Error(), "record not found") {
 			ctx.Ok()
@@ -265,11 +265,25 @@
 		return
 	}
 	var list []response.ProductInfo
-	err = structx.AssignTo(info.ProductList, &list)
+	err = structx.AssignTo(info.OutputList, &list)
 	if err != nil {
 		ctx.FailWithMsg(ecode.UnknownErr, "杞崲閿欒")
 		return
 	}
+
+	products, err := salesDetailsService.GetProducts(number)
+	m := make(map[string]*model.Product)
+
+	for _, product := range products {
+		m[product.Number] = product
+	}
+	for _, v := range list {
+		if m[v.Number] == nil {
+			continue
+		}
+		v.OrderAmount = m[v.Number].Amount.String()
+	}
+
 	ctx.OkWithDetailed(list)
 }
 
@@ -419,7 +433,7 @@
 
 	if err != nil {
 		logx.Errorf("product_inventory.OrderProductOutput err:%v, params:%v", err, params)
-		ctx.FailWithMsg(ecode.UnknownErr, "鍙戣揣澶辫触")
+		ctx.FailWithMsg(ecode.UnknownErr, "鍙戣揣澶辫触"+err.Error())
 		return
 	}
 
diff --git a/conf/aps-crm.json b/conf/aps-crm.json
index e9fc5a4..55d67be 100644
--- a/conf/aps-crm.json
+++ b/conf/aps-crm.json
@@ -51,7 +51,7 @@
   "GrpcServiceAddr": {
     "Aps": "192.168.20.119:9091",
     "Admin": "192.168.20.119:50051",
-    "WMS": "192.168.20.119:8006",
+    "WMS": "192.168.20.120:8006",
     "SRM": "192.168.20.119:9093"
   }
 }
diff --git a/model/salesDetailsProduct.go b/model/salesDetailsProduct.go
index abaed56..0884db9 100644
--- a/model/salesDetailsProduct.go
+++ b/model/salesDetailsProduct.go
@@ -42,6 +42,9 @@
 	if len(slf.ProductIds) > 0 {
 		db = db.Where("product_id in (?)", slf.ProductIds)
 	}
+	if slf.SalesDetailsId != 0 {
+		db = db.Where("sales_details_id = ?", slf.SalesDetailsId)
+	}
 
 	return db
 }
@@ -51,6 +54,11 @@
 	return slf
 }
 
+func (slf *SalesDetailsProductSearch) SetSalesDetailsId(id int) *SalesDetailsProductSearch {
+	slf.SalesDetailsId = id
+	return slf
+}
+
 func (slf *SalesDetailsProductSearch) Create(record *SalesDetailsProduct) error {
 	var db = slf.build()
 	return db.Create(record).Error
diff --git a/service/salesDetails.go b/service/salesDetails.go
index d49170c..4e10826 100644
--- a/service/salesDetails.go
+++ b/service/salesDetails.go
@@ -146,3 +146,20 @@
 	orders, err := model.NewDeliveryOrderSearch().SetSalesDetailsID(saleDetailID).FindAll()
 	return orders, err
 }
+
+func (slf SalesDetailsService) GetProducts(saleDetailNumber string) (products []*model.Product, err error) {
+	salesDetails, err := slf.GetSalesDetailsByNumber(saleDetailNumber)
+	if err != nil {
+		return nil, err
+	}
+	// get contact list
+	salesDetailsProducts, err := model.NewSalesDetailsProductSearch().SetSalesDetailsId(salesDetails.Id).FindAll()
+	if err != nil {
+		return
+	}
+	productIDs := make([]uint, 0)
+	for _, v := range salesDetailsProducts {
+		productIDs = append(productIDs, v.ProductId)
+	}
+	return model.NewProductSearch(nil).SetIds(productIDs).FindAll()
+}

--
Gitblit v1.8.0