package svc import ( "applet/app/utils" "applet/supply/db/model" "applet/supply/md" ) func GetMinProfitRate(skus []*model.MallSku) float64 { var ( minProfit float64 ) for i, sku := range skus { priceF := utils.AnyToFloat64(sku.Price) linePriceF := utils.AnyToFloat64(sku.LinePrice) profitF := (linePriceF - priceF) / priceF if i == 0 { minProfit = profitF } else { if profitF < minProfit { minProfit = profitF } } } return minProfit } func GetMinPrice(skus []*model.MallSku) float64 { var ( minPrice float64 ) for i, sku := range skus { priceF := utils.AnyToFloat64(sku.Price) if i == 0 { minPrice = priceF } else { if priceF < minPrice { minPrice = priceF } } } return minPrice } func GetGoodsRangeData(skus []model.MallSku) md.GoodsRangeData { var ( result md.GoodsRangeData minPrice float64 maxPrice float64 minLinePrice float64 maxLinePrice float64 minProfit float64 maxProfit float64 minWeight float64 maxWeight float64 ) for i, sku := range skus { priceF := utils.AnyToFloat64(sku.Price) linePriceF := utils.AnyToFloat64(sku.LinePrice) weightF := utils.AnyToFloat64(sku.Weight) profitF := (linePriceF - priceF) / priceF * 100 // 利润空间 if i == 0 { minPrice = priceF maxPrice = minPrice minLinePrice = linePriceF maxLinePrice = minLinePrice minProfit = profitF maxProfit = minProfit minWeight = weightF maxWeight = minWeight } else { if priceF < minPrice { minPrice = priceF } if priceF > maxPrice { maxPrice = priceF } if linePriceF < minLinePrice { minLinePrice = linePriceF } if linePriceF > maxLinePrice { maxLinePrice = linePriceF } if weightF < minWeight { minWeight = weightF } if weightF > maxWeight { maxWeight = weightF } if profitF < minProfit { minProfit = profitF } if profitF > maxProfit { maxProfit = profitF } } } if minPrice == maxPrice { result.PriceRange = utils.AnyToString(minPrice) } else { result.PriceRange = utils.AnyToString(minPrice) + "-" + utils.AnyToString(maxPrice) } if minLinePrice == maxLinePrice { result.LinePriceRange = utils.AnyToString(minLinePrice) } else { result.LinePriceRange = utils.AnyToString(minLinePrice) + "-" + utils.AnyToString(maxLinePrice) } if minProfit == maxProfit { result.ProfitRange = utils.AnyToString(minProfit) + "%" } else { result.ProfitRange = utils.AnyToString(minProfit) + "%-" + utils.AnyToString(maxProfit) + "%" } if minWeight == maxWeight { result.WeightRange = utils.AnyToString(minWeight) } else { result.WeightRange = utils.AnyToString(minWeight) + "-" + utils.AnyToString(maxWeight) } return result }