| | |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/pkg/structx" |
| | | "aps_crm/proto/crm_aps" |
| | | "aps_crm/proto/crm_srm" |
| | | "aps_crm/proto/product_inventory" |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | |
| | | return |
| | | } |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // GetSalesDetailsProductInfo |
| | | // |
| | | // @Tags SalesDetails |
| | | // @Summary 获取销售明细产品信息 |
| | | // @Produce application/json |
| | | // @Param number path string true "明细编码" |
| | | // @Success 200 {object} response.ListResponse |
| | | // |
| | | // @Router /api/salesDetails/getSalesDetailsProductInfo/{number} [get] |
| | | func (s *SalesDetailsApi) GetSalesDetailsProductInfo(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | number := c.Param("number") |
| | | first, err := model.NewSalesDetailsSearch().SetPreload(true).SetNumber(number).First() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.DBErr, "查询销售明细出错") |
| | | return |
| | | } |
| | | resp := make([]response.SalesDetailsProductInfo, 0) |
| | | amountMap := make(map[string]int64) |
| | | overMap := make(map[string]int64) |
| | | for _, product := range first.Products { |
| | | amountMap[product.Number] = 0 |
| | | overMap[product.Number] = 0 |
| | | var sdpi response.SalesDetailsProductInfo |
| | | sdpi.ProductId = product.Number |
| | | sdpi.ProductName = product.Name |
| | | sdpi.Specs = product.Specs |
| | | sdpi.Unit = product.Unit |
| | | sdpi.Amount = product.Amount |
| | | sdpi.Cost = product.Cost |
| | | sdpi.Price = product.Price |
| | | sdpi.Total = product.Total |
| | | sdpi.Profit = product.Profit |
| | | sdpi.Margin = product.Margin |
| | | resp = append(resp, sdpi) |
| | | } |
| | | srmClient := crm_srm.NewCrmAndSrmServiceClient(grpc_init.CrmSrmGrpcServiceConn) |
| | | info, err := srmClient.CrmGetPurchaseInfo(c, &crm_srm.CrmGetPurchaseInfoRequest{SalesDetailsNumber: number}) |
| | | if err != nil { |
| | | logx.Errorf("grpc CrmGetPurchaseInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | //采购数量 |
| | | for _, purchaseInfo := range info.Info { |
| | | amount := amountMap[purchaseInfo.ProductId] |
| | | amount += purchaseInfo.Amount |
| | | amountMap[purchaseInfo.ProductId] = amount |
| | | over := overMap[purchaseInfo.ProductId] |
| | | over += purchaseInfo.FinishAmount |
| | | overMap[purchaseInfo.ProductId] = over |
| | | } |
| | | for i := 0; i < len(resp); i++ { |
| | | resp[i].PurchaseAmount = amountMap[resp[i].ProductId] |
| | | amountMap[resp[i].ProductId] = 0 |
| | | resp[i].PurchaseFinishAmount = overMap[resp[i].ProductId] |
| | | resp[i].FinishAmount = resp[i].FinishAmount + overMap[resp[i].ProductId] |
| | | overMap[resp[i].ProductId] = 0 |
| | | } |
| | | |
| | | apsClient := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | productInfo, err := apsClient.CrmGetMakeAndOutsourcingProductInfo(c, &crm_aps.CrmGetMakeAndOutsourcingProductInfoRequest{SalesDetailsNumber: number}) |
| | | if err != nil { |
| | | logx.Errorf("grpc CrmGetMakeAndOutsourcingProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | //制造数量 |
| | | for _, makeInfo := range productInfo.Info { |
| | | if makeInfo.Type == 2 { |
| | | amount := amountMap[makeInfo.ProductId] |
| | | amount += makeInfo.Amount |
| | | amountMap[makeInfo.ProductId] = amount |
| | | over := overMap[makeInfo.ProductId] |
| | | over += makeInfo.FinishAmount |
| | | overMap[makeInfo.ProductId] = over |
| | | } |
| | | } |
| | | for i := 0; i < len(resp); i++ { |
| | | resp[i].MakeAmount = amountMap[resp[i].ProductId] |
| | | amountMap[resp[i].ProductId] = 0 |
| | | resp[i].MakeFinishAmount = overMap[resp[i].ProductId] |
| | | resp[i].FinishAmount = resp[i].FinishAmount + overMap[resp[i].ProductId] |
| | | overMap[resp[i].ProductId] = 0 |
| | | } |
| | | //委外数量 |
| | | for _, outsourcingInfo := range productInfo.Info { |
| | | if outsourcingInfo.Type == 3 { |
| | | amount := amountMap[outsourcingInfo.ProductId] |
| | | amount += outsourcingInfo.Amount |
| | | amountMap[outsourcingInfo.ProductId] = amount |
| | | over := overMap[outsourcingInfo.ProductId] |
| | | over += outsourcingInfo.FinishAmount |
| | | overMap[outsourcingInfo.ProductId] = over |
| | | } |
| | | } |
| | | for i := 0; i < len(resp); i++ { |
| | | resp[i].OutsourcingAmount = amountMap[resp[i].ProductId] |
| | | amountMap[resp[i].ProductId] = 0 |
| | | resp[i].OutsourcingFinishAmount = overMap[resp[i].ProductId] |
| | | resp[i].FinishAmount = resp[i].FinishAmount + overMap[resp[i].ProductId] |
| | | overMap[resp[i].ProductId] = 0 |
| | | } |
| | | ctx.OkWithDetailed(resp) |
| | | } |