| | |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/proto/product" |
| | | "aps_crm/proto/product_inventory" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "strconv" |
| | | ) |
| | | |
| | | type ProductApi struct{} |
| | |
| | | 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) |
| | | outputMap := make(map[string]int) |
| | | 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 { |
| | |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | //查询发货信息 |
| | | cl := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | operationInfo, err := cl.GetOutputOperationInfo(ctx.GetCtx(), &product_inventory.GetOutputOperationInfoRequest{Number: number}) |
| | | if err != nil { |
| | | logx.Errorf("grpc GetOutputOperationInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | for _, outputProduct := range operationInfo.Products { |
| | | amount, _ := strconv.Atoi(outputProduct.Amount) |
| | | outputMap[outputProduct.Number] = amount |
| | | } |
| | | var result response.Info |
| | | //制造信息 |
| | | var list []response.WorkOrderInfo |
| | | for _, orderInfo := range info.List { |
| | | var wo response.WorkOrderInfo |
| | |
| | | wo.WorkOrderStatus = orderInfo.WorkOrderStatus |
| | | wo.StartTime = orderInfo.StartTime |
| | | wo.EndTime = orderInfo.EndTime |
| | | wo.ProductId = orderInfo.ProductId |
| | | wo.Specs = orderInfo.Specs |
| | | 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.PurchaseName = pl.PurchaseName |
| | | p.PurchaseNumber = pl.PurchaseNumber |
| | | p.SupplierName = pl.SupplierName |
| | | p.ProductId = pl.ProductId |
| | | p.ProductName = pl.ProductName |
| | | p.Specs = pl.Specs |
| | | 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.OutsourcingId = outsourcingInfo.OutsourcingId |
| | | oi.OutsourcingStatus = outsourcingInfo.OutsourcingStatus |
| | | oi.ProductId = outsourcingInfo.ProductId |
| | | oi.ProductName = outsourcingInfo.ProductName |
| | | oi.SupplierName = outsourcingInfo.SupplierName |
| | | oi.StartTime = outsourcingInfo.StartTime |
| | | oi.EndTime = outsourcingInfo.EndTime |
| | | oi.Specs = outsourcingInfo.Specs |
| | | 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 |
| | | } |
| | | |
| | | //发货信息 |
| | | for i := 0; i < len(productInfo); i++ { |
| | | productInfo[i].DeliveryAmount = productInfo[i].DeliveryAmount + outputMap[productInfo[i].ProductId] |
| | | } |
| | | |
| | | result.OutsourcingInfo = outsourcingList |
| | | result.ProductInfo = productInfo |
| | | ctx.OkWithDetailed(result) |
| | | } |