From 530fed8ec225453572d57b15c200ab062c335457 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 01 十一月 2023 19:20:21 +0800
Subject: [PATCH] 公海member_id使用0

---
 api/v1/product.go |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/api/v1/product.go b/api/v1/product.go
index f34eb07..9ade9d2 100644
--- a/api/v1/product.go
+++ b/api/v1/product.go
@@ -2,6 +2,7 @@
 
 import (
 	"aps_crm/conf"
+	"aps_crm/model"
 	"aps_crm/model/request"
 	"aps_crm/model/response"
 	"aps_crm/pkg/contextx"
@@ -10,6 +11,7 @@
 	"aps_crm/proto/product"
 	"fmt"
 	"github.com/gin-gonic/gin"
+	"github.com/shopspring/decimal"
 	"github.com/spf13/cast"
 	"google.golang.org/grpc"
 	"google.golang.org/grpc/credentials/insecure"
@@ -28,6 +30,12 @@
 	if err != nil {
 		logx.Errorf("grpc dial product service error: %v", err.Error())
 		return
+	}
+}
+
+func CloseProductServiceConn() {
+	if productServiceConn != nil {
+		productServiceConn.Close()
 	}
 }
 
@@ -58,6 +66,17 @@
 		ProductNumber: params.ProductNumber,
 		ProductName:   params.ProductName,
 	})
+	rawProductList := getProductListResponse.List
+	productList := make([]model.Product, len(rawProductList))
+
+	for k, v := range rawProductList {
+		productList[k].Number = v.Number
+		productList[k].Name = v.Name
+		productList[k].Price = decimal.NewFromFloat(v.SalePrice).Round(2)
+		productList[k].Amount = decimal.NewFromFloat(1)
+		productList[k].Total = productList[k].Price.Mul(productList[k].Amount).Round(2)
+	}
+
 	if err != nil {
 		logx.Errorf("GetProductList err: %v", err.Error())
 		ctx.FailWithMsg(ecode.UnknownErr, "鍐呴儴閿欒")
@@ -69,7 +88,7 @@
 		return
 	}
 	ctx.OkWithDetailed(response.ListResponse{
-		Data:  getProductListResponse.List,
+		Data:  productList,
 		Count: getProductListResponse.Total,
 	})
 }

--
Gitblit v1.8.0