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 | 28 ++++++++++++++++++++++------ 1 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/v1/product.go b/api/v1/product.go index 8782b69..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() } } @@ -52,13 +60,23 @@ } cli := product.NewProductServiceClient(productServiceConn) - getProductListResponse, err := cli.GetProductList(ctx.GetCtx(), &product.GetProductListRequest{ Page: cast.ToInt32(params.Page), PageSize: cast.ToInt32(params.PageSize), 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, "鍐呴儴閿欒") @@ -70,7 +88,7 @@ return } ctx.OkWithDetailed(response.ListResponse{ - Data: getProductListResponse.List, + Data: productList, Count: getProductListResponse.Total, }) } @@ -92,7 +110,7 @@ productId := c.Query("productNumber") cli := product.NewProductServiceClient(productServiceConn) - getProductInfoResponse, err := cli.GetProductInfo(ctx.GetCtx(), &product.GetProductInfoRequest{ProductId: productId}, nil) + getProductInfoResponse, err := cli.GetProductInfo(ctx.GetCtx(), &product.GetProductInfoRequest{ProductId: productId}) if err != nil { logx.Errorf("GetProductInfo err: %v", err.Error()) ctx.FailWithMsg(ecode.UnknownErr, "鍐呴儴閿欒") @@ -103,7 +121,5 @@ ctx.FailWithMsg(ecode.UnknownErr, "鍐呴儴閿欒") return } - ctx.OkWithDetailed(contextx.Response{ - Data: getProductInfoResponse.Data, - }) + ctx.OkWithDetailed(getProductInfoResponse.Data) } -- Gitblit v1.8.0