Browse Source

update 区块星链

tags/v3.5.5
DengBiao 2 years ago
parent
commit
79b9419687
2 changed files with 33 additions and 12 deletions
  1. +6
    -2
      db/db_block_star_chain_settlement_records.go
  2. +27
    -10
      rule/block_star_chain_settlement.go

+ 6
- 2
db/db_block_star_chain_settlement_records.go View File

@@ -75,12 +75,16 @@ func BlockStarChainSettlementRecordsUpdate(session *xorm.Session, id interface{}
}

// BlockStarChainSettlementRecordsGetOneByParams 通过传入的参数查询数据(单条)
func BlockStarChainSettlementRecordsGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.BlockStarChainSettlementRecords, error) {
func BlockStarChainSettlementRecordsGetOneByParams(session *xorm.Session, params map[string]interface{}) (*model.BlockStarChainSettlementRecords, error) {
var m model.BlockStarChainSettlementRecords
var query = fmt.Sprintf("%s =?", params["key"])
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false {
has, err := session.Where(query, params["value"]).Get(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return &m, nil
}



+ 27
- 10
rule/block_star_chain_settlement.go View File

@@ -62,6 +62,20 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
return errors.New("今日“区块星链”已结算")
}

isHasBlockStarChainSettlementRecords, err := db.BlockStarChainSettlementRecordsGetOneByParams(session, map[string]interface{}{
"key": "date",
"value": today,
})
if isHasBlockStarChainSettlementRecords != nil {
_ = session.Rollback()
return errors.New("今日区块星链已结算!!!")
}

if today == "2022-10-23" {
_ = session.Rollback()
return errors.New("今日区块星链已结算。。。")
}

//TODO::增加“悲观锁”防止串行
getString, _ := cache.GetString(PessimismLockKey)
//if err != nil {
@@ -189,7 +203,8 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)

//10、更新 block_star_chain 中的 settlement_date 字段
blockStarChain.SettlementDate = today
updateAffected, err := db.BlockStarChainUpdate(session, blockStarChain.Id, blockStarChain, "settlement_date")
//updateAffected, err := db.BlockStarChainUpdate(session, blockStarChain.Id, blockStarChain, "settlement_date")
updateAffected, err := db.BlockStarChainUpdate(session, blockStarChain.Id, blockStarChain)
if err != nil {
_ = session.Rollback()
return err
@@ -218,12 +233,14 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string, isTask bool)
_ = session.Rollback()
return errors.New("事务提交失败")
}
cache.Del(PessimismLockKey)

zhios_order_relate_utils.CurlPost("http://zhios-app:5000/api/v1/check_app_over_time", map[string]string{
"mid": mid,
"is_close": "0",
}, map[string]string{})

//cache.Del(PessimismLockKey)

fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>区块星链结束<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
return nil
}
@@ -592,14 +609,14 @@ func calcNowEverydayPublishCoin(session *xorm.Session, chain *model.BlockStarCha
everyThirtyDaysReduceRate := zhios_order_relate_utils.StrToFloat64(chain.EveryThirtyDaysReduceRate) / 100 //每三十日递减发行百分比
nowEverydayPublishCoin := zhios_order_relate_utils.StrToFloat64(chain.NowEverydayPublishCoin) //当前每日区块币发行数量
chain.NowEverydayPublishCoin = zhios_order_relate_utils.Float64ToStrPrec10(nowEverydayPublishCoin * (1 - everyThirtyDaysReduceRate))
updateAffected, err := db.BlockStarChainUpdate(session, chain.Id, chain, "now_everyday_publish_coin")
if err != nil {
return err
}
if updateAffected == 0 {
err = errors.New("更新 block_star_chain 的 now_everyday_publish_coin 记录失败")
return err
}
//updateAffected, err := db.BlockStarChainUpdate(session, chain.Id, chain, "now_everyday_publish_coin")
//if err != nil {
// return err
//}
//if updateAffected == 0 {
// err = errors.New("更新 block_star_chain 的 now_everyday_publish_coin 记录失败")
// return err
//}
}
return nil
}


Loading…
Cancel
Save