@@ -66,7 +66,7 @@ func AutoAdjustPrice(engine *xorm.Engine) (err error) { | |||||
nowPriceValue, _ := decimal.NewFromString(eggEnergyCoreData.NowPrice) | nowPriceValue, _ := decimal.NewFromString(eggEnergyCoreData.NowPrice) | ||||
if nowPriceValue.GreaterThan(priceHigherThanValue) { | if nowPriceValue.GreaterThan(priceHigherThanValue) { | ||||
//当价格涨到设置某个价格时,自动执行 市商数量 兑换 市商资金 (降价公式) | //当价格涨到设置某个价格时,自动执行 市商数量 兑换 市商资金 (降价公式) | ||||
err1, resp := CalcPriceReductionFormula(marketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue.String(), eggEnergyCoreData) | |||||
err1, resp := CalcPriceReductionFormula(marketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue.String(), eggEnergyCoreData, "", *eggEnergyBasicSetting) | |||||
if err1 != nil { | if err1 != nil { | ||||
fmt.Println("err1111:::", err1) | fmt.Println("err1111:::", err1) | ||||
_ = session.Rollback() | _ = session.Rollback() | ||||
@@ -75,8 +75,9 @@ func AutoAdjustPrice(engine *xorm.Engine) (err error) { | |||||
// 市商数量 减少、市商资金 增加 | // 市商数量 减少、市商资金 增加 | ||||
err = DealAvailableEggEnergyCoin(session, int(enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds), eggEnergyCoreData, md2.DealAvailableEggEnergyCoinReq{ | err = DealAvailableEggEnergyCoin(session, int(enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds), eggEnergyCoreData, md2.DealAvailableEggEnergyCoinReq{ | ||||
Amount: resp.GetEggEnergyAmount, | |||||
AmountFee: marketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue.String(), | |||||
Amount: marketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue.String(), | |||||
AmountValue: resp.GetEggEnergyAmount, | |||||
AmountFee: resp.AmountFee, | |||||
BeforePrice: resp.BeforePrice, | BeforePrice: resp.BeforePrice, | ||||
AfterPrice: resp.AfterPrice, | AfterPrice: resp.AfterPrice, | ||||
BeforePlanetTotalValue: resp.BeforePlanetTotalValue, | BeforePlanetTotalValue: resp.BeforePlanetTotalValue, | ||||
@@ -102,7 +103,8 @@ func AutoAdjustPrice(engine *xorm.Engine) (err error) { | |||||
// 市商数量 增加、市商资金 减少 | // 市商数量 增加、市商资金 减少 | ||||
err = DealAvailableEggEnergyCoin(session, int(enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums), eggEnergyCoreData, md2.DealAvailableEggEnergyCoinReq{ | err = DealAvailableEggEnergyCoin(session, int(enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums), eggEnergyCoreData, md2.DealAvailableEggEnergyCoinReq{ | ||||
Amount: resp.GetEggEnergyNums, | Amount: resp.GetEggEnergyNums, | ||||
AmountFee: marketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue.String(), | |||||
AmountValue: marketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue.String(), | |||||
AmountFee: "", | |||||
BeforePrice: resp.BeforePrice, | BeforePrice: resp.BeforePrice, | ||||
AfterPrice: resp.AfterPrice, | AfterPrice: resp.AfterPrice, | ||||
BeforePlanetTotalValue: resp.BeforePlanetTotalValue, | BeforePlanetTotalValue: resp.BeforePlanetTotalValue, | ||||
@@ -4,6 +4,8 @@ import ( | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | ||||
egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils" | egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils" | ||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | "fmt" | ||||
"github.com/shopspring/decimal" | "github.com/shopspring/decimal" | ||||
) | ) | ||||
@@ -36,16 +38,43 @@ func CalcPriceIncreaseFormula(userAmountValue string, eggEnergyCoreData *model.E | |||||
} | } | ||||
// CalcPriceReductionFormula 计算降价公式(【用户需兑换蛋蛋能量数量*{星球价值 ÷(用户需兑换蛋蛋能量数量+现行数量} *(1 - 扣比例50% ~ 23%) = 用户获得钱) | // 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) //变更后-现行数量 | |||||
func CalcPriceReductionFormula(userExchangeNumsValue string, eggEnergyCoreData *model.EggEnergyCoreData, levelId string, eggEnergyBasicSetting model.EggEnergyBasicSetting) (err error, resp md.CalcPriceReductionFormulaResp) { | |||||
exchangeAccountBalanceFee := decimal.NewFromInt(0) //兑换手续费 | |||||
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 | |||||
if levelId != "" { | |||||
var vipEquitySetting []*md.VipEquitySettingStruct | |||||
err = json.Unmarshal([]byte(eggEnergyBasicSetting.VipEquitySetting), &vipEquitySetting) | |||||
if err != nil { | |||||
fmt.Println("err:::::", err) | |||||
return | |||||
} | |||||
var exchangeAccountBalanceFeeValue string | |||||
for _, v := range vipEquitySetting { | |||||
if v.VipLevelId == levelId { | |||||
exchangeAccountBalanceFeeValue = v.ExchangeAccountBalanceFee | |||||
} | |||||
if exchangeAccountBalanceFeeValue == "" { | |||||
err = errors.New("未查询到当前会员等级兑换余额手续费") | |||||
return | |||||
} | |||||
exchangeAccountBalanceFee, _ = decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 | |||||
} | |||||
} | |||||
decimalRate := decimal.NewFromInt(100) //百分比 | |||||
nowEnergyTotalNums, _ := decimal.NewFromString(eggEnergyCoreData.NowEnergyTotalNums) //现行数量 | |||||
planetTotalValue, _ := decimal.NewFromString(eggEnergyCoreData.PlanetTotalValue) //星球价值 | |||||
afterPrice := planetTotalValue.Div(userExchangeNums.Add(nowEnergyTotalNums)).Truncate(16) //降价后的价格 | |||||
greenEnergyValues := userExchangeNums.Mul(afterPrice) //能量价值 | |||||
greenEnergyFeeValues := greenEnergyValues.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //能量个数扣除手续费价值 | |||||
resp.GetEggEnergyAmount = greenEnergyValues.Sub(greenEnergyFeeValues).Truncate(8).String() //用户实际得到的钱 | |||||
amountFee := userExchangeNums.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //能量手续费 | |||||
resp.AmountFee = amountFee.String() | |||||
afterEnergyTotalNumsValue := nowEnergyTotalNums.Sub(userExchangeNums.Sub(amountFee)) //变更后-现行数量 | |||||
afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值 | afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值 | ||||
resp.GetEggEnergyAmount = greenEnergyValues.Truncate(16).String() | |||||
resp.BeforePrice = eggEnergyCoreData.NowPrice | resp.BeforePrice = eggEnergyCoreData.NowPrice | ||||
resp.AfterPrice = afterPrice.String() | resp.AfterPrice = afterPrice.String() | ||||
resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue | resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue | ||||
@@ -130,8 +130,8 @@ func DealAvailableEggEnergyCoin(session *xorm.Session, kind int, eggEnergyCoreDa | |||||
destructionQuantityNums, _ := decimal.NewFromString(eggEnergyCoreData.DestructionQuantityNums) //销毁数量 | destructionQuantityNums, _ := decimal.NewFromString(eggEnergyCoreData.DestructionQuantityNums) //销毁数量 | ||||
destructionQuantity, _ := decimal.NewFromString(destructionSetting.DestructionQuantity) | destructionQuantity, _ := decimal.NewFromString(destructionSetting.DestructionQuantity) | ||||
eggEnergyAvailableEnergyFlow.BeforeStarLevelDividendsValues = eggEnergyCoreData.DestructionQuantityNums | |||||
eggEnergyAvailableEnergyFlow.AfterStarLevelDividendsValues = destructionQuantityNums.Add(amountFeeValue.Mul(destructionQuantity.Div(decimalRate))).RoundFloor(8).String() | |||||
eggEnergyAvailableEnergyFlow.BeforeDestructionQuantityValues = eggEnergyCoreData.DestructionQuantityNums | |||||
eggEnergyAvailableEnergyFlow.AfterDestructionQuantityValues = destructionQuantityNums.Add(amountFeeValue.Mul(destructionQuantity.Div(decimalRate))).RoundFloor(8).String() | |||||
//TODO::新增 / 更新 egg_star_level_dividends_records 记录 | //TODO::新增 / 更新 egg_star_level_dividends_records 记录 | ||||
eggStarLevelDividendsRecordsDb := implement.NewEggStarLevelDividendsRecordsDb(session.Engine()) | eggStarLevelDividendsRecordsDb := implement.NewEggStarLevelDividendsRecordsDb(session.Engine()) | ||||
@@ -219,15 +219,15 @@ func DealAvailableEggEnergyCoin(session *xorm.Session, kind int, eggEnergyCoreDa | |||||
eggEnergyAvailableEnergyFlow.AfterDestructionQuantityValues = eggEnergyCoreData.DestructionQuantityNums | eggEnergyAvailableEnergyFlow.AfterDestructionQuantityValues = eggEnergyCoreData.DestructionQuantityNums | ||||
break | break | ||||
case int(enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds): //市商数量自动兑换市商资金 | case int(enum.MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds): //市商数量自动兑换市商资金 | ||||
amountFeeValue, _ := decimal.NewFromString(req.AmountFee) //消耗的蛋蛋能量 | |||||
amountValueValue, _ := decimal.NewFromString(req.AmountValue) //得到的蛋蛋能量价值 | |||||
marketplaceMerchantNums, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantNums) //市商数量 | marketplaceMerchantNums, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantNums) //市商数量 | ||||
eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantValues = eggEnergyCoreData.MarketplaceMerchantNums | eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantValues = eggEnergyCoreData.MarketplaceMerchantNums | ||||
eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantValues = marketplaceMerchantNums.Sub(amountFeeValue).RoundFloor(8).String() | |||||
eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantValues = marketplaceMerchantNums.Sub(amountValue).RoundFloor(8).String() | |||||
marketplaceMerchantFunds, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantFunds) //市商资金 | marketplaceMerchantFunds, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantFunds) //市商资金 | ||||
eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantFundValues = eggEnergyCoreData.MarketplaceMerchantFunds | eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantFundValues = eggEnergyCoreData.MarketplaceMerchantFunds | ||||
eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantFundValues = marketplaceMerchantFunds.Add(amountValue).RoundFloor(8).String() | |||||
eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantFundValues = marketplaceMerchantFunds.Add(amountValueValue).RoundFloor(8).String() | |||||
eggEnergyAvailableEnergyFlow.BeforeDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee //发展委员会 | eggEnergyAvailableEnergyFlow.BeforeDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee //发展委员会 | ||||
eggEnergyAvailableEnergyFlow.AfterDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee | eggEnergyAvailableEnergyFlow.AfterDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee | ||||
@@ -241,7 +241,7 @@ func DealAvailableEggEnergyCoin(session *xorm.Session, kind int, eggEnergyCoreDa | |||||
eggEnergyAvailableEnergyFlow.AfterDestructionQuantityValues = eggEnergyCoreData.DestructionQuantityNums | eggEnergyAvailableEnergyFlow.AfterDestructionQuantityValues = eggEnergyCoreData.DestructionQuantityNums | ||||
break | break | ||||
case int(enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums): //市商资金自动兑换市商数量 | case int(enum.MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums): //市商资金自动兑换市商数量 | ||||
amountFeeValue, _ := decimal.NewFromString(req.AmountFee) //消耗的资金 | |||||
amountValueValue, _ := decimal.NewFromString(req.AmountValue) //消耗的资金 | |||||
marketplaceMerchantNums, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantNums) //市商数量 | marketplaceMerchantNums, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantNums) //市商数量 | ||||
eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantValues = eggEnergyCoreData.MarketplaceMerchantNums | eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantValues = eggEnergyCoreData.MarketplaceMerchantNums | ||||
@@ -249,7 +249,7 @@ func DealAvailableEggEnergyCoin(session *xorm.Session, kind int, eggEnergyCoreDa | |||||
marketplaceMerchantFunds, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantFunds) //市商资金 | marketplaceMerchantFunds, _ := decimal.NewFromString(eggEnergyCoreData.MarketplaceMerchantFunds) //市商资金 | ||||
eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantFundValues = eggEnergyCoreData.MarketplaceMerchantFunds | eggEnergyAvailableEnergyFlow.BeforeMarketplaceMerchantFundValues = eggEnergyCoreData.MarketplaceMerchantFunds | ||||
eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantFundValues = marketplaceMerchantFunds.Sub(amountFeeValue).RoundFloor(8).String() | |||||
eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantFundValues = marketplaceMerchantFunds.Sub(amountValueValue).RoundFloor(8).String() | |||||
eggEnergyAvailableEnergyFlow.BeforeDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee //发展委员会 | eggEnergyAvailableEnergyFlow.BeforeDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee //发展委员会 | ||||
eggEnergyAvailableEnergyFlow.AfterDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee | eggEnergyAvailableEnergyFlow.AfterDevelopmentCommitteeValues = eggEnergyCoreData.DevelopmentCommittee | ||||
@@ -88,6 +88,7 @@ type CalcPriceIncreaseFormulaResp struct { | |||||
type CalcPriceReductionFormulaResp struct { | type CalcPriceReductionFormulaResp struct { | ||||
GetEggEnergyAmount string `json:"get_egg_energy_amount"` //得到蛋蛋能量的钱` | GetEggEnergyAmount string `json:"get_egg_energy_amount"` //得到蛋蛋能量的钱` | ||||
AmountFee string `json:"amount_fee"` //手续费 | |||||
BeforePrice string `json:"before_price"` //变更前-价格 | BeforePrice string `json:"before_price"` //变更前-价格 | ||||
AfterPrice string `json:"after_price"` //变更后-价格 | AfterPrice string `json:"after_price"` //变更后-价格 | ||||
BeforePlanetTotalValue string `json:"before_planet_total_value"` //变更前-星球总价值 | BeforePlanetTotalValue string `json:"before_planet_total_value"` //变更前-星球总价值 | ||||
@@ -98,6 +99,7 @@ type CalcPriceReductionFormulaResp struct { | |||||
type DealAvailableEggEnergyCoinReq struct { | type DealAvailableEggEnergyCoinReq struct { | ||||
Amount string `json:"amount"` //变更数量 | Amount string `json:"amount"` //变更数量 | ||||
AmountValue string `json:"amount_value"` //变更数量-价值 | |||||
AmountFee string `json:"amount_fee"` //手续费 | AmountFee string `json:"amount_fee"` //手续费 | ||||
BeforePrice string `json:"before_price"` //变更前-价格 | BeforePrice string `json:"before_price"` //变更前-价格 | ||||
AfterPrice string `json:"after_price"` //变更后-价格 | AfterPrice string `json:"after_price"` //变更后-价格 | ||||