| | |
| | | "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{} |
| | |
| | | return |
| | | } |
| | | |
| | | if params.QuotationNumber != "" { |
| | | find, err := model.NewQuotationSearch(nil).SetNumber(params.QuotationNumber).Find() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "报价单信息查询失败") |
| | | return |
| | | } |
| | | products := find.Products |
| | | ctx.OkWithDetailed(response.ListResponse{ |
| | | Data: products, |
| | | Count: int64(len(products)), |
| | | }) |
| | | return |
| | | } |
| | | cli := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | getProductListResponse, err := cli.GetProductList(ctx.GetCtx(), &product.GetProductListRequest{ |
| | | Page: cast.ToInt32(params.Page), |
| | |
| | | ProductNumber: params.ProductNumber, |
| | | ProductName: params.ProductName, |
| | | }) |
| | | if err != nil { |
| | | logx.Errorf("grpc GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | if getProductListResponse.Code != 0 { |
| | | logx.Errorf("grpc GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | rawProductList := getProductListResponse.List |
| | | productList := make([]model.Product, len(rawProductList)) |
| | | |
| | |
| | | productList[k].Amount = decimal.NewFromFloat(1) |
| | | productList[k].Total = productList[k].Price.Mul(productList[k].Amount).Round(2) |
| | | productList[k].Unit = v.Unit |
| | | productList[k].Type = v.Type |
| | | productList[k].Specs = v.Specs |
| | | productList[k].Price = decimal.NewFromFloat(v.SalePrice) |
| | | } |
| | | |
| | | if err != nil { |
| | | logx.Errorf("GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | if getProductListResponse.Code != 0 { |
| | | logx.Errorf("GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(response.ListResponse{ |
| | | Data: productList, |
| | | Count: getProductListResponse.Total, |
| | |
| | | |
| | | getProductInfoResponse, err := cli.GetProductInfo(ctx.GetCtx(), &product.GetProductInfoRequest{ProductId: productId}) |
| | | if err != nil { |
| | | logx.Errorf("GetProductInfo err: %v", err.Error()) |
| | | logx.Errorf(" grpc GetProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | if getProductInfoResponse.Code != 0 { |
| | | logx.Errorf("GetProductInfo err: %v", err.Error()) |
| | | logx.Errorf("grpc GetProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | |
| | | // @Summary 获取产品订单信息 |
| | | // @Produce application/json |
| | | // @Param number path string true "明细编码" |
| | | // @Success 200 {object} contextx.Response{data=[]product.WorkOrderInfo} "成功" |
| | | // @Success 200 {object} contextx.Response{data=response.Info} "成功" |
| | | // |
| | | // @Router /api/product/getProductOrderInfo/{number} [get] |
| | | func (ci *ProductApi) GetProductOrderInfo(c *gin.Context) { |
| | |
| | | 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 { |
| | | logx.Errorf("GetProductOrder err: %v", err.Error()) |
| | | logx.Errorf("grpc GetProductOrder err: %v", err.Error()) |
| | | 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) |
| | | } |
| | | ctx.OkWithDetailed(list) |
| | | 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.Amount = pl.Amount |
| | | p.Status = pl.Status |
| | | 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) |
| | | } |