From 9e36cf6dfbd916a1a5fd79d628887972a90d9b5e Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 07 十一月 2023 14:32:32 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/crm

---
 api/v1/salesDetails.go |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 117 insertions(+), 0 deletions(-)

diff --git a/api/v1/salesDetails.go b/api/v1/salesDetails.go
index 1a1e37d..4ad4730 100644
--- a/api/v1/salesDetails.go
+++ b/api/v1/salesDetails.go
@@ -1,14 +1,19 @@
 package v1
 
 import (
+	"aps_crm/conf"
 	"aps_crm/constvar"
 	"aps_crm/model"
 	"aps_crm/model/request"
 	"aps_crm/model/response"
 	"aps_crm/pkg/contextx"
 	"aps_crm/pkg/ecode"
+	"aps_crm/pkg/logx"
+	"aps_crm/proto/product_inventory"
 	"aps_crm/utils"
 	"github.com/gin-gonic/gin"
+	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials/insecure"
 	"strconv"
 )
 
@@ -160,6 +165,8 @@
 	salesDetailsModel.CodeStandID = salesDetails.CodeStandID
 	salesDetailsModel.DeliverType = salesDetails.DeliverType
 	salesDetailsModel.QuotationId = salesDetails.QuotationId
+	salesDetailsModel.Status = salesDetails.Status
+	salesDetailsModel.Source = salesDetails.Source
 
 	return ecode.OK, salesDetailsModel
 }
@@ -196,3 +203,113 @@
 		Count: int(total),
 	})
 }
+
+// UpdateStatus
+//
+//	@Tags		SalesDetails
+//	@Summary	鏇存柊閿�鍞槑缁嗙姸鎬�
+//	@Produce	application/json
+//	@Param		object	body		request.UpdateSalesDetails	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/salesDetails/update [post]
+func (s *SalesDetailsApi) UpdateStatus(c *gin.Context) {
+	var params request.UpdateSalesDetails
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	m := make(map[string]interface{})
+	m["status"] = params.SalesDetails.Status
+	err := model.NewSalesDetailsSearch().SetId(params.Id).UpdateByMap(m)
+	if err != nil {
+		ctx.FailWithMsg(ecode.UnknownErr, "鏇存柊澶辫触")
+		return
+	}
+
+	ctx.Ok()
+}
+
+var (
+	ProductInventoryServiceConn *grpc.ClientConn
+)
+
+func InitProductInventoryServiceConn() {
+	var err error
+	ProductInventoryServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.WMS, grpc.WithTransportCredentials(insecure.NewCredentials()))
+	if err != nil {
+		logx.Errorf("grpc dial product service error: %v", err.Error())
+		return
+	}
+}
+
+func CloseProductInventoryServiceConn() {
+	if ProductInventoryServiceConn != nil {
+		ProductInventoryServiceConn.Close()
+	}
+}
+
+// GetProductInventoryInfo
+//
+// @Tags		SalesDetails
+// @Summary	鑾峰彇浜у搧搴撳瓨淇℃伅
+// @Produce	application/json
+// @Param		number	path		string	true	"鏄庣粏缂栫爜"
+// @Success	200	{object}	response.ListResponse
+//
+//	@Router		/api/salesDetails/getProductInventoryInfo/{number} [get]
+func (s *SalesDetailsApi) GetProductInventoryInfo(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+	number := c.Param("number")
+	client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
+	info, err := client.GetInventoryProductInfo(ctx.GetCtx(), &product_inventory.GetInventoryProductInfoRequest{Number: number})
+	if err != nil {
+		logx.Errorf("GetProductInfo err: %v", err.Error())
+		ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒")
+		return
+	}
+	ctx.OkWithDetailed(info.ProductList)
+}
+
+// CreateOperation
+//
+// @Tags		SalesDetails
+// @Summary	鍒涘缓浜у搧鍑哄簱淇℃伅
+// @Produce	application/json
+// @Param		object	body		request.SalesDetails	true	"鏌ヨ鍙傛暟"
+// @Success	200	{object}	response.ListResponse
+//
+//	@Router		/api/salesDetails/createOperation [post]
+func (s *SalesDetailsApi) CreateOperation(c *gin.Context) {
+	var params request.SalesDetails
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
+	products := make([]*product_inventory.InventoryProduct, 0)
+	for _, product := range params.Products {
+		var p product_inventory.InventoryProduct
+		p.Id = product.Number
+		p.Amount = product.Amount.String()
+		products = append(products, &p)
+	}
+	_, err := client.CreateOperation(ctx.GetCtx(), &product_inventory.CreateOperationRequest{
+		Number:      params.Number,
+		Addressee:   params.Addressee,
+		Address:     params.Address,
+		Phone:       params.Phone,
+		DeliverType: int32(params.DeliverType),
+		ProductList: products,
+	})
+	if err != nil {
+		logx.Errorf("CreateOperation err: %v", err.Error())
+		ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒")
+		return
+	}
+	ctx.Ok()
+}

--
Gitblit v1.8.0