| | |
| | | "aps_crm/model" |
| | | "aps_crm/model/grpc_init" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/proto/product_inventory" |
| | | "aps_crm/service" |
| | | "context" |
| | | "errors" |
| | |
| | | } |
| | | |
| | | //推送到wms |
| | | clientName := "" |
| | | if detail.ClientId > 0 { |
| | | first, err := model.NewClientSearch(nil).SetId(detail.ClientId).First() |
| | | if err == nil { |
| | | clientName = first.Name |
| | | } |
| | | } |
| | | wmsProducts := make([]*product_inventory.InventoryProduct, 0) |
| | | for _, product := range detail.Products { |
| | | var p product_inventory.InventoryProduct |
| | | p.Id = product.Number |
| | | p.Amount = product.Amount.String() |
| | | wmsProducts = append(wmsProducts, &p) |
| | | } |
| | | clientWms := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | _, err = clientWms.CreateOperation(ctx, &product_inventory.CreateOperationRequest{ |
| | | Number: detail.Number, |
| | | Addressee: detail.Addressee, |
| | | Address: detail.Address, |
| | | Phone: detail.Phone, |
| | | DeliverType: int32(detail.DeliverType), |
| | | Source: "CRM", |
| | | ClientId: int64(detail.ClientId), |
| | | ClientName: clientName, |
| | | ProductList: wmsProducts, |
| | | }) |
| | | if err != nil { |
| | | //状态还原 |
| | | m["status"] = constvar.WaitConfirmed |
| | | _ = model.NewSalesDetailsSearch().SetNumber(detail.Number).UpdateByMap(m) |
| | | return nil, err |
| | | } |
| | | //clientName := "" |
| | | //if detail.ClientId > 0 { |
| | | // first, err := model.NewClientSearch(nil).SetId(detail.ClientId).First() |
| | | // if err == nil { |
| | | // clientName = first.Name |
| | | // } |
| | | //} |
| | | //wmsProducts := make([]*product_inventory.InventoryProduct, 0) |
| | | //for _, product := range detail.Products { |
| | | // var p product_inventory.InventoryProduct |
| | | // p.Id = product.Number |
| | | // p.Amount = product.Amount.String() |
| | | // wmsProducts = append(wmsProducts, &p) |
| | | //} |
| | | //clientWms := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | //_, err = clientWms.CreateOperation(ctx, &product_inventory.CreateOperationRequest{ |
| | | // Number: detail.Number, |
| | | // Addressee: detail.Addressee, |
| | | // Address: detail.Address, |
| | | // Phone: detail.Phone, |
| | | // DeliverType: int32(detail.DeliverType), |
| | | // Source: "CRM", |
| | | // ClientId: int64(detail.ClientId), |
| | | // ClientName: clientName, |
| | | // ProductList: wmsProducts, |
| | | //}) |
| | | //if err != nil { |
| | | // //状态还原 |
| | | // m["status"] = constvar.WaitConfirmed |
| | | // _ = model.NewSalesDetailsSearch().SetNumber(detail.Number).UpdateByMap(m) |
| | | // return nil, err |
| | | //} |
| | | |
| | | //推送到aps |
| | | products := make([]*SalesDetailsProduct, 0) |
| | |
| | | } |
| | | |
| | | salesDetail.Status = status |
| | | err = model.NewSalesDetailsSearch().Update(salesDetail) |
| | | err = model.NewSalesDetailsSearch().SetId(salesDetail.Id).Update(salesDetail) |
| | | if err != nil { |
| | | return nil, errors.New("更改CRM销售明细失败") |
| | | } |
| | |
| | | return &UpdateSalesDetailResponse{}, nil |
| | | } |
| | | |
| | | func (s *Server) RemoveSalesDetail(ctx context.Context, req *RemoveSalesDetailRequest) (*RemoveSalesDetailRequest, error) { |
| | | func (s *Server) RemoveSalesDetail(ctx context.Context, req *RemoveSalesDetailRequest) (*RemoveSalesDetailResponse, error) { |
| | | if req.Number == "" { |
| | | return nil, errors.New("销售明细编号为空") |
| | | } |
| | |
| | | return nil, errors.New("销售明细删除失败") |
| | | } |
| | | |
| | | return &RemoveSalesDetailRequest{}, nil |
| | | return &RemoveSalesDetailResponse{}, nil |
| | | } |
| | | |
| | | func (s *Server) GetCrmSalesDetailsProductInfo(ctx context.Context, req *GetCrmSalesDetailsProductInfoRequest) (*GetCrmSalesDetailsProductInfoResponse, error) { |
| | | if req.SalesDetailsNumber == "" { |
| | | return nil, errors.New("销售明细编号为空") |
| | | } |
| | | first, err := model.NewSalesDetailsSearch().SetPreload(true).SetNumber(req.SalesDetailsNumber).First() |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | list := make([]*CrmSalesDetailsProductInfo, 0) |
| | | for _, product := range first.Products { |
| | | var csp CrmSalesDetailsProductInfo |
| | | csp.ProductId = product.Number |
| | | csp.ProductName = product.Name |
| | | csp.Specs = product.Specs |
| | | csp.Unit = product.Unit |
| | | csp.Amount = product.Amount.IntPart() |
| | | csp.Cost = product.Cost |
| | | csp.Price = product.Price.IntPart() |
| | | csp.Total = product.Total.IntPart() |
| | | csp.Profit = product.Profit |
| | | csp.Margin = product.Margin |
| | | list = append(list, &csp) |
| | | } |
| | | resp := new(GetCrmSalesDetailsProductInfoResponse) |
| | | resp.List = list |
| | | return resp, nil |
| | | } |