|
|
@@ -115,8 +115,18 @@ func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string |
|
|
|
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 |
|
|
|
originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 |
|
|
|
nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 |
|
|
|
originalQuantityFunds, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalFunds) //原始资金 |
|
|
|
afterPrice := originalQuantityFunds.Div(userExchangeNums.Add(originalQuantityNums)) //降价后的价格 |
|
|
|
var priceSettingStruct *md2.PriceSettingStruct |
|
|
|
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.PriceSetting), &priceSettingStruct) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
priceHigherThanValue, _ := decimal.NewFromString(priceSettingStruct.PriceHigherThanValue) |
|
|
|
if nowPrice.Cmp(priceHigherThanValue) == 1 { |
|
|
|
err = errors.New("当前价格异常,请稍后重新兑换") |
|
|
|
return |
|
|
|
} |
|
|
|
originalQuantityFunds, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalFunds) //原始资金 |
|
|
|
afterPrice := originalQuantityFunds.Div(userExchangeNums.Add(originalQuantityNums)) //降价后的价格 |
|
|
|
|
|
|
|
greenEnergyValues := userExchangeNums.Mul(afterPrice) //绿色能量个数 |
|
|
|
greenEnergyFeeValues := greenEnergyValues.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //绿色能量个数扣除手续费价值 |
|
|
|