Browse Source

update 区块星链

tags/v3.4.3
DengBiao 2 years ago
parent
commit
50d0c53e07
3 changed files with 77 additions and 49 deletions
  1. +1
    -0
      go.mod
  2. +2
    -0
      go.sum
  3. +74
    -49
      rule/block_star_chain_settlement.go

+ 1
- 0
go.mod View File

@@ -6,6 +6,7 @@ require (
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.8.9 // indirect github.com/gomodule/redigo v1.8.9 // indirect
github.com/jinzhu/copier v0.3.5 github.com/jinzhu/copier v0.3.5
github.com/shopspring/decimal v1.3.1 // indirect
github.com/syyongx/php2go v0.9.6 github.com/syyongx/php2go v0.9.6
go.uber.org/zap v1.13.0 go.uber.org/zap v1.13.0
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f


+ 2
- 0
go.sum View File

@@ -324,6 +324,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=


+ 74
- 49
rule/block_star_chain_settlement.go View File

@@ -26,10 +26,11 @@ func Init(redisAddr string) (err error) {
return return
} }


const PessimismLockKey = "daily_settlement_block_star_chain_pessimism_lock_key"
const PessimismLockValue = "running"

// DailySettlementBlockStarChain 每日结算“区块星链” // DailySettlementBlockStarChain 每日结算“区块星链”
func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) (err error) { func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool) (err error) {
//TODO::先休眠2分钟
time.Sleep(time.Minute * 2)
session := engine.NewSession() session := engine.NewSession()
defer func() { defer func() {
session.Close() session.Close()
@@ -42,11 +43,11 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
today := now.Format("2006-01-02") today := now.Format("2006-01-02")


fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", now.Hour()) fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", now.Hour())
//if isTask && (now.Hour() > 8 || now.Hour() < 1) {
if isTask && (now.Hour() > 8) { if isTask && (now.Hour() > 8) {
//TODO::只在凌晨一点 ~ 凌晨 8 点运行 //TODO::只在凌晨一点 ~ 凌晨 8 点运行
return errors.New("非运行时间") return errors.New("非运行时间")
} }

//1、查找 `block_star_chain` 基础设置 //1、查找 `block_star_chain` 基础设置
blockStarChain, err := db.BlockStarChainGetOneByParams(session, map[string]interface{}{ blockStarChain, err := db.BlockStarChainGetOneByParams(session, map[string]interface{}{
"key": "is_use", "key": "is_use",
@@ -56,19 +57,22 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
_ = session.Rollback() _ = session.Rollback()
return err return err
} }
//if blockStarChain.StartAt == "" || blockStarChain.StartAt == "0000-00-00" {
// _ = session.Rollback()
// return errors.New("区块星链空投暂未开启")
//} else {
// _ = session.Rollback()
// return errors.New("区块星链空投暂未开启1111")
//}

if blockStarChain.SettlementDate == today { if blockStarChain.SettlementDate == today {
_ = session.Rollback() _ = session.Rollback()
return errors.New("今日“区块星链”已结算") return errors.New("今日“区块星链”已结算")
} }
//initialCoinTotal := zhios_order_relate_utils.StrToFloat64(blockStarChain.InitialCoinTotal) //初始区块币总量

//TODO::增加“悲观锁”防止串行
getString, err := cache.GetString(PessimismLockKey)
if err != nil {
return err
}
if getString == PessimismLockValue {
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次结算未执行完")
return errors.New("非运行时间")
}
cache.SetEx(PessimismLockKey, PessimismLockValue, 3600*8) //8小时

todayPublishCoin := zhios_order_relate_utils.StrToFloat64(blockStarChain.TodayPublishCoin) //今日区块币发行数量(若为0,则按当前每日区块币发行数量) todayPublishCoin := zhios_order_relate_utils.StrToFloat64(blockStarChain.TodayPublishCoin) //今日区块币发行数量(若为0,则按当前每日区块币发行数量)
nowEverydayPublishCoin := zhios_order_relate_utils.StrToFloat64(blockStarChain.NowEverydayPublishCoin) //当前每日区块币发行数量 nowEverydayPublishCoin := zhios_order_relate_utils.StrToFloat64(blockStarChain.NowEverydayPublishCoin) //当前每日区块币发行数量


@@ -208,6 +212,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
_ = session.Rollback() _ = session.Rollback()
return errors.New("事务提交失败") return errors.New("事务提交失败")
} }
cache.Del(PessimismLockKey)
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>区块星链结束<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>区块星链结束<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
return nil return nil
} }
@@ -588,6 +593,7 @@ func calcNowEverydayPublishCoin(session *xorm.Session, chain *model.BlockStarCha


//处理虚拟币 - 发放 //处理虚拟币 - 发放
func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.BlockStarChain) error { func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.BlockStarChain) error {
amountValue := decimal.NewFromFloat(amount)
now := time.Now() now := time.Now()
var blockStarChainFlow model.BlockStarChainFlow var blockStarChainFlow model.BlockStarChainFlow
blockStarChainFlow.CoinId = chain.Coin1 blockStarChainFlow.CoinId = chain.Coin1
@@ -595,15 +601,20 @@ func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string
blockStarChainFlow.Kind = kind blockStarChainFlow.Kind = kind
blockStarChainFlow.Title = title blockStarChainFlow.Title = title
blockStarChainFlow.CreateTime = now blockStarChainFlow.CreateTime = now
blockStarChainFlow.Amount = zhios_order_relate_utils.Float64ToStrPrec10(amount)
blockStarChainFlow.Amount = amountValue.RoundFloor(4).String()
switch kind { switch kind {
case int(enum.SystemTimingIssue): case int(enum.SystemTimingIssue):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) + amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Add(amountValue).RoundFloor(4).String()

blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) - amount)
beforeTotalRemainderCoin, _ := decimal.NewFromString(chain.TotalRemainderCoin)
blockStarChainFlow.AfterTotalRemainderCoin = beforeTotalRemainderCoin.Sub(amountValue).RoundFloor(4).String()

blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalPublishCoin) + amount)
beforeTotalPublishCoin, _ := decimal.NewFromString(chain.TotalPublishCoin)
blockStarChainFlow.AfterTotalPublishCoin = beforeTotalPublishCoin.Add(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.AfterTotalDestroyCoin = chain.TotalDestroyCoin
break break
@@ -633,13 +644,14 @@ func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string


//DealDestroyCoin 处理虚拟币 - 销毁 //DealDestroyCoin 处理虚拟币 - 销毁
func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.BlockStarChain) error { func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.BlockStarChain) error {
amountValue := decimal.NewFromFloat(amount)
now := time.Now() now := time.Now()
var blockStarChainFlow model.BlockStarChainFlow var blockStarChainFlow model.BlockStarChainFlow
blockStarChainFlow.CoinId = chain.Coin1 blockStarChainFlow.CoinId = chain.Coin1
blockStarChainFlow.Direction = md.FlowDirectionExpenditure blockStarChainFlow.Direction = md.FlowDirectionExpenditure
blockStarChainFlow.Kind = kind blockStarChainFlow.Kind = kind
blockStarChainFlow.Title = title blockStarChainFlow.Title = title
blockStarChainFlow.Amount = zhios_order_relate_utils.Float64ToStrPrec10(amount)
blockStarChainFlow.Amount = amountValue.RoundFloor(4).String()
blockStarChainFlow.CreateTime = now blockStarChainFlow.CreateTime = now
switch kind { switch kind {
case int(enum.SystemDestroy): case int(enum.SystemDestroy):
@@ -650,113 +662,126 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.StaticUnallocatedAndDestroy): case int(enum.StaticUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.DynamicallyUnallocatedAndDestroy): case int(enum.DynamicallyUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.OperationCenterUnallocatedAndDestroy): case int(enum.OperationCenterUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.OtherUnallocatedAndDestroy): case int(enum.OtherUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.RewardDestroy): case int(enum.RewardDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.RewardUnallocatedAndDestroy): case int(enum.RewardUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.GroupLotteryAndDestroy): case int(enum.GroupLotteryAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.RedEnvelopeTransferBalanceAndDestroy): case int(enum.RedEnvelopeTransferBalanceAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
case int(enum.TransferFeeAndDestroy): case int(enum.TransferFeeAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) - amount)
beforeTotalNowCoin, _ := decimal.NewFromString(chain.TotalNowCoin)
blockStarChainFlow.AfterTotalNowCoin = beforeTotalNowCoin.Sub(amountValue).RoundFloor(4).String()
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin blockStarChainFlow.AfterTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
beforeTotalDestroyCoin, _ := decimal.NewFromString(chain.TotalDestroyCoin)
blockStarChainFlow.AfterTotalDestroyCoin = beforeTotalDestroyCoin.Add(amountValue).RoundFloor(4).String()
break break
} }


chain.TotalNowCoin = blockStarChainFlow.AfterTotalNowCoin chain.TotalNowCoin = blockStarChainFlow.AfterTotalNowCoin
//chain.TotalRemainderCoin = blockStarChainFlow.AfterTotalRemainderCoin
//chain.TotalPublishCoin = blockStarChainFlow.AfterTotalPublishCoin
chain.TotalDestroyCoin = blockStarChainFlow.AfterTotalDestroyCoin chain.TotalDestroyCoin = blockStarChainFlow.AfterTotalDestroyCoin
//更新 `block_star_chain` 表 //更新 `block_star_chain` 表
_, err := db.BlockStarChainUpdate(session, chain.Id, chain) _, err := db.BlockStarChainUpdate(session, chain.Id, chain)
if err != nil { if err != nil {
return err return err
} }
//if updateAffected == 0 {
// err = errors.New("更新 block_star_chain 记录失败")
// return err
//}


//插入 `block_star_chain_flow` 记录 //插入 `block_star_chain_flow` 记录
_, err = db.BlockStarChainFlowInsert(session, &blockStarChainFlow) _, err = db.BlockStarChainFlowInsert(session, &blockStarChainFlow)
@@ -785,7 +810,7 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) {
return err return err
} }
coinAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(coinAmount)) coinAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(coinAmount))
amountValue := decimal.NewFromFloat(req.Amount)
amountValue := decimal.NewFromFloat(req.Amount).RoundFloor(4)


var userVirtualCoinFlow model.UserVirtualCoinFlow var userVirtualCoinFlow model.UserVirtualCoinFlow
userVirtualCoinFlow.CoinId = req.CoinId userVirtualCoinFlow.CoinId = req.CoinId
@@ -798,10 +823,10 @@ func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) {


if req.Kind == "add" { if req.Kind == "add" {
userVirtualCoinFlow.Direction = 1 userVirtualCoinFlow.Direction = 1
userVirtualCoinFlow.AfterAmout = coinAmountValue.Add(amountValue).String()
userVirtualCoinFlow.AfterAmout = coinAmountValue.Add(amountValue).RoundFloor(4).String()
} else if req.Kind == "sub" { } else if req.Kind == "sub" {
userVirtualCoinFlow.Direction = 2 userVirtualCoinFlow.Direction = 2
userVirtualCoinFlow.AfterAmout = coinAmountValue.Sub(amountValue).String()
userVirtualCoinFlow.AfterAmout = coinAmountValue.Sub(amountValue).RoundFloor(4).String()
} else { } else {
err = errors.New("错误的kind类型") err = errors.New("错误的kind类型")
return err return err
@@ -850,8 +875,8 @@ func DealLotteryDraw(session *xorm.Session, req md.DealLotteryDrawReq) (err erro
rewardValue, _ := decimal.NewFromString(req.Amount) rewardValue, _ := decimal.NewFromString(req.Amount)
rewardValue = rewardValue.Mul(decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(blockStarChain.LotteryDrawDestroyCoinRate) / 100)) rewardValue = rewardValue.Mul(decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(blockStarChain.LotteryDrawDestroyCoinRate) / 100))
platformGuidePriceForCoin, _ := decimal.NewFromString(blockStarChain.PlatformGuidePriceForCoin) platformGuidePriceForCoin, _ := decimal.NewFromString(blockStarChain.PlatformGuidePriceForCoin)
needDestroyCoin := rewardValue.Div(platformGuidePriceForCoin) //须销毁的米豆
destroyCoinValue, _ := needDestroyCoin.Float64() //系统销毁 区块币值
needDestroyCoin := rewardValue.Div(platformGuidePriceForCoin) //须销毁的米豆
destroyCoinValue, _ := needDestroyCoin.RoundFloor(4).Float64() //系统销毁 区块币值


//2、用户扣除 //2、用户扣除
err = DealUserCoin(session, md.DealUserCoinReq{ err = DealUserCoin(session, md.DealUserCoinReq{
@@ -884,7 +909,7 @@ func DealLotteryDraw(session *xorm.Session, req md.DealLotteryDrawReq) (err erro
return nil return nil
} }


// CalcLotteryDraw 处理抽奖
// CalcLotteryDraw 计算抽奖
func CalcLotteryDraw(session *xorm.Session, req md.DealLotteryDrawReq) (err error) { func CalcLotteryDraw(session *xorm.Session, req md.DealLotteryDrawReq) (err error) {
defer func() { defer func() {
session.Close() session.Close()
@@ -905,7 +930,7 @@ func CalcLotteryDraw(session *xorm.Session, req md.DealLotteryDrawReq) (err erro
rewardValue, _ := decimal.NewFromString(req.Amount) rewardValue, _ := decimal.NewFromString(req.Amount)
rewardValue = rewardValue.Mul(decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(blockStarChain.LotteryDrawDestroyCoinRate) / 100)) rewardValue = rewardValue.Mul(decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(blockStarChain.LotteryDrawDestroyCoinRate) / 100))
platformGuidePriceForCoin, _ := decimal.NewFromString(blockStarChain.PlatformGuidePriceForCoin) platformGuidePriceForCoin, _ := decimal.NewFromString(blockStarChain.PlatformGuidePriceForCoin)
needDestroyCoin := rewardValue.Div(platformGuidePriceForCoin) //须销毁的米豆
needDestroyCoin := rewardValue.Div(platformGuidePriceForCoin).RoundFloor(4) //须销毁的米豆


coinAmount, err := svc.GetUserCoinAmount(session, req.Mid, blockStarChain.Coin1, req.Uid) //用户当前的米豆值 coinAmount, err := svc.GetUserCoinAmount(session, req.Mid, blockStarChain.Coin1, req.Uid) //用户当前的米豆值
coinAmountValue, _ := decimal.NewFromString(coinAmount) coinAmountValue, _ := decimal.NewFromString(coinAmount)


Loading…
Cancel
Save