蛋蛋星球-制度模式
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.

available_green_energy_settlement.go 3.5 KiB

1 month ago
1 month ago
1 month ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package egg_energy
  2. import (
  3. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  4. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  5. egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
  6. "github.com/shopspring/decimal"
  7. )
  8. // CalcPriceIncreaseFormula 计算涨价公式(【用户资金 ÷(用户资金+星球价值)÷ 现行数量】 = 用户获得蛋蛋能量个数)
  9. func CalcPriceIncreaseFormula(userAmountValue string, eggEnergyCoreData *model.EggEnergyCoreData) (err error, resp md.CalcPriceIncreaseFormulaResp) {
  10. userAmount, _ := decimal.NewFromString(userAmountValue) //用户资金
  11. nowPrice, _ := decimal.NewFromString(eggEnergyCoreData.NowPrice) //当前价格
  12. nowEnergyTotalNums, _ := decimal.NewFromString(eggEnergyCoreData.NowEnergyTotalNums) //现行数量
  13. planetTotalValue, _ := decimal.NewFromString(eggEnergyCoreData.PlanetTotalValue) //星球价值
  14. afterPrice := (planetTotalValue.Add(userAmount)).Div(nowEnergyTotalNums).Truncate(8) //涨价后的价格
  15. getEggEnergyNumsValue := userAmount.Div(afterPrice).Truncate(8) //用户得到绿色能量个数
  16. afterEnergyTotalNumsValue := nowEnergyTotalNums.Add(getEggEnergyNumsValue) //变更后-现行数量
  17. afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值
  18. resp.GetEggEnergyNums = getEggEnergyNumsValue.String()
  19. resp.BeforePrice = nowPrice.String()
  20. resp.AfterPrice = afterPrice.String()
  21. resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue
  22. resp.AfterPlanetTotalValue = afterPlanetTotalValue.String()
  23. resp.BeforeEnergyTotalNums = eggEnergyCoreData.NowEnergyTotalNums
  24. resp.AfterEnergyTotalNums = afterEnergyTotalNumsValue.String()
  25. egg_system_rules.FilePutContents("CalcPriceIncreaseFormula", egg_system_rules.SerializeStr(resp))
  26. return
  27. }
  28. // CalcPriceReductionFormula 计算降价公式(【用户需兑换蛋蛋能量数量*{星球价值 ÷(用户需兑换蛋蛋能量数量+现行数量} *(1 - 扣比例50% ~ 23%) = 用户获得钱)
  29. func CalcPriceReductionFormula(userExchangeNumsValue string, eggEnergyCoreData *model.EggEnergyCoreData) (err error, resp md.CalcPriceReductionFormulaResp) {
  30. userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量
  31. nowEnergyTotalNums, _ := decimal.NewFromString(eggEnergyCoreData.NowEnergyTotalNums) //现行数量
  32. planetTotalValue, _ := decimal.NewFromString(eggEnergyCoreData.PlanetTotalValue) //星球价值
  33. afterPrice := planetTotalValue.Div(userExchangeNums.Add(nowEnergyTotalNums)) //降价后的价格
  34. greenEnergyValues := userExchangeNums.Mul(afterPrice) //用户获得的钱
  35. afterEnergyTotalNumsValue := nowEnergyTotalNums.Sub(userExchangeNums) //变更后-现行数量
  36. afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值
  37. resp.GetEggEnergyAmount = greenEnergyValues.Truncate(8).String()
  38. resp.BeforePrice = eggEnergyCoreData.NowPrice
  39. resp.AfterPrice = afterPrice.String()
  40. resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue
  41. resp.AfterPlanetTotalValue = afterPlanetTotalValue.String()
  42. resp.BeforeEnergyTotalNums = eggEnergyCoreData.NowEnergyTotalNums
  43. resp.AfterEnergyTotalNums = afterEnergyTotalNumsValue.String()
  44. egg_system_rules.FilePutContents("CalcPriceReductionFormula", egg_system_rules.SerializeStr(resp))
  45. return
  46. }