From 40e540f8ca398fee68f4520dbebd6db6fe2e164c Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期四, 11 一月 2024 15:28:19 +0800
Subject: [PATCH] 添加销售明细推送到wms

---
 proto/crm_aps/server.go |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/proto/crm_aps/server.go b/proto/crm_aps/server.go
index fd51bc1..b626b02 100644
--- a/proto/crm_aps/server.go
+++ b/proto/crm_aps/server.go
@@ -4,6 +4,7 @@
 	"aps_crm/constvar"
 	"aps_crm/model"
 	"aps_crm/model/grpc_init"
+	"aps_crm/proto/product_inventory"
 	"context"
 	"github.com/shopspring/decimal"
 )
@@ -70,6 +71,41 @@
 			return nil, err
 		}
 
+		//鎺ㄩ�佸埌wms
+		clientName := ""
+		if detail.ClientId > 0 {
+			first, err := model.NewClientSearch(nil).SetId(detail.ClientId).First()
+			if err == nil {
+				clientName = first.Name
+			}
+		}
+		wmsProducts := make([]*product_inventory.InventoryProduct, 0)
+		for _, product := range detail.Products {
+			var p product_inventory.InventoryProduct
+			p.Id = product.Number
+			p.Amount = product.Amount.String()
+			wmsProducts = append(wmsProducts, &p)
+		}
+		clientWms := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn)
+		_, err = clientWms.CreateOperation(ctx, &product_inventory.CreateOperationRequest{
+			Number:      detail.Number,
+			Addressee:   detail.Addressee,
+			Address:     detail.Address,
+			Phone:       detail.Phone,
+			DeliverType: int32(detail.DeliverType),
+			Source:      "CRM",
+			ClientId:    int64(detail.ClientId),
+			ClientName:  clientName,
+			ProductList: wmsProducts,
+		})
+		if err != nil {
+			//鐘舵�佽繕鍘�
+			m["status"] = constvar.WaitConfirmed
+			_ = model.NewSalesDetailsSearch().SetNumber(detail.Number).UpdateByMap(m)
+			return nil, err
+		}
+
+		//鎺ㄩ�佸埌aps
 		products := make([]*SalesDetailsProduct, 0)
 		var total decimal.Decimal
 		for _, product := range detail.Products {
@@ -93,6 +129,9 @@
 			Products:     products,
 		})
 		if err != nil {
+			//鐘舵�佽繕鍘�
+			m["status"] = constvar.WaitConfirmed
+			_ = model.NewSalesDetailsSearch().SetNumber(detail.Number).UpdateByMap(m)
 			return nil, err
 		}
 	}

--
Gitblit v1.8.0