Eric0718 2 éve
szülő
commit
cea14cb0e4

+ 5 - 0
blockchain/participate.go

@@ -0,0 +1,5 @@
+package blockchain
+
+func participate() {
+
+}

+ 129 - 0
blockchain/scan.go

@@ -0,0 +1,129 @@
+package blockchain
+
+import (
+	"context"
+	"fmt"
+	"ktogame/contractgo/Collect"
+	"ktogame/dbUtil"
+	"ktogame/models"
+	"os"
+	"strings"
+	"time"
+
+	"github.com/astaxie/beego"
+	"github.com/astaxie/beego/logs"
+	"github.com/ethereum/go-ethereum/accounts/abi"
+
+	utilAddress "github.com/korthochain/korthochain/pkg/address"
+	"github.com/korthochain/korthochain/pkg/block"
+	pb "github.com/korthochain/korthochain/pkg/server/grpcserver/message"
+	"github.com/korthochain/korthochain/pkg/transaction"
+	"google.golang.org/grpc"
+)
+
+var ktoClient pb.GreeterClient
+var ktoRpc = beego.AppConfig.String("hostHttp_mit_kto")
+var currentBlock uint64
+
+var TopsMap map[string]string
+
+func init() {
+	kc, err := grpc.Dial(ktoRpc, grpc.WithInsecure(), grpc.WithBlock())
+	if err != nil {
+		logs.Info(err)
+		os.Exit(1)
+	}
+	ktoClient = pb.NewGreeterClient(kc)
+	utilAddress.SetNetWork("mainnet")
+
+	tm := make(map[string]string, 0)
+	tm[TopicParticipate] = COLLECT_PARTICIPATE
+	TopsMap = tm
+
+	go scanBlock()
+}
+
+func scanBlock() {
+	time.Sleep(time.Second * 2)
+	var bi models.BlockInfo
+	ok, err := dbUtil.Engine.Id(1).Get(&bi)
+	if err != nil {
+		fmt.Println("获取最新快高错误=", err)
+		return
+	}
+	if !ok {
+		fmt.Println("获取最新快高失败!")
+		return
+	}
+	currentBlock = uint64(bi.BlockNumber) + 1
+	//currentBlock =62203394
+	for {
+		time.Sleep(time.Second * 5)
+		res, err := ktoClient.GetMaxBlockHeight(context.Background(), &pb.ReqMaxBlockHeight{})
+		if err != nil {
+			fmt.Println("获取交易block number错误=", err)
+			time.Sleep(time.Second * 5)
+			continue
+		}
+		if res.MaxHeight < currentBlock {
+			time.Sleep(time.Second * time.Duration(((currentBlock - res.MaxHeight) * 5)))
+			continue
+		}
+
+		bl, err := ktoClient.GetBlockByNum(context.Background(), &pb.ReqBlockByNumber{Height: currentBlock})
+		if err != nil || bl.Code != 0 {
+			fmt.Println("获取交易block错误=", err)
+			continue
+		}
+		blc, errs := block.Deserialize(bl.Data)
+		if errs != nil {
+			fmt.Println("解析blcock错误=", errs)
+			continue
+		}
+		var ERR error
+		for _, v := range blc.Transactions {
+			evm, err := transaction.DecodeEvmData(v.Input)
+			if err != nil {
+				ERR = err
+				break
+			}
+			if len(evm.Logs) == 0 {
+				break
+			}
+			for _, l := range evm.Logs {
+				th := l.Topics[0].Hex()
+				method := TopsMap[th]
+				addr := l.Address.String()
+				if method == COLLECT_PARTICIPATE && addr == COLLECTCONTRACT {
+					var ev EventParticipate
+					abi, err := abi.JSON(strings.NewReader(Collect.CollectMetaData.ABI))
+					if err != nil {
+						ERR = err
+						break
+					}
+					err = abi.UnpackIntoInterface(&ev, method, l.Data)
+					if err != nil {
+						ERR = err
+						break
+					}
+					fmt.Printf("data=%+v\n ", ev)
+					//handle user participate
+
+					//usdrido(ev.User.String(), ev.Referrer.String(), v.HashToString(), decimal.NewFromBigInt(ev.Amount, -11), decimal.NewFromBigInt(ev.Price, -18), currentBlock)
+				}
+			}
+		}
+		if ERR != nil {
+			fmt.Println("处理错误=", ERR)
+			continue
+		}
+		bi.BlockNumber = int64(currentBlock)
+		_, err = dbUtil.Engine.ID(1).Update(&bi)
+		if err != nil {
+			fmt.Println("更新最新快高错误=", err)
+			return
+		}
+
+		currentBlock++
+	}
+}

+ 19 - 0
blockchain/types.go

@@ -0,0 +1,19 @@
+package blockchain
+
+import (
+	"math/big"
+
+	"github.com/ethereum/go-ethereum/common"
+)
+
+const (
+	TopicParticipate    = "0xddd670a4142d06229b922c5d433d29131580e1a2952c86700b0a36ea9e8b87ee"
+	COLLECT_PARTICIPATE = "participate"
+	COLLECTCONTRACT     = "0xaaaaaaaaaaaaaaaaa"
+)
+
+type EventParticipate struct {
+	User    common.Address
+	Inviter common.Address
+	Amount  *big.Int
+}

+ 480 - 0
contractgo/Collect/Collect.abi

@@ -0,0 +1,480 @@
+[
+	{
+		"anonymous": false,
+		"inputs": [
+			{
+				"indexed": false,
+				"internalType": "address",
+				"name": "user",
+				"type": "address"
+			},
+			{
+				"indexed": false,
+				"internalType": "uint256",
+				"name": "amount",
+				"type": "uint256"
+			}
+		],
+		"name": "Claim",
+		"type": "event"
+	},
+	{
+		"anonymous": false,
+		"inputs": [
+			{
+				"indexed": true,
+				"internalType": "address",
+				"name": "previousOwner",
+				"type": "address"
+			},
+			{
+				"indexed": true,
+				"internalType": "address",
+				"name": "newOwner",
+				"type": "address"
+			}
+		],
+		"name": "OwnershipTransferred",
+		"type": "event"
+	},
+	{
+		"anonymous": false,
+		"inputs": [
+			{
+				"indexed": false,
+				"internalType": "address",
+				"name": "participant",
+				"type": "address"
+			},
+			{
+				"indexed": false,
+				"internalType": "address",
+				"name": "inviter",
+				"type": "address"
+			},
+			{
+				"indexed": false,
+				"internalType": "uint256",
+				"name": "amount",
+				"type": "uint256"
+			}
+		],
+		"name": "Participate",
+		"type": "event"
+	},
+	{
+		"anonymous": false,
+		"inputs": [
+			{
+				"indexed": false,
+				"internalType": "address",
+				"name": "_manager",
+				"type": "address"
+			}
+		],
+		"name": "RemoveManager",
+		"type": "event"
+	},
+	{
+		"anonymous": false,
+		"inputs": [
+			{
+				"indexed": false,
+				"internalType": "address",
+				"name": "_manager",
+				"type": "address"
+			}
+		],
+		"name": "SetManager",
+		"type": "event"
+	},
+	{
+		"inputs": [],
+		"name": "_baseDistribution",
+		"outputs": [
+			{
+				"internalType": "uint256",
+				"name": "",
+				"type": "uint256"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_baseReward",
+		"outputs": [
+			{
+				"internalType": "uint256",
+				"name": "",
+				"type": "uint256"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_baseValue",
+		"outputs": [
+			{
+				"internalType": "uint256",
+				"name": "",
+				"type": "uint256"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_community",
+		"outputs": [
+			{
+				"internalType": "address",
+				"name": "",
+				"type": "address"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_devAddress",
+		"outputs": [
+			{
+				"internalType": "address",
+				"name": "",
+				"type": "address"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_reinputLimit",
+		"outputs": [
+			{
+				"internalType": "uint256",
+				"name": "",
+				"type": "uint256"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_reinputModBase",
+		"outputs": [
+			{
+				"internalType": "uint256",
+				"name": "",
+				"type": "uint256"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "_technical",
+		"outputs": [
+			{
+				"internalType": "address",
+				"name": "",
+				"type": "address"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "claimValue",
+				"type": "uint256"
+			},
+			{
+				"internalType": "string",
+				"name": "signTime",
+				"type": "string"
+			},
+			{
+				"internalType": "bytes32",
+				"name": "signature",
+				"type": "bytes32"
+			}
+		],
+		"name": "claimRewards",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "getDigit",
+		"outputs": [
+			{
+				"internalType": "string",
+				"name": "",
+				"type": "string"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "initialize",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "community",
+				"type": "address"
+			},
+			{
+				"internalType": "address",
+				"name": "technical",
+				"type": "address"
+			},
+			{
+				"internalType": "address",
+				"name": "devAddress",
+				"type": "address"
+			}
+		],
+		"name": "initialize",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "",
+				"type": "address"
+			}
+		],
+		"name": "managers",
+		"outputs": [
+			{
+				"internalType": "bool",
+				"name": "",
+				"type": "bool"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "owner",
+		"outputs": [
+			{
+				"internalType": "address",
+				"name": "",
+				"type": "address"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "inviter",
+				"type": "address"
+			}
+		],
+		"name": "participate",
+		"outputs": [],
+		"stateMutability": "payable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "_manager",
+				"type": "address"
+			}
+		],
+		"name": "removeManager",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [],
+		"name": "renounceOwnership",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "dis",
+				"type": "uint256"
+			}
+		],
+		"name": "setBaseDistribution",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "baseReward",
+				"type": "uint256"
+			}
+		],
+		"name": "setBaseReward",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "value",
+				"type": "uint256"
+			}
+		],
+		"name": "setBaseValue",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "string",
+				"name": "_digit",
+				"type": "string"
+			}
+		],
+		"name": "setDigit",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "_manager",
+				"type": "address"
+			}
+		],
+		"name": "setManager",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "newOwner",
+				"type": "address"
+			}
+		],
+		"name": "transferOwnership",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "amount",
+				"type": "uint256"
+			},
+			{
+				"internalType": "string",
+				"name": "signTime",
+				"type": "string"
+			},
+			{
+				"internalType": "bytes32",
+				"name": "signature",
+				"type": "bytes32"
+			}
+		],
+		"name": "verify",
+		"outputs": [
+			{
+				"internalType": "bool",
+				"name": "",
+				"type": "bool"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "_amount",
+				"type": "uint256"
+			},
+			{
+				"internalType": "string",
+				"name": "_time",
+				"type": "string"
+			},
+			{
+				"internalType": "address",
+				"name": "_user",
+				"type": "address"
+			},
+			{
+				"internalType": "bytes32",
+				"name": "_sign",
+				"type": "bytes32"
+			}
+		],
+		"name": "verifySignature",
+		"outputs": [
+			{
+				"internalType": "bool",
+				"name": "",
+				"type": "bool"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "uint256",
+				"name": "amount",
+				"type": "uint256"
+			}
+		],
+		"name": "withdraw",
+		"outputs": [],
+		"stateMutability": "nonpayable",
+		"type": "function"
+	}
+]

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 32 - 0
contractgo/Collect/Collect.go


+ 111 - 2
controller/calculate.go

@@ -1,6 +1,115 @@
 package controller
 
-//可领取收益
-func (uc *UserController) Claim() {
+import (
+	"errors"
+	"ktogame/models"
+	"strings"
 
+	"github.com/go-xorm/xorm"
+)
+
+func UpdateSuperiorsPerformance(engine *xorm.Engine, superiorsStr string, amount float64) error {
+	ids := strings.Split(superiorsStr, ",")
+	if len(ids) <= 0 {
+		return nil
+	}
+	var supers []models.UserInfo
+	for _, sid := range ids {
+		var tmpUser models.UserInfo
+		ok, err := engine.Id(sid).Get(&tmpUser)
+		if err != nil {
+			return err
+		}
+		if !ok {
+			return errors.New("UpdateSuperiorsPerformance get super failed")
+		}
+		supers = append(supers, tmpUser)
+	}
+
+	var rp models.RewardsPool
+	_, err := engine.Id(1).Get(&rp)
+	if err != nil {
+		return err
+	}
+
+	for _, user := range supers {
+		var per models.Performance
+		ok, err := engine.Id(user.Addr).Get(&per)
+		if err != nil {
+			return err
+		}
+		if !ok {
+			return errors.New("UpdateSuperiorsPerformance get performance failed")
+		}
+
+		per.TotalPerformance += amount
+		var level int = 0
+		for i := 1; i < len(PerformanceLevel); i++ {
+			if PerformanceLevel[i-1] <= per.TotalPerformance && per.TotalPerformance < PerformanceLevel[i] {
+				level = i
+				break
+			}
+		}
+		if level > 0 {
+			if level > per.ClaimedPerformanceLevel {
+				ratio := PerformanceRatio[level] - PerformanceRatio[per.ClaimedPerformanceLevel]
+				rewards := amount * ratio
+				if rp.TeamPerformance >= rewards {
+					rp.TeamPerformance -= rewards     //pool sub rewards
+					per.PerformanceRewards += rewards //user add rewards to PerformanceRewards
+					//update available
+					err := UpdateAvailableRewards(engine, rewards, user.Id)
+					if err != nil {
+						return err
+					}
+
+					_, err = engine.ID(user.Addr).Update(&per)
+					if err != nil {
+						return err
+					}
+				}
+			}
+		}
+
+	}
+
+	return nil
+}
+
+func UpdateRewardsPool(engine *xorm.Engine, amount float64) error {
+	var rp models.RewardsPool
+	rp.Recommendation = amount * 0.2
+	rp.TeamPerformance = amount * 0.2
+	rp.CommunityGift = amount * 0.5
+	rp.TeamCultivate = amount * 0.05
+	rp.CommunityNode = amount * 0.05
+	_, err := engine.ID(1).Update(&rp)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func UpdateAvailableRewards(engine *xorm.Engine, rewards float64, uid int64) error {
+	a_rewards := rewards * 60 / 100
+	a_reinput := rewards * 40 / 100
+	var user models.UserInfo
+	ok, err := engine.Id(uid).Get(&user)
+	if err != nil {
+		return err
+	}
+	if !ok {
+		return errors.New("engine get failed")
+	}
+	user.AvailableClaim = a_rewards
+	user.AvailableReinput = a_reinput
+	_, err = engine.ID(user.Addr).Cols("available_claim").Update(&user)
+	if err != nil {
+		return err
+	}
+	_, err = engine.ID(user.Addr).Cols("available_reinput").Update(&user)
+	if err != nil {
+		return err
+	}
+	return nil
 }

+ 14 - 40
controller/reinput.go

@@ -39,31 +39,12 @@ func (uc *UserController) Reinput(user string) {
 		ErrResponse(uc.Controller, err)
 		return
 	}
-	///update Recommendation Rewards
-	rewards := reinputValue * 10 / 100
-	a_rewards := rewards * 60 / 100
-	a_reinput := rewards * 40 / 100
 
+	///update Recommendation Rewards
 	///update direct recommend rewards
+	rewards := reinputValue * 10 / 100
 	if ui.Direct != -1 {
-		var dui models.UserInfo
-		ok, err := uc.engine.Id(ui.Direct).Get(&dui)
-		if err != nil {
-			ErrResponse(uc.Controller, err)
-			return
-		}
-		if !ok {
-			ErrResponse(uc.Controller, "db get failed!")
-			return
-		}
-		dui.AvailableClaim = a_rewards
-		dui.AvailableReinput = a_reinput
-		_, err = uc.engine.ID(dui.Addr).Cols("available_claim").Update(&dui)
-		if err != nil {
-			ErrResponse(uc.Controller, err)
-			return
-		}
-		_, err = uc.engine.ID(dui.Addr).Cols("available_reinput").Update(&dui)
+		err := UpdateAvailableRewards(uc.engine, rewards, ui.Direct)
 		if err != nil {
 			ErrResponse(uc.Controller, err)
 			return
@@ -71,28 +52,21 @@ func (uc *UserController) Reinput(user string) {
 	}
 	///update indirect recommend rewards
 	if ui.Indirect != -1 {
-		var idui models.UserInfo
-		ok, err := uc.engine.Id(ui.Indirect).Get(&idui)
-		if err != nil {
-			ErrResponse(uc.Controller, err)
-			return
-		}
-		if !ok {
-			ErrResponse(uc.Controller, "db get failed!")
-			return
-		}
-		idui.AvailableClaim = a_rewards
-		idui.AvailableReinput = a_reinput
-		_, err = uc.engine.ID(idui.Addr).Cols("available_claim").Update(&idui)
-		if err != nil {
-			ErrResponse(uc.Controller, err)
-			return
-		}
-		_, err = uc.engine.ID(idui.Addr).Cols("available_reinput").Update(&idui)
+		err := UpdateAvailableRewards(uc.engine, rewards, ui.Indirect)
 		if err != nil {
 			ErrResponse(uc.Controller, err)
 			return
 		}
 	}
+	err = UpdateRewardsPool(uc.engine, reinputValue)
+	if err != nil {
+		ErrResponse(uc.Controller, err)
+		return
+	}
+	err = UpdateSuperiorsPerformance(uc.engine, ui.Superiors, reinputValue)
+	if err != nil {
+		ErrResponse(uc.Controller, err)
+		return
+	}
 	TxObjectResponse(uc.Controller, "success")
 }

+ 4 - 0
controller/types.go

@@ -14,3 +14,7 @@ const (
 	OfficialUser   = 1
 	CommunityUsers = 2
 )
+
+var PerformanceLevel = [9]float64{10000 * Decimals, 30000 * Decimals, 100000 * Decimals, 300000 * Decimals,
+	1000000 * Decimals, 200 * Decimals, 5000000 * Decimals, 10000000 * Decimals, 50000000 * Decimals}
+var PerformanceRatio = [9]float64{0, 0.3, 0.6, 0.9, 0.12, 0.15, 0.17, 0.19, 0.2}

+ 41 - 35
dbUtil/redisCoon.go

@@ -3,10 +3,16 @@ package dbUtil
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/gomodule/redigo/redis"
-	"github.com/shopspring/decimal"
 	"os"
 	"strings"
+
+	"github.com/gomodule/redigo/redis"
+	"github.com/shopspring/decimal"
+)
+
+const (
+	TopicParticipate = "0xddd670a4142d06229b922c5d433d29131580e1a2952c86700b0a36ea9e8b87ee"
+	FuncParticipate  = "participate"
 )
 
 //var conn redis.Conn
@@ -14,32 +20,34 @@ var pool *redis.Pool
 var TopsMap map[string]string
 var MethodMap map[string]string
 var LvMap map[int]decimal.Decimal
-func init(){
+
+func init() {
 	pool = &redis.Pool{
 		MaxIdle:     500,
 		MaxActive:   2000,
 		IdleTimeout: 120,
 		Dial: func() (redis.Conn, error) {
 			coon, err := redis.Dial("tcp", "127.0.0.1:6379")
-			if err!=nil{
+			if err != nil {
 				fmt.Println(err)
 				os.Exit(1)
 			}
-			coon.Send("auth","0x817A=7%BJ#x%H=1rK")
-			return coon,err
+			coon.Send("auth", "0x817A=7%BJ#x%H=1rK")
+			return coon, err
 		},
 	}
-	tm :=make(map[string]string,0)
-	tm["0xddd670a4142d06229b922c5d433d29131580e1a2952c86700b0a36ea9e8b87ee"] = "newDeposit"
-	tm["0x056f1f5cdd8662230b94b7f88e06d95549d18e77cb2959933db3849d36df790a"] = "newWithdraw"
+	tm := make(map[string]string, 0)
+	// tm["0xddd670a4142d06229b922c5d433d29131580e1a2952c86700b0a36ea9e8b87ee"] = "newDeposit"
+	// tm["0x056f1f5cdd8662230b94b7f88e06d95549d18e77cb2959933db3849d36df790a"] = "newWithdraw"
+	tm[TopicParticipate] = FuncParticipate
 	TopsMap = tm
 
-	mm :=make(map[string]string,0)
+	mm := make(map[string]string, 0)
 	mm["transferFrom"] = "Transfer"
 	mm["sell"] = "SellOrder"
 	MethodMap = mm
 
-	lm :=make(map[int]decimal.Decimal,0)
+	lm := make(map[int]decimal.Decimal, 0)
 	lm[1] = decimal.NewFromFloat(0.1)
 	lm[2] = decimal.NewFromFloat(0.08)
 	lm[3] = decimal.NewFromFloat(0.03)
@@ -53,70 +61,68 @@ func init(){
 	LvMap = lm
 }
 
-func GetValue(key string,t int)interface{}{
+func GetValue(key string, t int) interface{} {
 	rc := pool.Get()
 	defer rc.Close()
 	key = strings.ToLower(key)
-	if t == 1{
+	if t == 1 {
 		i, e := rc.Do("get", key)
-		if e!=nil {
-			fmt.Println("e=",e)
+		if e != nil {
+			fmt.Println("e=", e)
 			return 0
 		}
-		reply, _:= redis.Int64(i,e)
+		reply, _ := redis.Int64(i, e)
 		return reply
-	}else if t == 2{
+	} else if t == 2 {
 		//fmt.Println("GetValue key=",key)
 		r, e := rc.Do("GET", key)
-		if e!=nil {
+		if e != nil {
 			//fmt.Println("eeeeee=",e)
 			return nil
 		}
 		//fmt.Println("=rrrrr==",r)
-		reply, err := redis.Bytes(r,e)
-		if err!=nil {
+		reply, err := redis.Bytes(r, e)
+		if err != nil {
 			//fmt.Println("错误13331=",err)
 			return nil
 		}
 		//fmt.Println("===",string(reply))
 		var d *[]string
 		err = json.Unmarshal(reply, &d)
-		if err!=nil {
-			fmt.Println("错误11=",err)
+		if err != nil {
+			fmt.Println("错误11=", err)
 		}
 		//fmt.Printf("d2结果的原始类型%T,值为%v\n", d, *d)
 		return *d
-	}else if t == 3{
+	} else if t == 3 {
 		i, e := rc.Do("get", key)
-		if e!=nil {
-			fmt.Println("e=",e)
+		if e != nil {
+			fmt.Println("e=", e)
 			return 0
 		}
-		reply, _:= redis.String(i,e)
+		reply, _ := redis.String(i, e)
 		return reply
-	}else{
+	} else {
 		return ""
 	}
 }
 
-
-func SetValue(key string,value interface{}){
+func SetValue(key string, value interface{}) {
 	rc := pool.Get()
 	defer rc.Close()
 	key = strings.ToLower(key)
-	rc.Do("set",key,value)
+	rc.Do("set", key, value)
 }
 
-func SetValueTime(key string,value interface{},t int64){
+func SetValueTime(key string, value interface{}, t int64) {
 	rc := pool.Get()
 	defer rc.Close()
 	key = strings.ToLower(key)
-	rc.Do("set",key,value,"EX",t)
+	rc.Do("set", key, value, "EX", t)
 }
 
-
-func DeleteValue(key string){
+func DeleteValue(key string) {
 	rc := pool.Get()
 	defer rc.Close()
-	rc.Do("DEL",key)
+	rc.Do("DEL", key)
 }

BIN
ktogame


+ 21 - 11
models/tables.go

@@ -9,13 +9,13 @@ import (
 type UserInfo struct {
 	Id               int64
 	Addr             string
-	Direct           int     //我的上级
+	Direct           int64   //我的上级
 	DirectNumber     int     //直推总人数
 	IndirectRewards  float64 `xorm:"Decimal"`
-	Indirect         int     //上上级
+	Indirect         int64   //上上级
 	IndirectNumber   int     //间推总人数
 	DirectRewards    float64 `xorm:"Decimal"`
-	TeamMembers      string  //团队(上级)
+	Superiors        string  //所有上级
 	AvailableClaim   float64 `xorm:"Decimal"` //可领取收益
 	TotalClaimed     float64 `xorm:"Decimal"` //总共已领取的收益
 	AvailableReinput float64 `xorm:"Decimal"` //可用复投
@@ -30,15 +30,15 @@ type UserInfo struct {
 // 	CommunityNode float64 `xorm:"Decimal"`
 
 type Performance struct {
-	Id                 int64
-	Addr               string
-	TotalPerformance   float64 `xorm:"Decimal"`
-	PerformanceLevel   int
-	PerformanceRewards float64 `xorm:"Decimal"`
+	Id                      int64
+	Addr                    string
+	TotalPerformance        float64 `xorm:"Decimal"`
+	ClaimedPerformanceLevel int
+	PerformanceRewards      float64 `xorm:"Decimal"`
 
-	TotalTeamCultivate   float64 `xorm:"Decimal"`
-	TeamCultivateLevel   int
-	TeamCultivateRewards float64 `xorm:"Decimal"`
+	TotalTeamCultivate    float64 `xorm:"Decimal"`
+	ClaimedCultivateLevel int
+	TeamCultivateRewards  float64 `xorm:"Decimal"`
 
 	CommunityGift float64 `xorm:"Decimal"`
 	CommunityNode float64 `xorm:"Decimal"`
@@ -49,6 +49,16 @@ type BlockInfo struct {
 	BlockNumber int64
 }
 
+type RewardsPool struct {
+	Id              int64
+	Recommendation  float64 `xorm:"Decimal"`
+	TeamPerformance float64 `xorm:"Decimal"`
+	TeamCultivate   float64 `xorm:"Decimal"`
+	CommunityGift   float64 `xorm:"Decimal"`
+	CommunityNode   float64 `xorm:"Decimal"`
+	TotalPool       float64 `xorm:"Decimal"`
+}
+
 type UserTxs struct {
 	Id     int64
 	Addr   string

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott