Commit 074f1074e320ccf984f77300868a7d2fdc4139dc
1 parent
ecddc4fc
Exists in
ver2.3.6
提交
Showing
3 changed files
with
40 additions
and
16 deletions
Show diff stats
src/HttpServer/logic/function.go
... | ... | @@ -11,7 +11,6 @@ import ( |
11 | 11 | "encoding/json" |
12 | 12 | "errors" |
13 | 13 | "io/ioutil" |
14 | - "mysql" | |
15 | 14 | "net/http" |
16 | 15 | "sort" |
17 | 16 | "strconv" |
... | ... | @@ -55,10 +54,10 @@ func GetUserInfo(uniqueid string) (*UserData, error) { |
55 | 54 | |
56 | 55 | data, err := redishandler.GetRedisClient().HGet(redis.USER_DATA_KEY, uniqueid) |
57 | 56 | if err != nil { |
58 | - logger.Info("GetUserInfo from mysql") | |
59 | - //return nil, err | |
57 | + //logger.Info("GetUserInfo from mysql") | |
58 | + return nil, err | |
60 | 59 | //从mysql读取 |
61 | - err,info,task,ach := mysql.GetFromBackUp(uniqueid) | |
60 | + /*err,info,task,ach := mysql.GetFromBackUp(uniqueid) | |
62 | 61 | if err != nil { |
63 | 62 | return nil, err |
64 | 63 | } |
... | ... | @@ -73,7 +72,7 @@ func GetUserInfo(uniqueid string) (*UserData, error) { |
73 | 72 | return nil, err |
74 | 73 | } |
75 | 74 | |
76 | - return &tmp, nil | |
75 | + return &tmp, nil*/ | |
77 | 76 | }else { |
78 | 77 | var tmp UserData |
79 | 78 | err = json.Unmarshal([]byte(data), &tmp) | ... | ... |
src/HttpServer/logic/logic.go
... | ... | @@ -7,6 +7,7 @@ import ( |
7 | 7 | "common/redis" |
8 | 8 | "encoding/json" |
9 | 9 | "fmt" |
10 | + "mysql" | |
10 | 11 | "net/http" |
11 | 12 | "strconv" |
12 | 13 | "strings" |
... | ... | @@ -1193,8 +1194,32 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int) { |
1193 | 1194 | if !isexist { |
1194 | 1195 | //不存在 |
1195 | 1196 | //属于新登录的玩家数据 |
1196 | - //需要判断是否存在老的版本的数据 | |
1197 | - isexist, err = redishandler.GetRedisClient().HExists(redis.USER_DATA_KEY, strconv.Itoa(uuid)) | |
1197 | + //需要判断是否存在mysql中 | |
1198 | + logger.Info("GetUserInfo from mysql") | |
1199 | + //return nil, err | |
1200 | + //从mysql读取 | |
1201 | + err,info,task,ach,isfind := mysql.GetFromBackUp(uniqueuuid) | |
1202 | + if err != nil { | |
1203 | + /*logger.Error("mysql failed err=%v", err) | |
1204 | + resp.Message = "服务器错误" | |
1205 | + resp.Code = ERROR_SRV_ERROR | |
1206 | + break*/ | |
1207 | + logger.Error("mysql failed err=%v", err) | |
1208 | + err = GetUserData(uuid, uniqueuuid, &rdata, &resp) | |
1209 | + } | |
1210 | + | |
1211 | + if isfind { | |
1212 | + //先保存数据 | |
1213 | + err = redishandler.GetRedisClient().HSet(redis.USER_DATA_KEY, uniqueuuid,info) | |
1214 | + err = redishandler.GetRedisClient().HSet(redis.USER_TASKINFO_LIST, uniqueuuid,task) | |
1215 | + err = redishandler.GetRedisClient().HSet(redis.USER_ACHIEVEMENTINFO_LIST, uniqueuuid,ach) | |
1216 | + }else { | |
1217 | + //不存在老的数据 之间走新号流程 | |
1218 | + err = InitUserInfo(&rdata, &resp, uuid, uniqueuuid) | |
1219 | + } | |
1220 | + | |
1221 | + | |
1222 | + /*isexist, err = redishandler.GetRedisClient().HExists(redis.USER_DATA_KEY, strconv.Itoa(uuid)) | |
1198 | 1223 | if err == nil && isexist { |
1199 | 1224 | //如果存在老的数据 做数据迁移 |
1200 | 1225 | oldstr, err := redishandler.GetRedisClient().HGet(redis.USER_DATA_KEY, strconv.Itoa(uuid)) |
... | ... | @@ -1217,11 +1242,8 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int) { |
1217 | 1242 | //删除老的数据 |
1218 | 1243 | redishandler.GetRedisClient().HDel(redis.USER_DATA_KEY, strconv.Itoa(uuid)) |
1219 | 1244 | logger.Info("HandlerLogin uuid=%v do set", uuid) |
1220 | - } | |
1221 | - } else { | |
1222 | - //不存在老的数据 之间走新号流程 | |
1223 | - err = InitUserInfo(&rdata, &resp, uuid, uniqueuuid) | |
1224 | - } | |
1245 | + }*/ | |
1246 | + | |
1225 | 1247 | |
1226 | 1248 | } else { |
1227 | 1249 | //已经迁移过的数据之间返回 | ... | ... |
src/mysql/dbmysql.go
... | ... | @@ -46,7 +46,8 @@ func ExcuteCmd(cmd string) error { |
46 | 46 | return err |
47 | 47 | } |
48 | 48 | |
49 | -func GetFromBackUp(uniqueid string) (error,string,string,string) { | |
49 | +func GetFromBackUp(uniqueid string) (error,string,string,string,bool) { | |
50 | + isfind := false | |
50 | 51 | cmd := "select info,task,achieve from hedaoshi where uid = " + uniqueid |
51 | 52 | rows, err := m_game_db.Query(cmd) |
52 | 53 | if rows != nil { |
... | ... | @@ -54,7 +55,7 @@ func GetFromBackUp(uniqueid string) (error,string,string,string) { |
54 | 55 | } |
55 | 56 | if err != nil { |
56 | 57 | logger.Notic("TestClearData mysql select error:%v", err) |
57 | - return err,"","","" | |
58 | + return err,"","","",isfind | |
58 | 59 | } |
59 | 60 | var info,task,ach string |
60 | 61 | for rows.Next() { |
... | ... | @@ -62,14 +63,16 @@ func GetFromBackUp(uniqueid string) (error,string,string,string) { |
62 | 63 | err = rows.Scan(&info,&task,&ach) |
63 | 64 | if err != nil { |
64 | 65 | logger.Notic("GetFromBackUp mysql handle result error:%v", err) |
65 | - return err,"","","" | |
66 | + return err,"","","",isfind | |
66 | 67 | } |
68 | + | |
69 | + isfind = true | |
67 | 70 | logger.Info("GetFromBackUp uniqueid=%v",uniqueid) |
68 | 71 | |
69 | 72 | break |
70 | 73 | } |
71 | 74 | |
72 | - return nil,info,task,ach | |
75 | + return nil,info,task,ach,isfind | |
73 | 76 | } |
74 | 77 | |
75 | 78 | func TestClearData(uid int) (int,error) { | ... | ... |