|
|
@@ -455,17 +455,6 @@ func ExchangeEnergy(c *gin.Context) { |
|
|
|
if cb != nil { |
|
|
|
defer cb() // 释放锁 |
|
|
|
} |
|
|
|
energyAmount, err := decimal.NewFromString(req.EnergyAmount) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
nowPrice, err := decimal.NewFromString(eggEnergyCoreData.NowPrice) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
amount, _ := energyAmount.Mul(nowPrice).Float64() |
|
|
|
|
|
|
|
// 3. 获取用户蛋蛋能量余额 |
|
|
|
eggEnergyAmount, err := rule.GetUserCoinAmount(session, coinID, user.Id) |
|
|
@@ -481,7 +470,7 @@ func ExchangeEnergy(c *gin.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 调用降价公式 |
|
|
|
err, calcPriceReductionFormula := egg_energy.CalcPriceReductionFormula(req.EnergyAmount, eggEnergyCoreData) |
|
|
|
err, calcPriceReductionFormula := egg_energy.CalcPriceReductionFormula(req.EnergyAmount, eggEnergyCoreData, utils.IntToStr(user.Level), *setting) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
@@ -489,8 +478,8 @@ func ExchangeEnergy(c *gin.Context) { |
|
|
|
|
|
|
|
// 6. 更改动态数据 |
|
|
|
err = egg_energy.DealAvailableEggEnergyCoin(session, int(enum.EggEnergyExchangeAccountBalance), eggEnergyCoreData, md3.DealAvailableEggEnergyCoinReq{ |
|
|
|
Amount: calcPriceReductionFormula.GetEggEnergyAmount, |
|
|
|
AmountFee: "", |
|
|
|
Amount: req.EnergyAmount, |
|
|
|
AmountFee: calcPriceReductionFormula.AmountFee, |
|
|
|
BeforePrice: calcPriceReductionFormula.BeforePrice, |
|
|
|
AfterPrice: calcPriceReductionFormula.AfterPrice, |
|
|
|
BeforePlanetTotalValue: calcPriceReductionFormula.BeforePlanetTotalValue, |
|
|
@@ -526,7 +515,7 @@ func ExchangeEnergy(c *gin.Context) { |
|
|
|
Kind: int(enum.EggEnergyExchangeAccountBalance), |
|
|
|
Title: enum.EggEnergyExchangeAccountBalance.String(), |
|
|
|
Uid: user.Id, |
|
|
|
Amount: amount, |
|
|
|
Amount: utils.StrToFloat64(calcPriceReductionFormula.GetEggEnergyAmount), |
|
|
|
} |
|
|
|
err = rule.DealUserWallet(session, dealUserWalletReq) |
|
|
|
if err != nil { |
|
|
|