|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package egg_energy
-
- import (
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
- egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
- "github.com/shopspring/decimal"
- )
-
- // CalcPriceIncreaseFormula 计算涨价公式(【用户资金 ÷(用户资金+星球价值)÷ 现行数量】 = 用户获得蛋蛋能量个数)
- func CalcPriceIncreaseFormula(userAmountValue string, eggEnergyCoreData *model.EggEnergyCoreData) (err error, resp md.CalcPriceIncreaseFormulaResp) {
- userAmount, _ := decimal.NewFromString(userAmountValue) //用户资金
- nowPrice, _ := decimal.NewFromString(eggEnergyCoreData.NowPrice) //当前价格
- nowEnergyTotalNums, _ := decimal.NewFromString(eggEnergyCoreData.NowEnergyTotalNums) //现行数量
- planetTotalValue, _ := decimal.NewFromString(eggEnergyCoreData.PlanetTotalValue) //星球价值
- afterPrice := (planetTotalValue.Add(userAmount)).Div(nowEnergyTotalNums).Truncate(8) //涨价后的价格
- getEggEnergyNumsValue := userAmount.Div(afterPrice).Truncate(8) //用户得到绿色能量个数
- afterEnergyTotalNumsValue := nowEnergyTotalNums.Add(getEggEnergyNumsValue) //变更后-现行数量
- afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值
-
- resp.GetEggEnergyNums = getEggEnergyNumsValue.String()
- resp.BeforePrice = nowPrice.String()
- resp.AfterPrice = afterPrice.String()
- resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue
- resp.AfterPlanetTotalValue = afterPlanetTotalValue.String()
- resp.BeforeEnergyTotalNums = eggEnergyCoreData.NowEnergyTotalNums
- resp.AfterEnergyTotalNums = afterEnergyTotalNumsValue.String()
- egg_system_rules.FilePutContents("CalcPriceIncreaseFormula", egg_system_rules.SerializeStr(resp))
- return
- }
-
- // CalcPriceReductionFormula 计算降价公式(【用户需兑换蛋蛋能量数量*{星球价值 ÷(用户需兑换蛋蛋能量数量+现行数量} *(1 - 扣比例50% ~ 23%) = 用户获得钱)
- func CalcPriceReductionFormula(userExchangeNumsValue string, eggEnergyCoreData *model.EggEnergyCoreData) (err error, resp md.CalcPriceReductionFormulaResp) {
- userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量
- nowEnergyTotalNums, _ := decimal.NewFromString(eggEnergyCoreData.NowEnergyTotalNums) //现行数量
- planetTotalValue, _ := decimal.NewFromString(eggEnergyCoreData.PlanetTotalValue) //星球价值
- afterPrice := planetTotalValue.Div(userExchangeNums.Add(nowEnergyTotalNums)) //降价后的价格
- greenEnergyValues := userExchangeNums.Mul(afterPrice) //用户获得的钱
- afterEnergyTotalNumsValue := nowEnergyTotalNums.Sub(userExchangeNums) //变更后-现行数量
- afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值
-
- resp.GetEggEnergyAmount = greenEnergyValues.Truncate(8).String()
- resp.BeforePrice = eggEnergyCoreData.NowPrice
- resp.AfterPrice = afterPrice.String()
- resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue
- resp.AfterPlanetTotalValue = afterPlanetTotalValue.String()
- resp.BeforeEnergyTotalNums = eggEnergyCoreData.NowEnergyTotalNums
- resp.AfterEnergyTotalNums = afterEnergyTotalNumsValue.String()
-
- egg_system_rules.FilePutContents("CalcPriceReductionFormula", egg_system_rules.SerializeStr(resp))
- return
- }
|