智慧食堂-队列消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

129 lines
2.7 KiB

  1. package svc
  2. import (
  3. "applet/app/utils"
  4. "applet/supply/db/model"
  5. "applet/supply/md"
  6. )
  7. func GetMinProfitRate(skus []*model.MallSku) float64 {
  8. var (
  9. minProfit float64
  10. )
  11. for i, sku := range skus {
  12. priceF := utils.AnyToFloat64(sku.Price)
  13. linePriceF := utils.AnyToFloat64(sku.LinePrice)
  14. profitF := (linePriceF - priceF) / priceF
  15. if i == 0 {
  16. minProfit = profitF
  17. } else {
  18. if profitF < minProfit {
  19. minProfit = profitF
  20. }
  21. }
  22. }
  23. return minProfit
  24. }
  25. func GetMinPrice(skus []*model.MallSku) float64 {
  26. var (
  27. minPrice float64
  28. )
  29. for i, sku := range skus {
  30. priceF := utils.AnyToFloat64(sku.Price)
  31. if i == 0 {
  32. minPrice = priceF
  33. } else {
  34. if priceF < minPrice {
  35. minPrice = priceF
  36. }
  37. }
  38. }
  39. return minPrice
  40. }
  41. func GetGoodsRangeData(skus []model.MallSku) md.GoodsRangeData {
  42. var (
  43. result md.GoodsRangeData
  44. minPrice float64
  45. maxPrice float64
  46. minLinePrice float64
  47. maxLinePrice float64
  48. minProfit float64
  49. maxProfit float64
  50. minWeight float64
  51. maxWeight float64
  52. )
  53. for i, sku := range skus {
  54. priceF := utils.AnyToFloat64(sku.Price)
  55. linePriceF := utils.AnyToFloat64(sku.LinePrice)
  56. weightF := utils.AnyToFloat64(sku.Weight)
  57. profitF := (linePriceF - priceF) / priceF * 100 // 利润空间
  58. if i == 0 {
  59. minPrice = priceF
  60. maxPrice = minPrice
  61. minLinePrice = linePriceF
  62. maxLinePrice = minLinePrice
  63. minProfit = profitF
  64. maxProfit = minProfit
  65. minWeight = weightF
  66. maxWeight = minWeight
  67. } else {
  68. if priceF < minPrice {
  69. minPrice = priceF
  70. }
  71. if priceF > maxPrice {
  72. maxPrice = priceF
  73. }
  74. if linePriceF < minLinePrice {
  75. minLinePrice = linePriceF
  76. }
  77. if linePriceF > maxLinePrice {
  78. maxLinePrice = linePriceF
  79. }
  80. if weightF < minWeight {
  81. minWeight = weightF
  82. }
  83. if weightF > maxWeight {
  84. maxWeight = weightF
  85. }
  86. if profitF < minProfit {
  87. minProfit = profitF
  88. }
  89. if profitF > maxProfit {
  90. maxProfit = profitF
  91. }
  92. }
  93. }
  94. if minPrice == maxPrice {
  95. result.PriceRange = utils.AnyToString(minPrice)
  96. } else {
  97. result.PriceRange = utils.AnyToString(minPrice) + "-" + utils.AnyToString(maxPrice)
  98. }
  99. if minLinePrice == maxLinePrice {
  100. result.LinePriceRange = utils.AnyToString(minLinePrice)
  101. } else {
  102. result.LinePriceRange = utils.AnyToString(minLinePrice) + "-" + utils.AnyToString(maxLinePrice)
  103. }
  104. if minProfit == maxProfit {
  105. result.ProfitRange = utils.AnyToString(minProfit) + "%"
  106. } else {
  107. result.ProfitRange = utils.AnyToString(minProfit) + "%-" + utils.AnyToString(maxProfit) + "%"
  108. }
  109. if minWeight == maxWeight {
  110. result.WeightRange = utils.AnyToString(minWeight)
  111. } else {
  112. result.WeightRange = utils.AnyToString(minWeight) + "-" + utils.AnyToString(maxWeight)
  113. }
  114. return result
  115. }