| | |
| | | ctx.Ok() |
| | | return |
| | | } |
| | | first, err := model.NewSalesDetailsSearch().SetPreload(true).SetNumber(number).First() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.DBErr, "查询销售明细出错") |
| | | return |
| | | } |
| | | productInfo := make([]response.SalesDetailsProductInfo, 0) |
| | | amountMap := make(map[string]int64) |
| | | overMap := make(map[string]int64) |
| | | for _, p := range first.Products { |
| | | amountMap[p.Number] = 0 |
| | | overMap[p.Number] = 0 |
| | | var sdpi response.SalesDetailsProductInfo |
| | | sdpi.ProductId = p.Number |
| | | sdpi.ProductName = p.Name |
| | | sdpi.Specs = p.Specs |
| | | sdpi.Unit = p.Unit |
| | | sdpi.Amount = p.Amount |
| | | sdpi.Cost = p.Cost |
| | | sdpi.Price = p.Price |
| | | sdpi.Total = p.Total |
| | | sdpi.Profit = p.Profit |
| | | sdpi.Margin = p.Margin |
| | | productInfo = append(productInfo, sdpi) |
| | | } |
| | | |
| | | client := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | info, err := client.GetProductOrder(ctx.GetCtx(), &product.GetProductOrderRequest{SalesDetailsNumber: number}) |
| | | if err != nil { |
| | |
| | | return |
| | | } |
| | | var result response.Info |
| | | //制造信息 |
| | | var list []response.WorkOrderInfo |
| | | for _, orderInfo := range info.List { |
| | | var wo response.WorkOrderInfo |
| | |
| | | wo.Unit = orderInfo.Unit |
| | | wo.Amount = orderInfo.Amount |
| | | wo.FinishAmount = orderInfo.FinishAmount |
| | | at := amountMap[orderInfo.ProductId] + orderInfo.Amount |
| | | amountMap[orderInfo.ProductId] = at |
| | | fat := overMap[orderInfo.ProductId] + orderInfo.FinishAmount |
| | | overMap[orderInfo.ProductId] = fat |
| | | list = append(list, wo) |
| | | } |
| | | for i := 0; i < len(productInfo); i++ { |
| | | productInfo[i].MakeAmount = amountMap[productInfo[i].ProductId] |
| | | amountMap[productInfo[i].ProductId] = 0 |
| | | productInfo[i].MakeFinishAmount = overMap[productInfo[i].ProductId] |
| | | productInfo[i].FinishAmount = productInfo[i].FinishAmount + overMap[productInfo[i].ProductId] |
| | | overMap[productInfo[i].ProductId] = 0 |
| | | } |
| | | result.MakeInfo = list |
| | | |
| | | //采购信息 |
| | | var purchaseInfo []response.Purchase |
| | | for _, pl := range info.PurchaseList { |
| | | var p response.Purchase |
| | |
| | | p.Unit = pl.Unit |
| | | p.Amount = pl.Amount |
| | | p.FinishAmount = pl.FinishAmount |
| | | at := amountMap[pl.ProductId] + pl.Amount |
| | | amountMap[pl.ProductId] = at |
| | | fat := overMap[pl.ProductId] + pl.FinishAmount |
| | | overMap[pl.ProductId] = fat |
| | | purchaseInfo = append(purchaseInfo, p) |
| | | } |
| | | for i := 0; i < len(productInfo); i++ { |
| | | productInfo[i].PurchaseAmount = amountMap[productInfo[i].ProductId] |
| | | amountMap[productInfo[i].ProductId] = 0 |
| | | productInfo[i].PurchaseFinishAmount = overMap[productInfo[i].ProductId] |
| | | productInfo[i].FinishAmount = productInfo[i].FinishAmount + overMap[productInfo[i].ProductId] |
| | | overMap[productInfo[i].ProductId] = 0 |
| | | } |
| | | result.PurchaseInfo = purchaseInfo |
| | | |
| | | //委外信息 |
| | | var outsourcingList []response.OutsourcingInfo |
| | | for _, outsourcingInfo := range info.OutsourcingList { |
| | | var oi response.OutsourcingInfo |
| | |
| | | oi.Unit = outsourcingInfo.Unit |
| | | oi.Amount = outsourcingInfo.Amount |
| | | oi.FinishAmount = outsourcingInfo.FinishAmount |
| | | at := amountMap[outsourcingInfo.ProductId] + outsourcingInfo.Amount |
| | | amountMap[outsourcingInfo.ProductId] = at |
| | | fat := overMap[outsourcingInfo.ProductId] + outsourcingInfo.FinishAmount |
| | | overMap[outsourcingInfo.ProductId] = fat |
| | | outsourcingList = append(outsourcingList, oi) |
| | | } |
| | | for i := 0; i < len(productInfo); i++ { |
| | | productInfo[i].OutsourcingAmount = amountMap[productInfo[i].ProductId] |
| | | amountMap[productInfo[i].ProductId] = 0 |
| | | productInfo[i].OutsourcingFinishAmount = overMap[productInfo[i].ProductId] |
| | | productInfo[i].FinishAmount = productInfo[i].FinishAmount + overMap[productInfo[i].ProductId] |
| | | overMap[productInfo[i].ProductId] = 0 |
| | | } |
| | | result.OutsourcingInfo = outsourcingList |
| | | result.ProductInfo = productInfo |
| | | ctx.OkWithDetailed(result) |
| | | } |