| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/conf" |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/model/grpc_init" |
| | |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | | "strconv" |
| | | "strings" |
| | | ) |
| | | |
| | | type SalesDetailsApi struct{} |
| | |
| | | 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 |
| | |
| | | return |
| | | } |
| | | number := c.Param("number") |
| | | client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn) |
| | | client := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | info, err := client.GetInventoryProductInfo(ctx.GetCtx(), &product_inventory.GetInventoryProductInfoRequest{Number: number}) |
| | | if err != nil { |
| | | if strings.Contains(err.Error(), "record not found") { |
| | | ctx.Ok() |
| | | return |
| | | } |
| | | logx.Errorf("GetProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "grpc调用错误") |
| | | return |
| | |
| | | if !ok { |
| | | return |
| | | } |
| | | clientName := "" |
| | | if params.ClientId > 0 { |
| | | first, err := model.NewClientSearch(nil).SetId(params.ClientId).First() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "客户信息查询失败") |
| | | return |
| | | } |
| | | clientName = first.Name |
| | | } |
| | | m := make(map[string]interface{}) |
| | | m["status"] = params.Status |
| | | m["project_id"] = params.ProjectId |
| | |
| | | p.Amount = product.Amount.String() |
| | | wmsProducts = append(wmsProducts, &p) |
| | | } |
| | | clientWms := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn) |
| | | clientWms := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | _, err = clientWms.CreateOperation(ctx.GetCtx(), &product_inventory.CreateOperationRequest{ |
| | | Number: params.Number, |
| | | Addressee: params.Addressee, |
| | |
| | | Phone: params.Phone, |
| | | DeliverType: int32(params.DeliverType), |
| | | Source: "CRM", |
| | | ClientId: int64(params.ClientId), |
| | | ClientName: clientName, |
| | | ProductList: wmsProducts, |
| | | }) |
| | | if err != nil { |