liujiandao
2023-11-23 42ca2293072e5eb011e655c9cc8fd9bf0ba376f1
api/v1/salesDetails.go
@@ -289,53 +289,6 @@
   ctx.OkWithDetailed(list)
}
// 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
   }
   m := make(map[string]interface{})
   m["status"] = params.Status
   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)
   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()
}
// GetApsProjectList
//
// @Tags      SalesDetails
@@ -358,16 +311,16 @@
   ctx.OkWithDetailed(projectList.List)
}
// SendSalesDetailsToApsProject
// SendSalesDetailsToOtherSystem
//
// @Tags      SalesDetails
// @Summary     推送销售明细信息到aps项目模块
// @Summary     推送销售明细信息到其他系统
// @Produce   application/json
// @Param      object   body      request.SalesDetails   true   "查询参数"
// @Success   200   {object}   response.ListResponse
//
//   @Router      /api/salesDetails/sendSalesDetailsToApsProject [post]
func (s *SalesDetailsApi) SendSalesDetailsToApsProject(c *gin.Context) {
//   @Router      /api/salesDetails/sendSalesDetailsToOtherSystem [post]
func (s *SalesDetailsApi) SendSalesDetailsToOtherSystem(c *gin.Context) {
   var params request.SalesDetails
   ctx, ok := contextx.NewContext(c, &params)
   if !ok {
@@ -381,18 +334,40 @@
      return
   }
   products := make([]*crm_aps.SalesDetailsProduct, 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()
      wmsProducts = append(wmsProducts, &p)
   }
   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: wmsProducts,
   })
   if err != nil {
      logx.Errorf("CreateOperation err: %v", err.Error())
   }
   //推送到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()
      products = append(products, &sp)
      ApsProducts = append(ApsProducts, &sp)
      total = total.Add(product.Amount)
   }
   client := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn)
   _, err = client.SendSalesDetailsToApsProject(c, &crm_aps.SendSalesDetailsToApsProjectRequest{
   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,
@@ -401,9 +376,12 @@
      Source:       params.Source,
      ProductTotal: total.IntPart(),
      ProjectId:    params.ProjectId,
      Products:     products,
      Products:     ApsProducts,
   })
   if err != nil {
      //状态还原
      m["status"] = constvar.WaitConfirmed
      _ = model.NewSalesDetailsSearch().SetNumber(params.Number).UpdateByMap(m)
      ctx.FailWithMsg(ecode.UnknownErr, "grpc调用错误: "+err.Error())
      return
   }