| | |
| | | "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" |
| | |
| | | } |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // GetApsProjectList |
| | | // |
| | | // @Tags SalesDetails |
| | | // @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) |
| | | } |
| | | |
| | | // SendSalesDetailsToApsProject |
| | | // |
| | | // @Tags SalesDetails |
| | | // @Summary 推送销售明细信息到aps项目模块 |
| | | // @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) { |
| | | var params request.SalesDetails |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | 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 |
| | | } |
| | | |
| | | products := 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) |
| | | total = total.Add(product.Amount) |
| | | } |
| | | |
| | | client := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | _, err = client.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: products, |
| | | }) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "grpc调用错误: "+err.Error()) |
| | | return |
| | | } |
| | | ctx.Ok() |
| | | } |