瀏覽代碼

update

master
dengbiao 1 周之前
父節點
當前提交
e970feba7d
共有 5 個文件被更改,包括 66 次插入31 次删除
  1. +3
    -1
      rule/egg_energy/activity_coin_auto_exchange_egg_energy.go
  2. +26
    -10
      rule/egg_energy/activity_coin_ready_exchange_egg_energy.go
  3. +9
    -8
      rule/egg_energy/activity_coin_start_exchange_egg_person_energy.go
  4. +17
    -11
      rule/egg_energy/available_green_energy_settlement.go
  5. +11
    -1
      rule/egg_energy/deal_available_green_energy_points.go

+ 3
- 1
rule/egg_energy/activity_coin_auto_exchange_egg_energy.go 查看文件

@@ -23,7 +23,9 @@ func ActivityCoinAutoExchangeEggPersonEnergy(engine *xorm.Engine, req md.EggEner
now := time.Now()
endTimeValue, _ := egg_system_rules.StringToTime(req.EndExchangeTime)
if endTimeValue.After(now) {
time.Sleep(time.Microsecond * time.Duration(rand.Intn(5))) //TODO::随机休眠5s不等
seconds := time.Duration(rand.Intn(10))
fmt.Println("休眠:::::", seconds)
time.Sleep(time.Second * seconds) //TODO::随机休眠10s不等
return errors.New("未到可执行时间~~~")
}



+ 26
- 10
rule/egg_energy/activity_coin_ready_exchange_egg_energy.go 查看文件

@@ -142,15 +142,31 @@ func ActivityCoinReadyExchangeEggEnergy(engine *xorm.Engine, uid int64, ch *rabb
}

//TODO::推入rabbitmq 异步处理
ch.Publish(md2.EggEnergyExchange, md2.EggEnergyStructForStartExchangeGreenEnergy{
Uid: uid,
SignId: sign.Id,
PersonEggEnergyCoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId,
TeamEggEnergyCoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
PersonPointCoinId: coin1.Id,
PersonEnergyCoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId,
TeamPointCoinId: coin2.Id,
TeamEnergyCoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
}, md2.EggEnergyRoutKeyForStartExchangeGreenEnergy)
if egg_system_rules.StrToFloat64(autoExchangeNumsByPersonAmountValue) > 0 {
ch.Publish(md2.EggEnergyExchange, md2.EggEnergyStructForStartExchangeGreenEnergy{
Uid: uid,
SignId: sign.Id,
PersonEggEnergyCoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId,
TeamEggEnergyCoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
PersonPointCoinId: coin1.Id,
PersonEnergyCoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId,
TeamPointCoinId: coin2.Id,
TeamEnergyCoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
}, md2.EggEnergyRoutKeyForStartExchangeGreenEnergy)
}

if egg_system_rules.StrToFloat64(autoExchangeNumsByTeamAmountValue) > 0 {
ch.Publish(md2.EggEnergyExchange, md2.EggEnergyStructForStartExchangeGreenEnergy{
Uid: uid,
SignId: sign.Id,
PersonEggEnergyCoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId,
TeamEggEnergyCoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
PersonPointCoinId: coin1.Id,
PersonEnergyCoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId,
TeamPointCoinId: coin2.Id,
TeamEnergyCoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
}, md2.EggEnergyRoutKeyForStartExchangeGreenEnergy)
}

return
}

+ 9
- 8
rule/egg_energy/activity_coin_start_exchange_egg_person_energy.go 查看文件

@@ -71,20 +71,14 @@ func ActivityCoinStartExchangeEggEnergy(engine *xorm.Engine, req md.EggEnergyStr
if cb != nil {
defer cb() // 释放锁
}
//3.1、计算涨价公式
err1, calcPriceIncreaseFormulaRespForPerson := CalcPriceIncreaseFormula(sign.TotalPersonEggPointsAmountValue, eggEnergyCoreData)
if err1 != nil {
_ = session.Rollback()
return err1
}

err1, calcPriceIncreaseFormulaRespForTeam := CalcPriceIncreaseFormula(sign.TotalTeamEggPointsAmountValue, eggEnergyCoreData)
//3.1、"个人" 购买
err1, calcPriceIncreaseFormulaRespForPerson := CalcPriceIncreaseFormula(sign.TotalPersonEggPointsAmountValue, eggEnergyCoreData)
if err1 != nil {
_ = session.Rollback()
return err1
}

//3.2、更改动态数据
err = DealAvailableEggEnergyCoin(session, int(enum2.PersonalActivePointRedemption), eggEnergyCoreData, md.DealAvailableEggEnergyCoinReq{
Amount: calcPriceIncreaseFormulaRespForPerson.GetEggEnergyNums,
AmountFee: "",
@@ -100,6 +94,13 @@ func ActivityCoinStartExchangeEggEnergy(engine *xorm.Engine, req md.EggEnergyStr
_ = session.Rollback()
return err
}

//3.2、"团队" 购买
err1, calcPriceIncreaseFormulaRespForTeam := CalcPriceIncreaseFormula(sign.TotalTeamEggPointsAmountValue, eggEnergyCoreData)
if err1 != nil {
_ = session.Rollback()
return err1
}
err = DealAvailableEggEnergyCoin(session, int(enum2.TeamActivePointRedemption), eggEnergyCoreData, md.DealAvailableEggEnergyCoinReq{
Amount: calcPriceIncreaseFormulaRespForTeam.GetEggEnergyNums,
AmountFee: "",


+ 17
- 11
rule/egg_energy/available_green_energy_settlement.go 查看文件

@@ -4,27 +4,33 @@ 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"
"fmt"
"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) //变更后-星球价值
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(16) //涨价后的价格
fmt.Println("userAmount:::", userAmount.String())
fmt.Println("nowEnergyTotalNums:::", nowEnergyTotalNums.String())
fmt.Println("planetTotalValue:::", planetTotalValue.String())
fmt.Println("afterPrice:::", afterPrice.String())
getEggEnergyNumsValue := userAmount.Div(afterPrice).Truncate(8) //用户得到绿色能量个数
afterEnergyTotalNumsValue := nowEnergyTotalNums.Add(getEggEnergyNumsValue) //变更后-现行数量
afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值
fmt.Println("afterPlanetTotalValue:::", afterPlanetTotalValue.String())

resp.GetEggEnergyNums = getEggEnergyNumsValue.String()
resp.BeforePrice = nowPrice.String()
resp.AfterPrice = afterPrice.String()
resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue
resp.AfterPlanetTotalValue = afterPlanetTotalValue.String()
resp.AfterPlanetTotalValue = afterPlanetTotalValue.Truncate(8).String()
resp.BeforeEnergyTotalNums = eggEnergyCoreData.NowEnergyTotalNums
resp.AfterEnergyTotalNums = afterEnergyTotalNumsValue.String()
resp.AfterEnergyTotalNums = afterEnergyTotalNumsValue.Truncate(8).String()
egg_system_rules.FilePutContents("CalcPriceIncreaseFormula", egg_system_rules.SerializeStr(resp))
return
}
@@ -39,7 +45,7 @@ func CalcPriceReductionFormula(userExchangeNumsValue string, eggEnergyCoreData *
afterEnergyTotalNumsValue := nowEnergyTotalNums.Sub(userExchangeNums) //变更后-现行数量
afterPlanetTotalValue := afterEnergyTotalNumsValue.Mul(afterPrice) //变更后-星球价值

resp.GetEggEnergyAmount = greenEnergyValues.Truncate(8).String()
resp.GetEggEnergyAmount = greenEnergyValues.Truncate(16).String()
resp.BeforePrice = eggEnergyCoreData.NowPrice
resp.AfterPrice = afterPrice.String()
resp.BeforePlanetTotalValue = eggEnergyCoreData.PlanetTotalValue


+ 11
- 1
rule/egg_energy/deal_available_green_energy_points.go 查看文件

@@ -36,7 +36,7 @@ func DealAvailableEggEnergyCoin(session *xorm.Session, kind int, eggEnergyCoreDa
eggEnergyAvailableEnergyFlow.BeforeNowEnergyTotalNums = req.BeforeEnergyTotalNums //现行总量
eggEnergyAvailableEnergyFlow.AfterNowEnergyTotalNums = req.AfterEnergyTotalNums
eggEnergyAvailableEnergyFlow.BeforePlanetTotalValue = req.BeforePlanetTotalValue //星球总价值
eggEnergyAvailableEnergyFlow.AfterNowEnergyTotalNums = req.AfterPlanetTotalValue
eggEnergyAvailableEnergyFlow.AfterPlanetTotalValue = req.AfterPlanetTotalValue
eggEnergyAvailableEnergyFlow.CreateTime = now.Format("2006-01-02 15:04:05")

switch kind {
@@ -273,6 +273,16 @@ func DealAvailableEggEnergyCoin(session *xorm.Session, kind int, eggEnergyCoreDa
break
}

eggEnergyCoreData.NowPrice = req.AfterPrice
eggEnergyCoreData.PlanetTotalValue = eggEnergyAvailableEnergyFlow.AfterPlanetTotalValue
eggEnergyCoreData.NowEnergyTotalNums = eggEnergyAvailableEnergyFlow.AfterNowEnergyTotalNums
eggEnergyCoreData.MarketplaceMerchantNums = eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantValues
eggEnergyCoreData.MarketplaceMerchantFunds = eggEnergyAvailableEnergyFlow.AfterMarketplaceMerchantFundValues
eggEnergyCoreData.DevelopmentCommittee = eggEnergyAvailableEnergyFlow.AfterDevelopmentCommitteeValues
eggEnergyCoreData.PublicWelfareAndCharity = eggEnergyAvailableEnergyFlow.AfterPublicWelfareAndCharityValues
eggEnergyCoreData.StarLevelDividends = eggEnergyAvailableEnergyFlow.AfterStarLevelDividendsValues
eggEnergyCoreData.CommunityDividends = eggEnergyAvailableEnergyFlow.AfterCommunityDividends
eggEnergyCoreData.DestructionQuantityNums = eggEnergyAvailableEnergyFlow.AfterDestructionQuantityValues
//更新 `egg_energy_core_data` 表
eggEnergyCoreDataDb := implement.NewEggEnergyCoreDataDb(session.Engine())
_, err := eggEnergyCoreDataDb.EggEnergyCoreDataUpdateBySession(session, eggEnergyCoreData.Id, eggEnergyCoreData,


Loading…
取消
儲存