Commit ca57fc775f1575cbdb0f4e8e725d8e1cf96677e4
1 parent
848d5b51
Exists in
master
提交接口
Showing
6 changed files
with
202 additions
and
0 deletions
Show diff stats
src/HttpServer/logic/datadef.go
| @@ -88,6 +88,34 @@ type UserLoginResp struct { | @@ -88,6 +88,34 @@ type UserLoginResp struct { | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | +type QueryInviteReq struct{ | ||
| 92 | + Uuid int `json:"uuid"` | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +type QueryInviteData struct { | ||
| 96 | + Uuid int `json:"uuid"` | ||
| 97 | + Nickname string `json:"nickname"` | ||
| 98 | + Isfetched int `json:"isfetched"` | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +type QueryInviteResp struct { | ||
| 102 | + Code int `json:"code"` | ||
| 103 | + Message string `json:"message"` | ||
| 104 | + Data []QueryInviteData `json:"data"` | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +type FetchInviteReq struct{ | ||
| 108 | + Selfuuid int `json:"selfuuid"` | ||
| 109 | + Fuuid int `json:"fuuid"` | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | + | ||
| 113 | +type FetchInviteResp struct { | ||
| 114 | + Code int `json:"code"` | ||
| 115 | + Message string `json:"message"` | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | + | ||
| 91 | type RegeisterReq struct{ | 119 | type RegeisterReq struct{ |
| 92 | Account string `json:"account"` | 120 | Account string `json:"account"` |
| 93 | Password string `json:"password"` | 121 | Password string `json:"password"` |
src/HttpServer/logic/errordef.go
| @@ -39,4 +39,5 @@ const ( | @@ -39,4 +39,5 @@ const ( | ||
| 39 | ERROR_REGEISTACCOUNTEXIST = 34 //注册账号重复 | 39 | ERROR_REGEISTACCOUNTEXIST = 34 //注册账号重复 |
| 40 | ERROR_ACCOUNTPWDWRONG= 35 //账号登录密码不对 | 40 | ERROR_ACCOUNTPWDWRONG= 35 //账号登录密码不对 |
| 41 | ERROR_TEAMISMAX= 36 //队伍人数已满 | 41 | ERROR_TEAMISMAX= 36 //队伍人数已满 |
| 42 | + ERROR_INVITEREAWARD_FETCHED= 37 //邀请奖励已经领取 | ||
| 42 | ) | 43 | ) |
| 43 | \ No newline at end of file | 44 | \ No newline at end of file |
src/HttpServer/logic/httpserver.go
| @@ -69,6 +69,10 @@ func startServerHttpServe() { | @@ -69,6 +69,10 @@ func startServerHttpServe() { | ||
| 69 | http.HandleFunc("/catcafe/friend/delFriend", DelFriend) //删除好友 | 69 | http.HandleFunc("/catcafe/friend/delFriend", DelFriend) //删除好友 |
| 70 | http.HandleFunc("/catcafe/friend/QueryPlayerData", QueryPlayerData) //根据用户id获取用户信息 好友用 | 70 | http.HandleFunc("/catcafe/friend/QueryPlayerData", QueryPlayerData) //根据用户id获取用户信息 好友用 |
| 71 | 71 | ||
| 72 | + //................................................................................................................... | ||
| 73 | + http.HandleFunc("/catcafe/user/queryInvite", QueryInvite) //查询玩家对应邀请关系 | ||
| 74 | + http.HandleFunc("/catcafe/user/fetchInviteReward",FetchInviteReward) //领取邀请奖励 | ||
| 75 | + | ||
| 72 | 76 | ||
| 73 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 77 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
| 74 | CheckErr(err) | 78 | CheckErr(err) |
| @@ -207,6 +211,30 @@ func ClearData(w http.ResponseWriter, r *http.Request) { | @@ -207,6 +211,30 @@ func ClearData(w http.ResponseWriter, r *http.Request) { | ||
| 207 | //HandleRegeister(w,s) | 211 | //HandleRegeister(w,s) |
| 208 | } | 212 | } |
| 209 | 213 | ||
| 214 | +func FetchInviteReward(w http.ResponseWriter, r *http.Request) { | ||
| 215 | + | ||
| 216 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 217 | + r.Body.Close() | ||
| 218 | + | ||
| 219 | + s := string(result) | ||
| 220 | + logger.Info("FetchInviteReward , body:%v,uuid=%v", s) | ||
| 221 | + | ||
| 222 | + HandleFetchInviteReward(w,s) | ||
| 223 | + | ||
| 224 | +} | ||
| 225 | + | ||
| 226 | +func QueryInvite(w http.ResponseWriter, r *http.Request) { | ||
| 227 | + | ||
| 228 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 229 | + r.Body.Close() | ||
| 230 | + | ||
| 231 | + s := string(result) | ||
| 232 | + logger.Info("QueryInvite , body:%v,uuid=%v", s) | ||
| 233 | + | ||
| 234 | + HandleQueryInvite(w,s) | ||
| 235 | + | ||
| 236 | +} | ||
| 237 | + | ||
| 210 | func Regeister(w http.ResponseWriter, r *http.Request) { | 238 | func Regeister(w http.ResponseWriter, r *http.Request) { |
| 211 | 239 | ||
| 212 | result, _ := ioutil.ReadAll(r.Body) | 240 | result, _ := ioutil.ReadAll(r.Body) |
src/HttpServer/logic/logic.go
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | "common/redis" | 8 | "common/redis" |
| 9 | ksuid "github.com/segmentio" | 9 | ksuid "github.com/segmentio" |
| 10 | "io/ioutil" | 10 | "io/ioutil" |
| 11 | + "mysql" | ||
| 11 | "strconv" | 12 | "strconv" |
| 12 | 13 | ||
| 13 | "encoding/json" | 14 | "encoding/json" |
| @@ -231,6 +232,91 @@ func TransmitUserData(in *UserData ,out *UserExtData) { | @@ -231,6 +232,91 @@ func TransmitUserData(in *UserData ,out *UserExtData) { | ||
| 231 | out.Invite_uid = in.InviteUid | 232 | out.Invite_uid = in.InviteUid |
| 232 | } | 233 | } |
| 233 | 234 | ||
| 235 | + | ||
| 236 | +func HandleQueryInvite(w http.ResponseWriter, data string) { | ||
| 237 | + | ||
| 238 | + SetHeader(w) | ||
| 239 | + var resp QueryInviteResp | ||
| 240 | + resp.Code = 0 | ||
| 241 | + var rdata QueryInviteReq | ||
| 242 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 243 | + for { | ||
| 244 | + if err != nil { | ||
| 245 | + logger.Error("HandleQueryInvite json unmarshal failed=%v", err) | ||
| 246 | + resp.Code = ERROR_JSONUNMASHFAILED | ||
| 247 | + resp.Message = "json unmarshal failed" | ||
| 248 | + break | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + inlist,err := mysql.QueryInvite(rdata.Uuid) | ||
| 252 | + if err != nil { | ||
| 253 | + logger.Error("HandleQueryInvite QueryInvite failed=%v", err) | ||
| 254 | + resp.Code = ERROR_JSONUNMASHFAILED | ||
| 255 | + resp.Message = "QueryInvite failed" | ||
| 256 | + break | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + for _,val := range inlist { | ||
| 260 | + var tmp QueryInviteData | ||
| 261 | + tmp.Uuid = val.Uuid | ||
| 262 | + tmp.Nickname = val.NickName | ||
| 263 | + tmp.Isfetched = val.IsFecthed | ||
| 264 | + resp.Data = append(resp.Data,tmp) | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + resp.Code = ERROR_OK | ||
| 268 | + break | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + //回包 | ||
| 272 | + respstr, _ := json.Marshal(&resp) | ||
| 273 | + fmt.Fprint(w, string(respstr)) | ||
| 274 | +} | ||
| 275 | + | ||
| 276 | +func HandleFetchInviteReward(w http.ResponseWriter, data string) { | ||
| 277 | + | ||
| 278 | + SetHeader(w) | ||
| 279 | + var resp FetchInviteResp | ||
| 280 | + resp.Code = 0 | ||
| 281 | + var rdata FetchInviteReq | ||
| 282 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 283 | + for { | ||
| 284 | + if err != nil { | ||
| 285 | + logger.Error("HandleFetchInviteReward json unmarshal failed=%v", err) | ||
| 286 | + resp.Code = ERROR_JSONUNMASHFAILED | ||
| 287 | + resp.Message = "json unmarshal failed" | ||
| 288 | + break | ||
| 289 | + } | ||
| 290 | + | ||
| 291 | + rkey := redis.USER_INVITEREWARD_FETCH_REWARD + ":" + strconv.Itoa(rdata.Selfuuid) | ||
| 292 | + isexist,err := redishandler.GetRedisClient().HExists(rkey,strconv.Itoa(rdata.Fuuid)) | ||
| 293 | + if err != nil { | ||
| 294 | + logger.Error("HandleFetchInviteReward redis failed=%v", err) | ||
| 295 | + resp.Code = ERROR_JSONUNMASHFAILED | ||
| 296 | + resp.Message = fmt.Sprintf("%s",err) | ||
| 297 | + break | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + if isexist { | ||
| 301 | + logger.Error("HandleFetchInviteReward alreadyfetched failed=%v", err) | ||
| 302 | + resp.Code = ERROR_INVITEREAWARD_FETCHED | ||
| 303 | + resp.Message = "already fetched" | ||
| 304 | + break | ||
| 305 | + } | ||
| 306 | + | ||
| 307 | + //将领取记录记录 | ||
| 308 | + redishandler.GetRedisClient().HSet(rkey,strconv.Itoa(rdata.Fuuid),strconv.Itoa(rdata.Fuuid)) | ||
| 309 | + | ||
| 310 | + resp.Code = ERROR_OK | ||
| 311 | + break | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + //回包 | ||
| 315 | + respstr, _ := json.Marshal(&resp) | ||
| 316 | + fmt.Fprint(w, string(respstr)) | ||
| 317 | +} | ||
| 318 | + | ||
| 319 | + | ||
| 234 | func HandleRegeister(w http.ResponseWriter, data string) { | 320 | func HandleRegeister(w http.ResponseWriter, data string) { |
| 235 | 321 | ||
| 236 | SetHeader(w) | 322 | SetHeader(w) |
src/common/redis/def.go
| @@ -16,4 +16,5 @@ const ( | @@ -16,4 +16,5 @@ const ( | ||
| 16 | FRIEND_APPROVELIST_KEY = "CATCAFE_FRIEND_APPROVELIST_KEY" //待批准好友列表,需要在末尾加死":uuid" | 16 | FRIEND_APPROVELIST_KEY = "CATCAFE_FRIEND_APPROVELIST_KEY" //待批准好友列表,需要在末尾加死":uuid" |
| 17 | FRIEND_RECOMMANDLIST_KEY = "CATCAFE_FRIEND_RECOMMANDLIST_KEY" //推荐好友缓存key | 17 | FRIEND_RECOMMANDLIST_KEY = "CATCAFE_FRIEND_RECOMMANDLIST_KEY" //推荐好友缓存key |
| 18 | USER_ACCOUNT_PASSWORD_KEY = "CATCAFE_USER_ACCOUNT_PASSWORD_KEY" //玩家账号密码的key | 18 | USER_ACCOUNT_PASSWORD_KEY = "CATCAFE_USER_ACCOUNT_PASSWORD_KEY" //玩家账号密码的key |
| 19 | + USER_INVITEREWARD_FETCH_REWARD = "CATCAFE_USER_INVITEREWARD_FETCH_REWARD" //玩家邀请奖励领取状况 hset | ||
| 19 | ) | 20 | ) |
src/mysql/dbmysql.go
| @@ -2,7 +2,9 @@ package mysql | @@ -2,7 +2,9 @@ package mysql | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "HttpServer/conf" | 4 | "HttpServer/conf" |
| 5 | + "HttpServer/redishandler" | ||
| 5 | "common/logger" | 6 | "common/logger" |
| 7 | + "common/redis" | ||
| 6 | "database/sql" | 8 | "database/sql" |
| 7 | "fmt" | 9 | "fmt" |
| 8 | _ "github.com/go-sql-driver/mysql" | 10 | _ "github.com/go-sql-driver/mysql" |
| @@ -15,6 +17,12 @@ var ( | @@ -15,6 +17,12 @@ var ( | ||
| 15 | m_game_db *sql.DB | 17 | m_game_db *sql.DB |
| 16 | ) | 18 | ) |
| 17 | 19 | ||
| 20 | +type QuerInviteDesc struct { | ||
| 21 | + Uuid int | ||
| 22 | + NickName string | ||
| 23 | + IsFecthed int | ||
| 24 | +} | ||
| 25 | + | ||
| 18 | func InitMysql() error { | 26 | func InitMysql() error { |
| 19 | db, err := InitMysqlByConf(conf.GetGameDBConf()) | 27 | db, err := InitMysqlByConf(conf.GetGameDBConf()) |
| 20 | if err != nil { | 28 | if err != nil { |
| @@ -138,4 +146,54 @@ func QueryAllData(f *os.File) error{ | @@ -138,4 +146,54 @@ func QueryAllData(f *os.File) error{ | ||
| 138 | } | 146 | } |
| 139 | return nil | 147 | return nil |
| 140 | 148 | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | + | ||
| 152 | +func QueryInvite(uuid int) ([]QuerInviteDesc,error){ | ||
| 153 | + var rtslice []QuerInviteDesc | ||
| 154 | + for i:=0;i<10;i++ { | ||
| 155 | + tablename := "b_user_ext_0" + strconv.Itoa(i) | ||
| 156 | + cmd := "SELECT user_id,nickname, from " + tablename + " where invite_uid= " + strconv.Itoa(uuid) | ||
| 157 | + rows, err := m_game_db.Query(cmd) | ||
| 158 | + defer func() { | ||
| 159 | + if rows != nil { | ||
| 160 | + rows.Close() //可以关闭掉未scan连接一直占用 | ||
| 161 | + } | ||
| 162 | + }() | ||
| 163 | + | ||
| 164 | + if err != nil { | ||
| 165 | + logger.Error("Query failed,err:%v", err) | ||
| 166 | + continue | ||
| 167 | + } | ||
| 168 | + for rows.Next() { | ||
| 169 | + var tmp QuerInviteDesc | ||
| 170 | + err = rows.Scan(&tmp.Uuid, &tmp.NickName) //不scan会导致连接不释放 | ||
| 171 | + if err != nil { | ||
| 172 | + logger.Error("Scan failed,err:%v", err) | ||
| 173 | + continue | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + tmp.IsFecthed = 0 | ||
| 177 | + rtslice = append(rtslice,tmp) | ||
| 178 | + } | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + //需要查询一下当前领取状态 | ||
| 182 | + rkey := redis.USER_INVITEREWARD_FETCH_REWARD + ":" + strconv.Itoa(uuid) | ||
| 183 | + for k,val := range rtslice{ | ||
| 184 | + isexist,err := redishandler.GetRedisClient().HExists(rkey,strconv.Itoa(val.Uuid)) | ||
| 185 | + if err != nil { | ||
| 186 | + logger.Error("USER_INVITEREWARD_FETCH_REWARD failed err=%v",err) | ||
| 187 | + rtslice[k].IsFecthed = 1 | ||
| 188 | + continue | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + if isexist { | ||
| 192 | + //已经存在 | ||
| 193 | + rtslice[k].IsFecthed = 1 | ||
| 194 | + } | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + | ||
| 198 | + return rtslice,nil | ||
| 141 | } | 199 | } |
| 142 | \ No newline at end of file | 200 | \ No newline at end of file |