From fd749fb39836ed5bed879e24f557b9842a04549f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 12 Jul 2024 17:21:25 +0800 Subject: [PATCH] 1 --- .../light_backtask/task/archived/dailyTask.go | 22 -- .../light_backtask/task/archived/formula.go | 94 -------- .../light_backtask/task/archived/hashRate.go | 179 --------------- .../task/archived/hourlyTask.go | 21 -- .../task/archived/seasonRanking.go | 151 ------------ .../task/gold_bullion_return.go | 110 --------- server/light_backtask/task/nftlock.go | 216 ------------------ .../task/spec_transfer721/gold_bullion.go | 129 ----------- .../task/spec_transfer721/hero.go | 104 --------- .../task/spec_transfer721/spec_transfer721.go | 80 ------- .../task/spec_transfer721/types.go | 10 - server/light_backtask/task/taskmgr.go | 25 -- 12 files changed, 1141 deletions(-) delete mode 100644 server/light_backtask/task/archived/dailyTask.go delete mode 100644 server/light_backtask/task/archived/formula.go delete mode 100644 server/light_backtask/task/archived/hashRate.go delete mode 100644 server/light_backtask/task/archived/hourlyTask.go delete mode 100644 server/light_backtask/task/archived/seasonRanking.go delete mode 100644 server/light_backtask/task/gold_bullion_return.go delete mode 100644 server/light_backtask/task/nftlock.go delete mode 100644 server/light_backtask/task/spec_transfer721/gold_bullion.go delete mode 100644 server/light_backtask/task/spec_transfer721/hero.go delete mode 100644 server/light_backtask/task/spec_transfer721/spec_transfer721.go delete mode 100644 server/light_backtask/task/spec_transfer721/types.go diff --git a/server/light_backtask/task/archived/dailyTask.go b/server/light_backtask/task/archived/dailyTask.go deleted file mode 100644 index cc619ad9..00000000 --- a/server/light_backtask/task/archived/dailyTask.go +++ /dev/null @@ -1,22 +0,0 @@ -package task - -import ( - "f5" - "fmt" - "q5" - "time" -) - -type DailyTaskMgr struct { - SeasonRankMgr -} - -func (this *DailyTaskMgr) Init() { - //sleepTime := f5.GetApp().GetNowDaySeconds() + 3600*24 - f5.GetApp().GetNowSeconds() - f5.GetTimer().SetInterval( - 1000*3600*24, - func(e int32, args *q5.Args) { - this.SeasonRankMgr.CalcRanking() - fmt.Printf("DailyTask.sleepTime:%v \n", time.Now()) - }) -} diff --git a/server/light_backtask/task/archived/formula.go b/server/light_backtask/task/archived/formula.go deleted file mode 100644 index 5fdbf979..00000000 --- a/server/light_backtask/task/archived/formula.go +++ /dev/null @@ -1,94 +0,0 @@ -package task - -import ( - "fmt" - "math" - "q5" -) - -func _xif(cond bool, trueVal int64, falseVal int64) int64 { - if cond { - return trueVal - } else { - return falseVal - } -} - -func _round(x float64, y int64) float64 { - var num float64 - if y == 0 { - num = math.Round(x) - } else { - //roundedNum := math.Round(x*100) / 100 - strFmt := "%." + q5.ToString(y) + "f" - result := fmt.Sprintf(strFmt, x) - num = q5.ToFloat64(result) - } - //t := q5.ToString(result) - return num -} - -func celTopX(ranking int64) int64 { - t := _xif(ranking > 0, 1, 0)*_xif(ranking <= 3, 1, 0)*1 + - _xif(ranking > 3, 1, 0)*_xif(ranking <= 10, 1, 0)*2 + - _xif(ranking > 10, 1, 0)*_xif(ranking <= 50, 1, 0)*3 + - _xif(ranking > 50, 1, 0)*_xif(ranking <= 100, 1, 0)*4 + - _xif(ranking > 100, 1, 0)*_xif(ranking <= 500, 1, 0)*5 + - _xif(ranking > 500, 1, 0)*_xif(ranking <= 1000, 1, 0)*6 + - _xif(ranking > 1000, 1, 0)*_xif(ranking <= 2000, 1, 0)*7 + - _xif(ranking > 2000, 1, 0)*_xif(ranking <= 5000, 1, 0)*8 + - _xif(ranking > 5000, 1, 0)*_xif(ranking <= 10000, 1, 0)*9 + - _xif(ranking > 10000, 1, 0)*10 - return t -} - -func celUserRankingPoint(ranking int64, topX int64) float64 { - //let XX = this.startTopX(topTd+1) ? this.startTopX(topTd+1):10001; - var x float64 - if topX > 9 { - x = 10001 - } else { - x = startTopX(topX + 1) - } - ////TopX排位赛标准分配额=MAX(ROUND(TopX梯队最高值-(TopX梯队最高值-TopX梯队最低值)/(TopX梯队开始值(TopX梯队+1)-TopX梯队开始值-1)*(TopX-TopX梯队开始值),2),TopX梯队最低值) - //return Math.max(jsRound(this.maxTopX(topTd)-(this.maxTopX(topTd)-this.minTopX(topTd))/(XX-this.startTopX(topTd)-1)*(top-this.startTopX(topTd)),2),this.minTopX(topTd)); - t := maxTopX(topX) - (maxTopX(topX)-minTopX(topX))/ - (x-startTopX(topX)-1)* - (q5.ToFloat64(ranking)-startTopX(topX)) - return math.Max(_round(t, 2), minTopX(topX)) -} - -func startTopX(topX int64) float64 { - t := _xif(topX == 1, 1, 0)*1 + - _xif(topX == 2, 1, 0)*4 + - _xif(topX == 3, 1, 0)*11 + - _xif(topX == 4, 1, 0)*51 + - _xif(topX == 5, 1, 0)*101 + - _xif(topX == 6, 1, 0)*501 + - _xif(topX == 7, 1, 0)*1001 + - _xif(topX == 8, 1, 0)*2001 + - _xif(topX == 9, 1, 0)*5001 + - _xif(topX == 10, 1, 0)*10001 - return q5.ToFloat64(t) -} - -func maxTopX(topX int64) float64 { - //TopX梯队最高值=ROUND(20000*0.6^(TopX梯队-1)*0.8*0.9^(TopX梯队-1),0) - //return jsRound(20000 * Math.pow(0.6,topTd-1) * 0.8 * Math.pow(0.9,topTd-1),0); - t := 20000 * math.Pow(0.6, q5.ToFloat64(topX-1)) * 0.8 * math.Pow(0.9, q5.ToFloat64(topX-1)) - return _round(t, 0) -} - -func minTopX(topX int64) float64 { - //TopX梯队最低值=ROUND(20000*0.6^(TopX梯队)*0.8*0.9^(TopX梯队-1),0) - //return jsRound(20000 * Math.pow(0.6,topTd) * 0.8 * Math.pow(0.9,topTd-1),0); - t := 20000 * math.Pow(0.6, q5.ToFloat64(topX)) * 0.8 * math.Pow(0.9, q5.ToFloat64(topX-1)) - return _round(t, 0) -} - -func ceilEx(number float64, decimals float64) float64 { - intPart := math.Floor(number) - floatPart := number - intPart - finallyFloatPart := math.Ceil(floatPart*math.Pow(q5.ToFloat64(10), decimals)) / math.Pow(q5.ToFloat64(10), decimals) - return intPart + finallyFloatPart -} diff --git a/server/light_backtask/task/archived/hashRate.go b/server/light_backtask/task/archived/hashRate.go deleted file mode 100644 index dfa18071..00000000 --- a/server/light_backtask/task/archived/hashRate.go +++ /dev/null @@ -1,179 +0,0 @@ -package task - -import ( - "f5" - "fmt" - "main/constant" - "mt" - "q5" -) - -type HashRateMgr struct { - totalPowerNumber float64 - period int32 - hashRateMate *mt.HashRateCommon -} - -func (this *HashRateMgr) CalPowerByCECReward() { - this.hashRateMate = mt.Table.HashRateCommon.GetLatestPeriod() - this.period = this.hashRateMate.GetId() - var totalPower float64 = 0 - f5.NewAsyncTask( - func(task *f5.AsyncTask) { - sql := fmt.Sprintf("SELECT * FROM t_power_exchange_record WHERE period = %d", - this.period) - f5.GetJsStyleDb().SelectCustomQuery( - constant.GAME_DB, - sql, - func(err error, rows *f5.DataSet) { - if err != nil { - task.SetFail() - f5.GetSysLog().Error("HashRateMgr Error1:%v \n", err) - return - } - for rows.Next() { - totalPower += q5.ToFloat64(rows.GetByName("total_num")) - } - if rows.NumOfReaded() <= 0 { - task.SetFail() - } else { - task.SetSucc() - } - }, - ) - }, - ).OnSucc( - func(task *f5.AsyncTask) { - if totalPower != 0 { - this.totalPowerNumber = totalPower - this.getAccountGroup() - } - }).OnFail( - func(task *f5.AsyncTask) { - fmt.Printf("Cal Fail") - }) -} -func (this *HashRateMgr) getAccountGroup() { - accountIds := []string{} - f5.NewAsyncTask( - func(task *f5.AsyncTask) { - sql := fmt.Sprintf("SELECT account_id,`period` FROM t_power_exchange_record WHERE period = %d group by account_id", - this.period) - f5.GetJsStyleDb().SelectCustomQuery( - constant.GAME_DB, - sql, - func(err error, rows *f5.DataSet) { - if err != nil { - task.SetFail() - f5.GetSysLog().Error("HashRateMgr Error2:%v \n", err) - return - } - for rows.Next() { - accountId := rows.GetByName("account_id") - accountIds = append(accountIds, accountId) - } - task.SetSucc() - }, - ) - }).OnSucc( - func(task *f5.AsyncTask) { - this.checkAccountIsSettle(accountIds) - }).OnFail( - func(task *f5.AsyncTask) { - }) -} - -func (this *HashRateMgr) checkAccountIsSettle(param []string) { - var index = 0 - f5.NewAsyncTask( - func(task *f5.AsyncTask) { - if index >= len(param) { - task.SetSucc() - return - } - f5.GetJsStyleDb().OrmSelectOne( - constant.GAME_DB, - "t_hash_rate_reward", - [][]string{ - {"account_id", q5.ToString(param[index])}, - {"period", q5.ToString(this.period)}, - }, - func(err error, row *f5.DataSet) { - - if err != nil { - f5.GetSysLog().Error("HashRateMgr Error3:%v \n", err) - task.SetFail() - return - } - if row.Next() { - index += 1 - task.Continue() - } else { - //结算操作 - this.getOwnerPower(param[index], func(ownerPower float64) { - target := ceilEx(q5.Min(this.totalPowerNumber/q5.ToFloat64(this.hashRateMate.GetCecPool()), 1), 6) - ratio := ownerPower / this.totalPowerNumber - cecNUm := ceilEx(q5.ToFloat64(this.hashRateMate.GetCecPool())*target*ratio, 2) - this.pushHashRateReward(param[index], cecNUm) - index += 1 - task.Continue() - }) - } - }) - }).OnSucc( - func(task *f5.AsyncTask) { - }).OnFail( - func(task *f5.AsyncTask) { - }) -} - -func (this *HashRateMgr) getOwnerPower(account string, cb func(param float64)) { - var ownerPower float64 = 0 - f5.NewAsyncTask(func(task *f5.AsyncTask) { - sql1 := fmt.Sprintf("SELECT * FROM t_power_exchange_record WHERE account_id = '%s' AND period = %d", - account, - this.period) - - f5.GetJsStyleDb().SelectCustomQuery( - constant.GAME_DB, - sql1, - func(err error, rows *f5.DataSet) { - if err != nil { - task.SetFail() - f5.GetSysLog().Error("HashRateMgr Error4:%v \n", err) - return - } - for rows.Next() { - ownerPower += q5.ToFloat64(rows.GetByName("total_num")) - } - task.SetSucc() - }, - ) - }).OnSucc(func(task *f5.AsyncTask) { - cb(ownerPower) - }).OnFail(func(task *f5.AsyncTask) { - }) -} - -func (this *HashRateMgr) pushHashRateReward(account string, num float64) { - fields := [][]string{ - {"account_id", account}, - //q5.GenFieldKvEmptyAsNull("address", v.address), - {"address", q5.ToString("test123456789")}, - {"period", q5.ToString(this.period)}, - {"reward_cec", q5.ToString(num)}, - {"createtime", q5.ToString(f5.GetApp().GetNowSeconds())}, - {"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())}, - } - f5.GetJsStyleDb().Insert( - constant.GAME_DB, - "t_hash_rate_reward", - fields, - func(err error, id int64, affectedRows int64) { - if err != nil || affectedRows != 1 { - // 插入失败,处理错误逻辑 - f5.GetSysLog().Error("HashRateMgr Error5:%v \n", err) - } - }, - ) -} diff --git a/server/light_backtask/task/archived/hourlyTask.go b/server/light_backtask/task/archived/hourlyTask.go deleted file mode 100644 index 78275f28..00000000 --- a/server/light_backtask/task/archived/hourlyTask.go +++ /dev/null @@ -1,21 +0,0 @@ -package task - -import ( - "f5" - "fmt" - "q5" - "time" -) - -type HourlyTaskMgr struct { - HashRateMgr -} - -func (this *HourlyTaskMgr) Init() { - f5.GetTimer().SetInterval( - 1000*3600, - func(e int32, args *q5.Args) { - this.HashRateMgr.CalPowerByCECReward() - fmt.Printf("HourlyTask.sleepTime:%v \n", time.Now()) - }) -} diff --git a/server/light_backtask/task/archived/seasonRanking.go b/server/light_backtask/task/archived/seasonRanking.go deleted file mode 100644 index cfd04281..00000000 --- a/server/light_backtask/task/archived/seasonRanking.go +++ /dev/null @@ -1,151 +0,0 @@ -package task - -import ( - "f5" - "fmt" - "main/constant" - "math" - "mt" - "q5" - "sort" -) - -type userDb struct { - idx int64 - account_id string - address string - channel int32 - rank int32 - score int32 - score_modifytime int64 -} - -type sortUserDb []userDb - -func (this sortUserDb) Len() int { - return len(this) -} - -func (this sortUserDb) Swap(i, j int) { - this[i], this[j] = this[j], this[i] -} - -func (this sortUserDb) Less(i, j int) bool { - if this[i].score == this[j].score { - if this[i].score_modifytime == this[j].score_modifytime { - return this[i].idx < this[j].idx - } else { - return this[i].score_modifytime < this[j].score_modifytime - } - } else { - return this[i].score > this[j].score - } -} - -type SeasonRankMgr struct { -} - -func (this *SeasonRankMgr) CalcRanking() { - seasonMt := mt.Table.RankSeason.GetCurrentSeason() - season := mt.Table.RankSeason.GetLastSeason() - f5.GetJsStyleDb().OrmSelectOne( - constant.GAME_DB, - "t_season_ranking", - [][]string{ - {"season", q5.ToString(season.GetId())}, - }, - func(err error, row *f5.DataSet) { - if err != nil { - f5.GetSysLog().Error("SeasonRankMgr Error1:%v \n", err) - return - } - row.Next() - if row.NumOfReaded() <= 0 && seasonMt == nil { - fmt.Println("OK") - this.goGetUsersRecords() - } - }) -} - -func (this *SeasonRankMgr) goGetUsersRecords() { - userHash := make(map[int64]*userDb) - userList := []userDb{} - var lastIdx int64 = 0 - f5.NewAsyncTask( - func(task *f5.AsyncTask) { - sql := fmt.Sprintf("SELECT * FROM t_user WHERE idx > %d AND score >= %d LIMIT %d", - lastIdx, - constant.BASE_SCORE, - 1000) - f5.GetJsStyleDb().SelectCustomQuery( - constant.GAME_DB, - sql, - func(err error, rows *f5.DataSet) { - if err != nil { - task.SetFail() - f5.GetSysLog().Error("SeasonRankMgr Error2:%v \n", err) - return - } - for rows.Next() { - user := userDb{} - user.idx = q5.ToInt64(rows.GetByName("idx")) - user.account_id = q5.ToString(rows.GetByName("account_id")) - user.address = q5.ToString(rows.GetByName("address")) - user.channel = q5.ToInt32(rows.GetByName("channel")) - user.rank = q5.ToInt32(rows.GetByName("rank")) - user.score = q5.ToInt32(rows.GetByName("score")) - user.score_modifytime = q5.ToInt64(rows.GetByName("score_modifytime")) - userHash[user.idx] = &user - userList = append(userList, user) - if user.idx > lastIdx { - lastIdx = user.idx - } - f5.GetSysLog().Info("get User:%s \n", user.idx) - } - task.SetSucc() - }, - ) - }).OnSucc( - func(task *f5.AsyncTask) { - if userList != nil { - sort.Sort(sortUserDb(userList)) - this.pushRankingResult(userList) - } - }).OnFail( - func(task *f5.AsyncTask) { - f5.GetSysLog().Error("SeasonRankMgr Error3 \n") - return - }) -} - -func (this *SeasonRankMgr) pushRankingResult(record []userDb) { - for i, v := range record { - ranking := i + 1 - topX := celTopX(q5.ToInt64(ranking)) - point := math.Round(celUserRankingPoint(q5.ToInt64(ranking), topX)) - fields := [][]string{ - {"ranking", q5.ToString(ranking)}, - {"ranking_point", q5.ToString(point)}, - {"account_id", v.account_id}, - q5.GenFieldKvEmptyAsNull("address", v.address), - {"channel", q5.ToString(v.channel)}, - {"rank", q5.ToString(v.rank)}, - {"score", q5.ToString(v.score)}, - {"season", q5.ToString(2)}, - {"createtime", q5.ToString(f5.GetApp().GetNowSeconds())}, - {"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())}, - } - //f5.GetJsStyleDb().Insert( - // constant.GAME_DB, - // "t_season_ranking", - // fields, - // func(err error, id int64, affectedRows int64) { - // if err != nil || affectedRows != 1 { - // // 插入失败,处理错误逻辑 - // fmt.Printf("Failed to insert t_season_ranking: %v", err) - // } - // }, - //) - f5.GetSysLog().Info("ranking:%v", fields) - } -} diff --git a/server/light_backtask/task/gold_bullion_return.go b/server/light_backtask/task/gold_bullion_return.go deleted file mode 100644 index d9624eef..00000000 --- a/server/light_backtask/task/gold_bullion_return.go +++ /dev/null @@ -1,110 +0,0 @@ -package task - -import ( - "q5" - "f5" - "mt" - "jccommon" - "fmt" - "main/constant" - "main/service" -) - -type goldBullionReturn struct { - -} - -func (this* goldBullionReturn) init() { - go this.loadExpiredGoldBullion() -} - -func (this* goldBullionReturn) unInit() { -} - -func (this* goldBullionReturn) loadExpiredGoldBullion() { - f5.GetGoStyleDb().LoopLoad( - constant.GAME_DB, - "goldBullionReturn", - "t_gold_bullion", - func () int64 { - return 60 * 5 - }, - func (lastIdx int64) string { - nowTime := f5.GetApp().GetRealSeconds() - expiredTime := nowTime - 3600 * 24 - 3600 - sql := fmt.Sprintf(` -SELECT * FROM t_gold_bullion -WHERE idx > %d AND activated = 0 AND returned = 0 AND status=%d AND createtime < %d LIMIT 100`, - lastIdx, - jccommon.GOLD_BULLION_NO_OPEN, - expiredTime) - return sql - }, - []string{ - }, - func () int64 { - return 10 - }, - func () int64 { - return 60 * 5 - }, - this.returnGold) -} - -func (this* goldBullionReturn) returnGold(ds *f5.DataSet) bool { - netId := q5.ToInt32(ds.GetByName("net_id")) - contractMeta := mt.Table.Contract.GetByNetIdName(netId, jccommon.CONTRACT_NAME_GoldBrick) - if contractMeta == nil { - return true - } - accountId := ds.GetByName("src_account_id") - if accountId == "" { - return true - } - contractAddress := contractMeta.GetAddress() - tokenId := ds.GetByName("token_id") - f5.GetSysLog().Info("returnGold net:%d accountId:%s contract_address:%s tokenId: %s", - netId, accountId, contractAddress, tokenId) - { - rspObj := struct { - Result struct { - TokenId string `json:"token_id"` - } `json:"result"` - }{} - url := fmt.Sprintf("%s/v1/chains/%s/collections/%s/nfts/%s", - mt.Table.Config.GetById(0).GetImmutableBaseUrl(), - mt.Table.Config.GetById(0).GetChainName(), - contractAddress, - tokenId) - rsp, data, err := q5.HttpGetEx2(url, map[string]string{}) - if err != nil { - f5.GetSysLog().Info("returnGold immutable api:%s request error:%s", - url, - err) - return true - } - f5.GetSysLog().Info("returnGold immutable api:%s statusCode:%d body:%s", - url, - rsp.StatusCode, - data) - if rsp.StatusCode != 404 { - return true - } - if rsp.StatusCode == 200 { - if err := q5.DecodeJson(data, &rspObj); err != nil { - f5.GetSysLog().Info("returnGold immutable api:%s decodeJson error:%s", - url, - err) - return true - } - if rspObj.Result.TokenId == tokenId { - f5.GetSysLog().Info("returnGold tokenId:%s exists", - tokenId) - return true - } - } - - } - service.ReturnGoldBullion(accountId, netId, tokenId) - return true -} diff --git a/server/light_backtask/task/nftlock.go b/server/light_backtask/task/nftlock.go deleted file mode 100644 index 3a1af0f9..00000000 --- a/server/light_backtask/task/nftlock.go +++ /dev/null @@ -1,216 +0,0 @@ -package task - -import ( - "q5" - "f5" - "fmt" - "strings" - "mt" - "jccommon" - "main/constant" - "main/service" - "math/rand" -) - -type lockReturnValues struct { - Nft string `json:"nft"` - Sender string `json:"sender"` - To string `json:"to"` - TokenIds []string `json:"tokenIds"` -} - -type nftLock struct { - mailCfgHash *q5.ConcurrentMap[string, *jccommon.MailConfig] -} - -func (this* nftLock) init() { - this.mailCfgHash = new(q5.ConcurrentMap[string, *jccommon.MailConfig]) - this.registerMailConfig(constant.MAIL_GOLD_BULLION_LOCK, - jccommon.MAIL_TAG1_GOLD_BULLION, - jccommon.MAIL_TAG2_GOLD_BULLION_LOCK) - go this.process() -} - -func (this* nftLock) unInit() { -} - -func (this* nftLock) process() { - f5.GetGoStyleDb().LoopLoad( - constant.BCEVENT_DB, - "nftLock", - "t_nft_lock_event", - func () int64 { - return 3 - }, - func (lastIdx int64) string { - sql := fmt.Sprintf(` -SELECT * FROM t_nft_lock_event WHERE idx > %d AND (nft_sync_status = 0 OR nft_use_status = 0) LIMIT 100`, - lastIdx, - ) - return sql - }, - []string{ - }, - func () int64 { - return 3 - }, - func () int64 { - return 60 + q5.ToInt64(rand.Intn(3)) - }, - this.repair) -} - -func (this* nftLock) repair(ds *f5.DataSet) bool { - nftSyncStatus := q5.ToInt32(ds.GetByName("nft_sync_status")) - nftUseStatus := q5.ToInt32(ds.GetByName("nft_use_status")) - netId := q5.ToInt32(ds.GetByName("net_id")) - idx := q5.ToInt64(ds.GetByName("idx")) - lockTo := ds.GetByName("lock_to") - if nftSyncStatus == 0 && lockTo != "" { - p := new(lockReturnValues) - if q5.DecodeJson(ds.GetByName("return_values"), p) == nil { - for _, val := range p.TokenIds { - contractAddress := strings.ToLower(p.Nft) - tokenId := val - if service.NftExists(netId, contractAddress, tokenId) { - service.NftUpdateLock(netId, contractAddress, tokenId, idx, lockTo) - } - } - } - } - if nftUseStatus == 0 { - p := new(lockReturnValues) - if q5.DecodeJson(ds.GetByName("return_values"), p) == nil { - this.useNft(idx, netId, lockTo, p) - } - } - return true -} - -func (this *nftLock) useNft(dbIdx int64, netId int32, lockTo string, p *lockReturnValues) { - lockTo = strings.ToLower(lockTo) - contractAddress := strings.ToLower(p.Nft) - - goldMeta := mt.Table.Contract.GetByNetIdName(netId, jccommon.CONTRACT_NAME_GoldBrick) - if goldMeta == nil { - return - } - if contractAddress != strings.ToLower(goldMeta.GetAddress()) { - f5.GetGoStyleDb().Update( - constant.BCEVENT_DB, - "t_nft_lock_event", - [][]string { - {"idx", q5.ToString(dbIdx)}, - }, - [][]string { - {"nft_use_status", q5.ToString(1)}, - }, - func (err error, lastInsertId int64, rowsAffected int64) { - }) - return - } - accountId := service.GetAccountIdByAddress(lockTo) - if accountId == "" { - return - } - ok := true - for _, tokenId := range p.TokenIds { - var itemId int32 - if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) { - if service.OpenGoldBullion(accountId, lockTo, netId, tokenId) { - if this.internalSendMail(dbIdx, lockTo, constant.MAIL_GOLD_BULLION_LOCK, tokenId) { - - } else { - ok = false - break - } - } else { - ok = false - break - } - } else { - ok = false - break - } - } - if ok { - f5.GetGoStyleDb().Update( - constant.BCEVENT_DB, - "t_nft_lock_event", - [][]string { - {"idx", q5.ToString(dbIdx)}, - }, - [][]string { - {"nft_use_status", q5.ToString(1)}, - }, - func (err error, lastInsertId int64, rowsAffected int64) { - }) - } -} - -func (this* nftLock) internalSendMail(dbIdx int64, accountAddress string, mailName string, tokenId string) bool { - var itemId int32 - if !service.GetGoldBullionItemIdByTokenId(tokenId, &itemId) { - return true - } - goldNum := jccommon.GetGoldBullionGoldNum(itemId) - goldNumStr := this.formatGoldNum(goldNum) - itemMeta := mt.Table.Item.GetById(q5.ToInt64(itemId)) - if itemMeta == nil { - return true - } - accountId := service.GetAccountIdByAddress(accountAddress) - if accountId == "" { - return true - } - mailMeta := mt.Table.Mail.GetByName(mailName) - if mailMeta == nil { - return true - } - mailCfg := this.getMailConfig(mailName) - if mailCfg == nil { - return true - } - nowTime := f5.GetApp().GetRealSeconds() - subject := mailMeta.GetTitle() - content := mailMeta.ReplaceContent(map[string]string{ - "${item.name}": itemMeta.GetRealName(), - "${gold}": goldNumStr, - }) - uniKey := fmt.Sprintf("%s_%s_%d", mailName, tokenId, dbIdx) - sendOk := service.SendSysMail( - uniKey, - accountId, - subject, - content, - q5.ToInt32(nowTime), - q5.ToInt32(nowTime) + 3600 * 24 * 7, - mailCfg.Tag1, - mailCfg.Tag2) - return sendOk -} - -func (this *nftLock) formatGoldNum(goldNum int32) string { - if goldNum == 1000 { - return "1,000" - } else if goldNum == 10000 { - return "10,000" - } - return q5.ToString(goldNum) -} - -func (this *nftLock) getMailConfig(mailName string) *jccommon.MailConfig { - if v, ok := this.mailCfgHash.Load(mailName); ok { - return *v - } else { - return nil - } -} - -func (this *nftLock) registerMailConfig(mailName string, tag1 int32, tag2 int32) { - p := new(jccommon.MailConfig) - p.MailName = mailName - p.Tag1 = tag1 - p.Tag2 = tag2 - this.mailCfgHash.Store(mailName, p) -} diff --git a/server/light_backtask/task/spec_transfer721/gold_bullion.go b/server/light_backtask/task/spec_transfer721/gold_bullion.go deleted file mode 100644 index 11b9684a..00000000 --- a/server/light_backtask/task/spec_transfer721/gold_bullion.go +++ /dev/null @@ -1,129 +0,0 @@ -package spec_transfer721 - -import ( - "q5" - "f5" - "main/service" - "main/constant" - "mt" - "jccommon" - "fmt" -) - -type goldBullion struct { - mailCfgHash *q5.ConcurrentMap[string, *jccommon.MailConfig] -} - -func (this* goldBullion) onMint(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool { - ok := this.internalSendMail(dbIdx, to, constant.MAIL_GOLD_BULLION_MINT, tokenId) - return ok -} - -func (this* goldBullion) onLock(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool { - /* - ok := this.internalSendMail(dbIdx, from, constant.MAIL_GOLD_BULLION_LOCK, tokenId) - return ok - */ - return true -} - -func (this *goldBullion) onUnlock(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool { - accountAddress := to - accountId := service.GetAccountIdByAddress(accountAddress) - if accountId == "" { - return false - } - { - - } - /* - goldDb := service.GetGoldBullionByTokenId(tokenId) - if goldDb == nil { - return false - }*/ - ok := this.internalSendMail(dbIdx, to, constant.MAIL_GOLD_BULLION_UNLOCK, tokenId) - return ok -} - -func (this* goldBullion) internalSendMail(dbIdx int64, accountAddress string, mailName string, tokenId string) bool { - var itemId int32 - if !service.GetGoldBullionItemIdByTokenId(tokenId, &itemId) { - return true - } - goldNum := jccommon.GetGoldBullionGoldNum(itemId) - goldNumStr := this.formatGoldNum(goldNum) - itemMeta := mt.Table.Item.GetById(q5.ToInt64(itemId)) - if itemMeta == nil { - return true - } - accountId := service.GetAccountIdByAddress(accountAddress) - if accountId == "" { - return true - } - mailMeta := mt.Table.Mail.GetByName(mailName) - if mailMeta == nil { - return true - } - mailCfg := this.getMailConfig(mailName) - if mailCfg == nil { - return true - } - nowTime := f5.GetApp().GetRealSeconds() + 3600 * 24 * 7 - subject := mailMeta.GetTitle() - content := mailMeta.ReplaceContent(map[string]string{ - "${item.name}": itemMeta.GetRealName(), - "${gold}": goldNumStr, - }) - uniKey := fmt.Sprintf("%s_%s_%d", mailName, tokenId, dbIdx) - sendOk := service.SendSysMail( - uniKey, - accountId, - subject, - content, - q5.ToInt32(nowTime), - q5.ToInt32(nowTime), - mailCfg.Tag1, - mailCfg.Tag2) - if sendOk { - return service.UpdateSpecTransferStatus(dbIdx, 1) - } - return false -} - -func (this *goldBullion) getMailConfig(mailName string) *jccommon.MailConfig { - if v, ok := this.mailCfgHash.Load(mailName); ok { - return *v - } else { - return nil - } -} - -func (this *goldBullion) registerMailConfig(mailName string, tag1 int32, tag2 int32) { - p := new(jccommon.MailConfig) - p.MailName = mailName - p.Tag1 = tag1 - p.Tag2 = tag2 - this.mailCfgHash.Store(mailName, p) -} - -func (this *goldBullion) formatGoldNum(goldNum int32) string { - return "" -} - -func newGoldBullion() *goldBullion { - p := new(goldBullion) - p.mailCfgHash = new(q5.ConcurrentMap[string, *jccommon.MailConfig]) - p.registerMailConfig(constant.MAIL_GOLD_BULLION_MINT, - jccommon.MAIL_TAG1_GOLD_BULLION, - jccommon.MAIL_TAG2_GOLD_BULLION_MINT) - p.registerMailConfig(constant.MAIL_GOLD_BULLION_LOCK, - jccommon.MAIL_TAG1_GOLD_BULLION, - jccommon.MAIL_TAG2_GOLD_BULLION_LOCK) - p.registerMailConfig(constant.MAIL_GOLD_BULLION_UNLOCK, - jccommon.MAIL_TAG1_GOLD_BULLION, - jccommon.MAIL_TAG2_GOLD_BULLION_UNLOCK) - return p -} diff --git a/server/light_backtask/task/spec_transfer721/hero.go b/server/light_backtask/task/spec_transfer721/hero.go deleted file mode 100644 index dcc1395d..00000000 --- a/server/light_backtask/task/spec_transfer721/hero.go +++ /dev/null @@ -1,104 +0,0 @@ -package spec_transfer721 - -import ( - "q5" - "f5" - "main/service" - "main/constant" - "mt" - "jccommon" - "fmt" -) - -type hero struct { - mailCfgHash *q5.ConcurrentMap[string, *jccommon.MailConfig] -} - -func (this* hero) onMint(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool { - if jccommon.IsAirDropNft(tokenId) { - return service.UpdateSpecTransferStatus(dbIdx, 1) - } - ok := this.internalSendMail(dbIdx, to, constant.MAIL_HERO_MINT, tokenId) - return ok -} - -func (this* hero) onLock(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool { - ok := this.internalSendMail(dbIdx, from, constant.MAIL_HERO_LOCK, tokenId) - return ok -} - -func (this *hero) onUnlock(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool { - ok := this.internalSendMail(dbIdx, to, constant.MAIL_HERO_UNLOCK, tokenId) - return ok -} - -func (this* hero) internalSendMail(dbIdx int64, accountAddress string, mailName string, tokenId string) bool { - var itemId, heroQuality int32 - if !service.GetHeroByTokenId(tokenId, &itemId, &heroQuality) { - return true - } - itemMeta := mt.Table.Item.GetById(q5.ToInt64(itemId)) - if itemMeta == nil { - return true - } - accountId := service.GetAccountIdByAddress(accountAddress) - if accountId == "" { - return true - } - mailMeta := mt.Table.Mail.GetByName(mailName) - if mailMeta == nil { - return true - } - mailCfg := this.getMailConfig(mailName) - if mailCfg == nil { - return true - } - nowTime := f5.GetApp().GetRealSeconds() + 3600 * 24 * 7 - subject := mailMeta.GetTitle() - content := mailMeta.ReplaceContent(map[string]string{ - "${hero.name}": itemMeta.GetRealName(), - "${hero.quality}": q5.ToString(heroQuality), - }) - uniKey := fmt.Sprintf("%s_%s_%d", mailName, tokenId, dbIdx) - sendOk := service.SendSysMail( - uniKey, - accountId, - subject, - content, - q5.ToInt32(nowTime), - q5.ToInt32(nowTime), - mailCfg.Tag1, - mailCfg.Tag2) - if sendOk { - return service.UpdateSpecTransferStatus(dbIdx, 1) - } - return false -} - -func (this *hero) getMailConfig(mailName string) *jccommon.MailConfig { - if v, ok := this.mailCfgHash.Load(mailName); ok { - return *v - } else { - return nil - } -} - -func (this *hero) registerMailConfig(mailName string, tag1 int32, tag2 int32) { - p := new(jccommon.MailConfig) - p.MailName = mailName - p.Tag1 = tag1 - p.Tag2 = tag2 - this.mailCfgHash.Store(mailName, p) -} - -func newHero() *hero { - p := new(hero) - p.mailCfgHash = new(q5.ConcurrentMap[string, *jccommon.MailConfig]) - p.registerMailConfig(constant.MAIL_HERO_MINT, jccommon.MAIL_TAG1_HERO, jccommon.MAIL_TAG2_HERO_MINT) - p.registerMailConfig(constant.MAIL_HERO_LOCK, jccommon.MAIL_TAG1_HERO, jccommon.MAIL_TAG2_HERO_LOCK) - p.registerMailConfig(constant.MAIL_HERO_UNLOCK, jccommon.MAIL_TAG1_HERO, jccommon.MAIL_TAG2_HERO_UNLOCK) - return p -} diff --git a/server/light_backtask/task/spec_transfer721/spec_transfer721.go b/server/light_backtask/task/spec_transfer721/spec_transfer721.go deleted file mode 100644 index 3e05d0bd..00000000 --- a/server/light_backtask/task/spec_transfer721/spec_transfer721.go +++ /dev/null @@ -1,80 +0,0 @@ -package spec_transfer721 - -import ( - "q5" - "f5" - "fmt" - "mt" - "jccommon" - "main/constant" - "math/rand" -) - -type SpecTransfer721 struct { - handleHash *q5.ConcurrentMap[string, specTransfer721Handle] -} - -func (this* SpecTransfer721) Init() { - return - this.handleHash = new(q5.ConcurrentMap[string, specTransfer721Handle]) - this.handleHash.Store(jccommon.CONTRACT_NAME_CFHero, newHero()) - //this.handleHash.Store(jccommon.CONTRACT_NAME_GoldBrick, newGoldBullion()) - go this.process() -} - -func (this* SpecTransfer721) UnInit() { -} - -func (this* SpecTransfer721) process() { - f5.GetGoStyleDb().LoopLoad( - constant.BCEVENT_DB, - "t_721nft_spec_transfer", - "t_721nft_spec_transfer", - func () int64 { - return 3 + q5.ToInt64(rand.Intn(2)) - }, - func (lastIdx int64) string { - nowTime := f5.GetApp().GetRealSeconds() - expiredTime := nowTime - 3600 * 24 * 7 - sql := fmt.Sprintf(` -SELECT * FROM t_721nft_spec_transfer WHERE idx > %d AND status = 0 AND createtime > %d LIMIT 1000 -`, - lastIdx, - expiredTime) - return sql - }, - []string{ - }, - func () int64{ - return 3 - }, - func () int64 { - return 60 * 1 - }, - this.dispatch) -} - -func (this* SpecTransfer721) dispatch(ds *f5.DataSet) bool { - idx := q5.ToInt64(ds.GetByName("idx")) - netId := q5.ToInt32(ds.GetByName("net_id")) - contractAddress := ds.GetByName("contract_address") - tokenId := ds.GetByName("token_id") - fromAddress := ds.GetByName("from_address") - toAddress := ds.GetByName("to_address") - contractMeta := mt.Table.Contract.GetByNetIdAddress(netId, contractAddress) - nftLockMeta := mt.Table.Contract.GetByNetIdName(netId, jccommon.CONTRACT_NAME_NFTLock) - if contractMeta != nil { - if p, ok := this.handleHash.Load(contractMeta.GetName()); ok { - if q5.IsWeb3ZeroAddress(fromAddress) { - return (*p).onMint(idx, netId, contractAddress, tokenId, fromAddress, toAddress) - } else if nftLockMeta != nil { - if toAddress == nftLockMeta.GetAddress() { - return (*p).onLock(idx, netId, contractAddress, tokenId, fromAddress, toAddress) - } else if fromAddress == nftLockMeta.GetAddress() { - return (*p).onUnlock(idx, netId, contractAddress, tokenId, fromAddress, toAddress) - } - } - } - } - return false -} diff --git a/server/light_backtask/task/spec_transfer721/types.go b/server/light_backtask/task/spec_transfer721/types.go deleted file mode 100644 index b26dc1ea..00000000 --- a/server/light_backtask/task/spec_transfer721/types.go +++ /dev/null @@ -1,10 +0,0 @@ -package spec_transfer721 - -type specTransfer721Handle interface { - onMint(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool - onLock(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool - onUnlock(dbIdx int64, netId int32, contractAddress string, tokenId string, - from string, to string) bool -} diff --git a/server/light_backtask/task/taskmgr.go b/server/light_backtask/task/taskmgr.go index 10c859a9..629746a4 100644 --- a/server/light_backtask/task/taskmgr.go +++ b/server/light_backtask/task/taskmgr.go @@ -1,53 +1,28 @@ package task import ( - //"fmt" - "sync" - //"main/task/spec_transfer721" ) type taskMgr struct { - //HourlyTaskMgr - //DailyTaskMgr webHook - goldBullionReturn - //spec_transfer721.SpecTransfer721 repairNft - openGoldLock sync.Mutex sysMail repairOrder refreshMeta - nftLock } func (this *taskMgr) Init() { - //t.HourlyTaskMgr.Init() - //t.DailyTaskMgr.Init() this.webHook.init() - this.goldBullionReturn.init() - //this.SpecTransfer721.Init() this.repairNft.init() this.sysMail.init() this.repairOrder.init() //this.refreshMeta.init() - this.nftLock.init() } func (this *taskMgr) UnInit() { - this.nftLock.unInit() //this.refreshMeta.unInit() this.repairOrder.unInit() this.sysMail.unInit() this.repairNft.unInit() - //this.SpecTransfer721.UnInit() - this.goldBullionReturn.unInit() this.webHook.unInit() } - -func (this *taskMgr) LockOpenGodBullion() { - this.openGoldLock.Lock() -} - -func (this *taskMgr) UnLockOpenGodBullion() { - this.openGoldLock.Unlock() -}