From 18c42494735992c42d63c7858f5fdb31069d0342 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期四, 23 十一月 2023 20:11:31 +0800
Subject: [PATCH] 获取客户列表服务端
---
api/v1/salesDetails.go | 83 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 72 insertions(+), 11 deletions(-)
diff --git a/api/v1/salesDetails.go b/api/v1/salesDetails.go
index d417eca..8b7e98a 100644
--- a/api/v1/salesDetails.go
+++ b/api/v1/salesDetails.go
@@ -4,15 +4,18 @@
"aps_crm/conf"
"aps_crm/constvar"
"aps_crm/model"
+ "aps_crm/model/grpc_init"
"aps_crm/model/request"
"aps_crm/model/response"
"aps_crm/pkg/contextx"
"aps_crm/pkg/ecode"
"aps_crm/pkg/logx"
"aps_crm/pkg/structx"
+ "aps_crm/proto/crm_aps"
"aps_crm/proto/product_inventory"
"aps_crm/utils"
"github.com/gin-gonic/gin"
+ "github.com/shopspring/decimal"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"strconv"
@@ -167,7 +170,12 @@
salesDetailsModel.DeliverType = salesDetails.DeliverType
salesDetailsModel.QuotationId = salesDetails.QuotationId
salesDetailsModel.Status = salesDetails.Status
- salesDetailsModel.Source = salesDetails.Source
+ if salesDetails.Source == "" {
+ salesDetailsModel.Source = "CRM鑷缓"
+ } else {
+ salesDetailsModel.Source = salesDetails.Source
+ }
+ salesDetailsModel.ProjectId = salesDetails.ProjectId
return ecode.OK, salesDetailsModel
}
@@ -281,16 +289,38 @@
ctx.OkWithDetailed(list)
}
-// CreateOperation
+// GetApsProjectList
//
// @Tags SalesDetails
-// @Summary 鍒涘缓浜у搧鍑哄簱淇℃伅
+// @Summary 鑾峰彇aps椤圭洰鍒楄〃
+// @Produce application/json
+// @Success 200 {object} response.Response
+//
+// @Router /api/salesDetails/getApsProjectList [get]
+func (s *SalesDetailsApi) GetApsProjectList(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+ client := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn)
+ projectList, err := client.GetApsProjectList(c, &crm_aps.GetApsProjectListRequest{})
+ if err != nil {
+ ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒: "+err.Error())
+ return
+ }
+ ctx.OkWithDetailed(projectList.List)
+}
+
+// SendSalesDetailsToOtherSystem
+//
+// @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) {
+// @Router /api/salesDetails/sendSalesDetailsToOtherSystem [post]
+func (s *SalesDetailsApi) SendSalesDetailsToOtherSystem(c *gin.Context) {
var params request.SalesDetails
ctx, ok := contextx.NewContext(c, ¶ms)
if !ok {
@@ -298,31 +328,62 @@
}
m := make(map[string]interface{})
m["status"] = params.Status
+ m["project_id"] = params.ProjectId
err := model.NewSalesDetailsSearch().SetNumber(params.Number).UpdateByMap(m)
if err != nil {
ctx.FailWithMsg(ecode.UnknownErr, "鐘舵�佹洿鏂板け璐�")
return
}
- client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
- products := make([]*product_inventory.InventoryProduct, 0)
+ //鎺ㄩ�佸埌wms
+ wmsProducts := 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)
+ wmsProducts = append(wmsProducts, &p)
}
- _, err = client.CreateOperation(ctx.GetCtx(), &product_inventory.CreateOperationRequest{
+ clientWms := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
+ _, err = clientWms.CreateOperation(ctx.GetCtx(), &product_inventory.CreateOperationRequest{
Number: params.Number,
Addressee: params.Addressee,
Address: params.Address,
Phone: params.Phone,
DeliverType: int32(params.DeliverType),
- ProductList: products,
+ ProductList: wmsProducts,
})
if err != nil {
logx.Errorf("CreateOperation err: %v", err.Error())
- ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒")
+ }
+
+ //鎺ㄩ�佸埌aps
+ ApsProducts := make([]*crm_aps.SalesDetailsProduct, 0)
+ var total decimal.Decimal
+ for _, product := range params.Products {
+ var sp crm_aps.SalesDetailsProduct
+ sp.ProductId = product.Number
+ sp.Amount = product.Amount.IntPart()
+ ApsProducts = append(ApsProducts, &sp)
+ total = total.Add(product.Amount)
+ }
+
+ clientAps := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn)
+ _, err = clientAps.SendSalesDetailsToApsProject(c, &crm_aps.SendSalesDetailsToApsProjectRequest{
+ Number: params.Number,
+ ClientName: params.Client.Name,
+ MemberName: params.Member.Username,
+ SignTime: params.SignTime,
+ DeliveryDate: params.DeliveryDate,
+ Source: params.Source,
+ ProductTotal: total.IntPart(),
+ ProjectId: params.ProjectId,
+ Products: ApsProducts,
+ })
+ if err != nil {
+ //鐘舵�佽繕鍘�
+ m["status"] = constvar.WaitConfirmed
+ _ = model.NewSalesDetailsSearch().SetNumber(params.Number).UpdateByMap(m)
+ ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒: "+err.Error())
return
}
ctx.Ok()
--
Gitblit v1.8.0