Commit c3089ea82f2281d6e2765bd70a96e499078bc633
1 parent
39e6bdb4
Exists in
master
提交好友相关接口
Showing
7 changed files
with
463 additions
and
3 deletions
Show diff stats
src/HttpServer/logic/datadef.go
| @@ -393,12 +393,78 @@ type SearchTeamReq struct{ | @@ -393,12 +393,78 @@ type SearchTeamReq struct{ | ||
| 393 | Page int `json:"page"` | 393 | Page int `json:"page"` |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | +type SearchTeamResp struct { | ||
| 397 | + Status string `json:"status"` | ||
| 398 | + Result GetTeamListResult `json:"result"` | ||
| 399 | +} | ||
| 396 | 400 | ||
| 401 | +type FriendInfo struct { | ||
| 402 | + Uuid int `json:"uuid"` | ||
| 403 | + Status int `json:"status"` | ||
| 404 | +} | ||
| 397 | 405 | ||
| 406 | +type FriendList struct { | ||
| 407 | + Friends []FriendInfo `json:"friends"` | ||
| 408 | +} | ||
| 398 | 409 | ||
| 399 | -type SearchTeamResp struct { | 410 | +type ApplyInfo struct { |
| 411 | + Uuid int `json:"uuid"` | ||
| 412 | + Apply_time int `json:"apply_time"` | ||
| 413 | +} | ||
| 414 | +type ApplyList struct { | ||
| 415 | + Apply_info []ApplyInfo `json:"apply_info"` | ||
| 416 | +} | ||
| 417 | + | ||
| 418 | +type ApproveList struct { | ||
| 419 | + Approve_info []ApplyInfo `json:"approve_info"` | ||
| 420 | +} | ||
| 421 | + | ||
| 422 | +type SetFriendReq struct{ | ||
| 423 | + Token string `json:"token"` | ||
| 424 | + User_id int `json:"user_id"` | ||
| 425 | +} | ||
| 426 | + | ||
| 427 | + | ||
| 428 | +type SetFriendResp struct { | ||
| 400 | Status string `json:"status"` | 429 | Status string `json:"status"` |
| 401 | - Result GetTeamListResult `json:"result"` | 430 | + Result CommonResult `json:"result"` |
| 431 | +} | ||
| 432 | + | ||
| 433 | +type GetFriendListReq struct{ | ||
| 434 | + Token string `json:"token"` | ||
| 435 | +} | ||
| 436 | + | ||
| 437 | +type GetFriendListDesc struct { | ||
| 438 | + Friend_list []FriendInfo `json:"friend_list"` | ||
| 439 | +} | ||
| 440 | + | ||
| 441 | +type GetFriendListResult struct { | ||
| 442 | + Code int `json:"code"` | ||
| 443 | + Data GetFriendListDesc `json:"data"` | ||
| 444 | +} | ||
| 445 | + | ||
| 446 | +type GetFriendListResp struct { | ||
| 447 | + Status string `json:"status"` | ||
| 448 | + Result GetFriendListResult `json:"result"` | ||
| 449 | +} | ||
| 450 | + | ||
| 451 | + | ||
| 452 | +type GetAuditListReq struct{ | ||
| 453 | + Token string `json:"token"` | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | +type GetAuditListDesc struct { | ||
| 457 | + Approve_list []ApplyInfo `json:"approve_list"` | ||
| 458 | +} | ||
| 459 | + | ||
| 460 | +type GetAuditListResult struct { | ||
| 461 | + Code int `json:"code"` | ||
| 462 | + Data GetAuditListDesc `json:"data"` | ||
| 463 | +} | ||
| 464 | + | ||
| 465 | +type GetAuditListResp struct { | ||
| 466 | + Status string `json:"status"` | ||
| 467 | + Result GetAuditListResult `json:"result"` | ||
| 402 | } | 468 | } |
| 403 | 469 | ||
| 404 | 470 |
src/HttpServer/logic/errordef.go
| @@ -20,4 +20,13 @@ const ( | @@ -20,4 +20,13 @@ const ( | ||
| 20 | ERROR_TEAMNOTINTEAM = 15 //不在在队伍中无法再推出 | 20 | ERROR_TEAMNOTINTEAM = 15 //不在在队伍中无法再推出 |
| 21 | ERROR_GETUSERINFOBYIDFAILED = 16 //通过uid查询玩家数据失败 | 21 | ERROR_GETUSERINFOBYIDFAILED = 16 //通过uid查询玩家数据失败 |
| 22 | ERROR_GETTEAMLISTFAILED = 17 //查询队伍列表失败 | 22 | ERROR_GETTEAMLISTFAILED = 17 //查询队伍列表失败 |
| 23 | + ERROR_GETFRIENDLISTAILED = 18 //获取好友列表失败 | ||
| 24 | + ERROR_INLISTAILED = 19 //已经在好友列表无法再添加 | ||
| 25 | + ERROR_FRIENDISMAX = 20 //好友人数已经达到上限无法继续添加 | ||
| 26 | + ERROR_FRIENDGETAPPLISTFAILED = 21 //获取申请好友列表失败 | ||
| 27 | + ERROR_FRIENDAPPLYLIMIT = 22 //当日申请已达上限 | ||
| 28 | + ERROR_FRIENDALREDAYINAPPLYLIST = 23 //已经在申请列表 | ||
| 29 | + RROR_FRIENDGETAPPROVELISTFAILED = 24 //获取申请好友列表失败 | ||
| 30 | + RROR_FRIENDINAPPROVELISTFAILED = 25 //已经在等待批准列表 | ||
| 31 | + ERROR_FRIENDAPPROVELIMIT = 26 //当日批准已达上限 | ||
| 23 | ) | 32 | ) |
| 24 | \ No newline at end of file | 33 | \ No newline at end of file |
src/HttpServer/logic/function.go
| @@ -381,4 +381,155 @@ func GetTeamListByNameCond(shopnum int,page int, name string) (TeamSlice,error,i | @@ -381,4 +381,155 @@ func GetTeamListByNameCond(shopnum int,page int, name string) (TeamSlice,error,i | ||
| 381 | 381 | ||
| 382 | return rtslice[begin:end],nil,sumlen | 382 | return rtslice[begin:end],nil,sumlen |
| 383 | 383 | ||
| 384 | +} | ||
| 385 | + | ||
| 386 | +func (alist *ApproveList) InApproveList(uuid int) bool { | ||
| 387 | + for _,val := range alist.Approve_info { | ||
| 388 | + if val.Uuid == uuid { | ||
| 389 | + return true | ||
| 390 | + } | ||
| 391 | + } | ||
| 392 | + return false | ||
| 393 | +} | ||
| 394 | + | ||
| 395 | +//待批准列表 | ||
| 396 | +func GetUserApproveList(uuid int) (*ApproveList,error) { | ||
| 397 | + rt := new(ApproveList) | ||
| 398 | + //存储为hset key为 固定key+uuid ,field为被添加者的uuid,fieldW为FriendInfo | ||
| 399 | + userkey := redis.FRIEND_APPROVELIST_KEY + ":" + strconv.Itoa(uuid) | ||
| 400 | + vv,err := redishandler.GetRedisClient().HGetAllValues(userkey) | ||
| 401 | + if err != nil { | ||
| 402 | + logger.Error("GetUserApproveList err") | ||
| 403 | + return nil,err | ||
| 404 | + } | ||
| 405 | + | ||
| 406 | + nowtime:= int(time.Now().Unix()) | ||
| 407 | + for _,val := range vv { | ||
| 408 | + one := new(ApplyInfo) | ||
| 409 | + bytestr := val.([]byte) | ||
| 410 | + err = json.Unmarshal(bytestr, one) | ||
| 411 | + if err!= nil { | ||
| 412 | + //需要剔除超过时间的 | ||
| 413 | + if nowtime <= one.Apply_time + 3*86400 { | ||
| 414 | + rt.Approve_info = append(rt.Approve_info,*one) | ||
| 415 | + }else { | ||
| 416 | + //已经超时,需要删除 | ||
| 417 | + redishandler.GetRedisClient().HDel(userkey,strconv.Itoa(one.Uuid)) | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + } | ||
| 421 | + | ||
| 422 | + } | ||
| 423 | + return rt,nil | ||
| 424 | +} | ||
| 425 | + | ||
| 426 | +func SaveUserApproveList(uuid int,adduuid int) error { | ||
| 427 | + userkey := redis.FRIEND_APPROVELIST_KEY + ":" + strconv.Itoa(uuid) | ||
| 428 | + var finfo ApplyInfo | ||
| 429 | + finfo.Uuid = adduuid | ||
| 430 | + finfo.Apply_time = int(time.Now().Unix()) | ||
| 431 | + str,err := json.Marshal(&finfo) | ||
| 432 | + if err != nil { | ||
| 433 | + logger.Error("SaveUserApproveList failed,err=%v",err) | ||
| 434 | + } | ||
| 435 | + err = redishandler.GetRedisClient().HSet(userkey,strconv.Itoa(adduuid),string(str)) | ||
| 436 | + return err | ||
| 437 | +} | ||
| 438 | + | ||
| 439 | +func (alist *ApplyList) InApplyList(uuid int) bool { | ||
| 440 | + for _,val := range alist.Apply_info { | ||
| 441 | + if val.Uuid == uuid { | ||
| 442 | + return true | ||
| 443 | + } | ||
| 444 | + } | ||
| 445 | + return false | ||
| 446 | +} | ||
| 447 | + | ||
| 448 | +func GetUserApplyList(uuid int) (*ApplyList,error) { | ||
| 449 | + rt := new(ApplyList) | ||
| 450 | + //存储为hset key为 固定key+uuid ,field为被添加者的uuid,fieldW为FriendInfo | ||
| 451 | + userkey := redis.FRIEND_APPLYLIST_KEY + ":" + strconv.Itoa(uuid) | ||
| 452 | + vv,err := redishandler.GetRedisClient().HGetAllValues(userkey) | ||
| 453 | + if err != nil { | ||
| 454 | + logger.Error("GetUserApplyList err") | ||
| 455 | + return nil,err | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + nowtime:= int(time.Now().Unix()) | ||
| 459 | + for _,val := range vv { | ||
| 460 | + one := new(ApplyInfo) | ||
| 461 | + bytestr := val.([]byte) | ||
| 462 | + err = json.Unmarshal(bytestr, one) | ||
| 463 | + if err!= nil { | ||
| 464 | + //需要剔除超过时间的 | ||
| 465 | + if nowtime <= one.Apply_time + 86400 { | ||
| 466 | + rt.Apply_info = append(rt.Apply_info,*one) | ||
| 467 | + }else { | ||
| 468 | + //已经超时,需要删除 | ||
| 469 | + redishandler.GetRedisClient().HDel(userkey,strconv.Itoa(one.Uuid)) | ||
| 470 | + } | ||
| 471 | + | ||
| 472 | + } | ||
| 473 | + | ||
| 474 | + } | ||
| 475 | + return rt,nil | ||
| 476 | +} | ||
| 477 | + | ||
| 478 | +func SaveUserApplyList(uuid int,adduuid int) error { | ||
| 479 | + userkey := redis.FRIEND_APPLYLIST_KEY + ":" + strconv.Itoa(uuid) | ||
| 480 | + var finfo ApplyInfo | ||
| 481 | + finfo.Uuid = adduuid | ||
| 482 | + finfo.Apply_time = int(time.Now().Unix()) | ||
| 483 | + str,err := json.Marshal(&finfo) | ||
| 484 | + if err != nil { | ||
| 485 | + logger.Error("SaveUserApplyList failed,err=%v",err) | ||
| 486 | + } | ||
| 487 | + err = redishandler.GetRedisClient().HSet(userkey,strconv.Itoa(adduuid),string(str)) | ||
| 488 | + return err | ||
| 489 | +} | ||
| 490 | + | ||
| 491 | +func GetUserFriendList(uuid int) (*FriendList,error) { | ||
| 492 | + //todo | ||
| 493 | + rt := new(FriendList) | ||
| 494 | + //存储为hset key为 固定key+uuid ,field为被添加者的uuid,fieldW为FriendInfo | ||
| 495 | + userkey := redis.FRIEND_LIST_KEY + ":" + strconv.Itoa(uuid) | ||
| 496 | + vv,err := redishandler.GetRedisClient().HGetAllValues(userkey) | ||
| 497 | + if err != nil { | ||
| 498 | + logger.Error("GetUserFriendList err") | ||
| 499 | + return nil,err | ||
| 500 | + } | ||
| 501 | + | ||
| 502 | + for _,val := range vv { | ||
| 503 | + one := new(FriendInfo) | ||
| 504 | + bytestr := val.([]byte) | ||
| 505 | + err = json.Unmarshal(bytestr, one) | ||
| 506 | + if err!= nil { | ||
| 507 | + rt.Friends = append(rt.Friends,*one) | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + } | ||
| 511 | + return rt,nil | ||
| 512 | +} | ||
| 513 | + | ||
| 514 | +func SaveUserFriendList(uuid int,adduuid int) error { | ||
| 515 | + userkey := redis.FRIEND_LIST_KEY + ":" + strconv.Itoa(uuid) | ||
| 516 | + var finfo FriendInfo | ||
| 517 | + finfo.Uuid = adduuid | ||
| 518 | + finfo.Status = 0 | ||
| 519 | + str,err := json.Marshal(&finfo) | ||
| 520 | + if err != nil { | ||
| 521 | + logger.Error("SaveUserFriendList failed,err=%v",err) | ||
| 522 | + } | ||
| 523 | + err = redishandler.GetRedisClient().HSet(userkey,strconv.Itoa(adduuid),string(str)) | ||
| 524 | + return err | ||
| 525 | +} | ||
| 526 | + | ||
| 527 | +//判断是否已经是好友 | ||
| 528 | +func (flist *FriendList) IsInFreiendList(uuid int) bool { | ||
| 529 | + for _,val := range flist.Friends { | ||
| 530 | + if val.Uuid == uuid && val.Status == 0 { | ||
| 531 | + return true | ||
| 532 | + } | ||
| 533 | + } | ||
| 534 | + return false | ||
| 384 | } | 535 | } |
| 385 | \ No newline at end of file | 536 | \ No newline at end of file |
src/HttpServer/logic/httpserver.go
| @@ -46,12 +46,49 @@ func startServerHttpServe() { | @@ -46,12 +46,49 @@ func startServerHttpServe() { | ||
| 46 | http.HandleFunc("/catcafe/team/getDataByUserId", GetDataByUserId) //获取队伍成员的详细数据 | 46 | http.HandleFunc("/catcafe/team/getDataByUserId", GetDataByUserId) //获取队伍成员的详细数据 |
| 47 | http.HandleFunc("/catcafe/team/getTeamList", GetTeamList) //查询队伍列表 | 47 | http.HandleFunc("/catcafe/team/getTeamList", GetTeamList) //查询队伍列表 |
| 48 | http.HandleFunc("/catcafe/team/searchTeam", SearchTeam) //根据名称搜索队伍 | 48 | http.HandleFunc("/catcafe/team/searchTeam", SearchTeam) //根据名称搜索队伍 |
| 49 | + http.HandleFunc("/catcafe/friend/setFriendRequest", SetFriendRequest) //申请添加好友 | ||
| 50 | + http.HandleFunc("/catcafe/friend/getList", GetFriendList) //获取好友列表 | ||
| 51 | + http.HandleFunc("/catcafe/friend/getAuditList", GetAuditList) //获取待审核好友列表 | ||
| 49 | 52 | ||
| 50 | 53 | ||
| 51 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 54 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
| 52 | CheckErr(err) | 55 | CheckErr(err) |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 58 | +func GetAuditList(w http.ResponseWriter, r *http.Request) { | ||
| 59 | + | ||
| 60 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 61 | + r.Body.Close() | ||
| 62 | + | ||
| 63 | + s := string(result) | ||
| 64 | + logger.Info("GetAuditList , body:%v,uuid=%v", s) | ||
| 65 | + | ||
| 66 | + HandleGetAuditList(w,s) | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | + | ||
| 70 | +func GetFriendList(w http.ResponseWriter, r *http.Request) { | ||
| 71 | + | ||
| 72 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 73 | + r.Body.Close() | ||
| 74 | + | ||
| 75 | + s := string(result) | ||
| 76 | + logger.Info("GetFriendList , body:%v,uuid=%v", s) | ||
| 77 | + | ||
| 78 | + HandleGetFriendList(w,s) | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +func SetFriendRequest(w http.ResponseWriter, r *http.Request) { | ||
| 82 | + | ||
| 83 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 84 | + r.Body.Close() | ||
| 85 | + | ||
| 86 | + s := string(result) | ||
| 87 | + logger.Info("SetFriendRequest , body:%v,uuid=%v", s) | ||
| 88 | + | ||
| 89 | + HandleSetFriendRequest(w,s) | ||
| 90 | +} | ||
| 91 | + | ||
| 55 | func SearchTeam(w http.ResponseWriter, r *http.Request) { | 92 | func SearchTeam(w http.ResponseWriter, r *http.Request) { |
| 56 | 93 | ||
| 57 | result, _ := ioutil.ReadAll(r.Body) | 94 | result, _ := ioutil.ReadAll(r.Body) |
src/HttpServer/logic/logic.go
| @@ -1141,4 +1141,190 @@ func HandleSearchTeam(w http.ResponseWriter, data string) { | @@ -1141,4 +1141,190 @@ func HandleSearchTeam(w http.ResponseWriter, data string) { | ||
| 1141 | //回包 | 1141 | //回包 |
| 1142 | respstr, _ := json.Marshal(&resp) | 1142 | respstr, _ := json.Marshal(&resp) |
| 1143 | fmt.Fprint(w, string(respstr)) | 1143 | fmt.Fprint(w, string(respstr)) |
| 1144 | -} | ||
| 1145 | \ No newline at end of file | 1144 | \ No newline at end of file |
| 1145 | +} | ||
| 1146 | + | ||
| 1147 | + | ||
| 1148 | +func HandleSetFriendRequest(w http.ResponseWriter, data string) { | ||
| 1149 | + SetHeader(w) | ||
| 1150 | + var resp SetFriendResp | ||
| 1151 | + resp.Status = "true" | ||
| 1152 | + resp.Result.Code = ERROR_OK | ||
| 1153 | + var rdata SetFriendReq | ||
| 1154 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 1155 | + for { | ||
| 1156 | + if err != nil { | ||
| 1157 | + logger.Error("HandleSetFriendRequest json unmarshal failed=%v", err) | ||
| 1158 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
| 1159 | + break | ||
| 1160 | + } | ||
| 1161 | + | ||
| 1162 | + uuid,err := GetTouristUid(rdata.Token) | ||
| 1163 | + if err != nil || uuid==0{ | ||
| 1164 | + logger.Error("HandleSetFriendRequest GetTouristUid failed=%v", err) | ||
| 1165 | + resp.Result.Code = ERROR_GETUSERIDFAILED | ||
| 1166 | + break | ||
| 1167 | + } | ||
| 1168 | + | ||
| 1169 | + //先判断是否是好友关系 | ||
| 1170 | + list,err := GetUserFriendList(rdata.User_id) | ||
| 1171 | + if err != nil { | ||
| 1172 | + logger.Error("HandleSetFriendRequest GetFriendList failed=%v", err) | ||
| 1173 | + resp.Result.Code = ERROR_GETFRIENDLISTAILED | ||
| 1174 | + break | ||
| 1175 | + } | ||
| 1176 | + inlist := list.IsInFreiendList(uuid) | ||
| 1177 | + if inlist { | ||
| 1178 | + logger.Error("HandleSetFriendRequest InFriendList failed=%v", err) | ||
| 1179 | + resp.Result.Code = ERROR_INLISTAILED | ||
| 1180 | + break | ||
| 1181 | + } | ||
| 1182 | + | ||
| 1183 | + //判断自己的好友人数是否已经达到上限 | ||
| 1184 | + ownlist,err := GetUserFriendList(uuid) | ||
| 1185 | + if err != nil { | ||
| 1186 | + logger.Error("HandleSetFriendRequest GetFriendList failed=%v", err) | ||
| 1187 | + resp.Result.Code = ERROR_GETFRIENDLISTAILED | ||
| 1188 | + break | ||
| 1189 | + } | ||
| 1190 | + //判断好友人数上限 | ||
| 1191 | + if len(list.Friends) >= FRIEND_MAX_NUM || len(ownlist.Friends) >= FRIEND_MAX_NUM { | ||
| 1192 | + logger.Error("HandleSetFriendRequest FRIENDMAX failed=%v", err) | ||
| 1193 | + resp.Result.Code = ERROR_FRIENDISMAX | ||
| 1194 | + break | ||
| 1195 | + } | ||
| 1196 | + | ||
| 1197 | + //判断申请列表是否已经有对该玩家的申请 24小时,此处需要判断24小时内的申请次数上限,需要先提出超过24小时的申请 | ||
| 1198 | + applylist,err := GetUserApplyList(uuid) | ||
| 1199 | + if err != nil { | ||
| 1200 | + logger.Error("HandleSetFriendRequest GetApplyListFailed failed=%v", err) | ||
| 1201 | + resp.Result.Code = ERROR_FRIENDGETAPPLISTFAILED | ||
| 1202 | + break | ||
| 1203 | + } | ||
| 1204 | + | ||
| 1205 | + if applylist.InApplyList(rdata.User_id) { | ||
| 1206 | + logger.Error("HandleSetFriendRequest ALREDAYINAPPLYLIST failed=%v", err) | ||
| 1207 | + resp.Result.Code = ERROR_FRIENDALREDAYINAPPLYLIST | ||
| 1208 | + break | ||
| 1209 | + } | ||
| 1210 | + | ||
| 1211 | + if len(applylist.Apply_info) >=FRIEND_APPLY_LIMIT { | ||
| 1212 | + logger.Error("HandleSetFriendRequest Apply limit failed=%v", err) | ||
| 1213 | + resp.Result.Code = ERROR_FRIENDAPPLYLIMIT | ||
| 1214 | + break | ||
| 1215 | + } | ||
| 1216 | + | ||
| 1217 | + //加入对方列表,如果已经在对方待批准列表则返回错误 | ||
| 1218 | + approvelist,err := GetUserApproveList(rdata.User_id) | ||
| 1219 | + if err != nil { | ||
| 1220 | + logger.Error("HandleSetFriendRequest GetApproveListFailed failed=%v", err) | ||
| 1221 | + resp.Result.Code = RROR_FRIENDGETAPPROVELISTFAILED | ||
| 1222 | + break | ||
| 1223 | + } | ||
| 1224 | + | ||
| 1225 | + if approvelist.InApproveList(uuid) { | ||
| 1226 | + logger.Error("HandleSetFriendRequest inApprovelist failed=%v", err) | ||
| 1227 | + resp.Result.Code = RROR_FRIENDINAPPROVELISTFAILED | ||
| 1228 | + break | ||
| 1229 | + } | ||
| 1230 | + | ||
| 1231 | + if len(approvelist.Approve_info) >=FRIEND_APPROVE_LIMIT { | ||
| 1232 | + logger.Error("HandleSetFriendRequest Apply limit failed=%v", err) | ||
| 1233 | + resp.Result.Code = ERROR_FRIENDAPPROVELIMIT | ||
| 1234 | + break | ||
| 1235 | + } | ||
| 1236 | + | ||
| 1237 | + //添加到对方的待批准记录 | ||
| 1238 | + SaveUserApplyList(uuid,rdata.User_id) | ||
| 1239 | + | ||
| 1240 | + //添加到自己的申请记录 | ||
| 1241 | + SaveUserApproveList(rdata.User_id,uuid) | ||
| 1242 | + | ||
| 1243 | + //清空好友推荐缓存 | ||
| 1244 | + //TODO | ||
| 1245 | + | ||
| 1246 | + resp.Result.Code = ERROR_OK | ||
| 1247 | + break | ||
| 1248 | + } | ||
| 1249 | + | ||
| 1250 | + //回包 | ||
| 1251 | + respstr, _ := json.Marshal(&resp) | ||
| 1252 | + fmt.Fprint(w, string(respstr)) | ||
| 1253 | +} | ||
| 1254 | + | ||
| 1255 | +func HandleGetFriendList(w http.ResponseWriter, data string) { | ||
| 1256 | + SetHeader(w) | ||
| 1257 | + var resp GetFriendListResp | ||
| 1258 | + resp.Status = "true" | ||
| 1259 | + resp.Result.Code = ERROR_OK | ||
| 1260 | + var rdata GetFriendListReq | ||
| 1261 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 1262 | + for { | ||
| 1263 | + if err != nil { | ||
| 1264 | + logger.Error("HandleGetFriendList json unmarshal failed=%v", err) | ||
| 1265 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
| 1266 | + break | ||
| 1267 | + } | ||
| 1268 | + | ||
| 1269 | + uuid,err := GetTouristUid(rdata.Token) | ||
| 1270 | + if err != nil || uuid==0{ | ||
| 1271 | + logger.Error("HandleGetFriendList GetTouristUid failed=%v", err) | ||
| 1272 | + resp.Result.Code = ERROR_GETUSERIDFAILED | ||
| 1273 | + break | ||
| 1274 | + } | ||
| 1275 | + | ||
| 1276 | + friendlist,err := GetUserFriendList(uuid) | ||
| 1277 | + if err != nil { | ||
| 1278 | + logger.Error("HandleSetFriendRequest GetFriendList failed=%v", err) | ||
| 1279 | + resp.Result.Code = ERROR_GETFRIENDLISTAILED | ||
| 1280 | + break | ||
| 1281 | + } | ||
| 1282 | + resp.Result.Data.Friend_list = append(resp.Result.Data.Friend_list,friendlist.Friends...) | ||
| 1283 | + | ||
| 1284 | + resp.Result.Code = ERROR_OK | ||
| 1285 | + break | ||
| 1286 | + } | ||
| 1287 | + | ||
| 1288 | + //回包 | ||
| 1289 | + respstr, _ := json.Marshal(&resp) | ||
| 1290 | + fmt.Fprint(w, string(respstr)) | ||
| 1291 | +} | ||
| 1292 | + | ||
| 1293 | + | ||
| 1294 | +func HandleGetAuditList(w http.ResponseWriter, data string) { | ||
| 1295 | + SetHeader(w) | ||
| 1296 | + var resp GetAuditListResp | ||
| 1297 | + resp.Status = "true" | ||
| 1298 | + resp.Result.Code = ERROR_OK | ||
| 1299 | + var rdata GetAuditListReq | ||
| 1300 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 1301 | + for { | ||
| 1302 | + if err != nil { | ||
| 1303 | + logger.Error("HandleGetAuditList json unmarshal failed=%v", err) | ||
| 1304 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
| 1305 | + break | ||
| 1306 | + } | ||
| 1307 | + | ||
| 1308 | + uuid,err := GetTouristUid(rdata.Token) | ||
| 1309 | + if err != nil || uuid==0{ | ||
| 1310 | + logger.Error("HandleGetAuditList GetTouristUid failed=%v", err) | ||
| 1311 | + resp.Result.Code = ERROR_GETUSERIDFAILED | ||
| 1312 | + break | ||
| 1313 | + } | ||
| 1314 | + | ||
| 1315 | + approvelist,err := GetUserApproveList(uuid) | ||
| 1316 | + if err != nil { | ||
| 1317 | + logger.Error("HandleGetAuditList Getapprovelistfailedt failed=%v", err) | ||
| 1318 | + resp.Result.Code = RROR_FRIENDGETAPPROVELISTFAILED | ||
| 1319 | + break | ||
| 1320 | + } | ||
| 1321 | + resp.Result.Data.Approve_list = append(resp.Result.Data.Approve_list,approvelist.Approve_info...) | ||
| 1322 | + | ||
| 1323 | + resp.Result.Code = ERROR_OK | ||
| 1324 | + break | ||
| 1325 | + } | ||
| 1326 | + | ||
| 1327 | + //回包 | ||
| 1328 | + respstr, _ := json.Marshal(&resp) | ||
| 1329 | + fmt.Fprint(w, string(respstr)) | ||
| 1330 | +} | ||
| 1331 | + |
src/common/redis/def.go
| @@ -11,4 +11,7 @@ const ( | @@ -11,4 +11,7 @@ const ( | ||
| 11 | TEAM_INFO = "CATCAFE_TEAM_INFO" //存储了玩家队伍信息 | 11 | TEAM_INFO = "CATCAFE_TEAM_INFO" //存储了玩家队伍信息 |
| 12 | TEAM_MAX_UUID = "CATCAFE_TEAM_MAX_UUID" //记录当前最大的teamid,新增自增即可 | 12 | TEAM_MAX_UUID = "CATCAFE_TEAM_MAX_UUID" //记录当前最大的teamid,新增自增即可 |
| 13 | TEAM_TEAMID_TOUUID = "CATCAFE_TEAM_TEAMID_TOUUID" //记录teamid与uuid的关系 | 13 | TEAM_TEAMID_TOUUID = "CATCAFE_TEAM_TEAMID_TOUUID" //记录teamid与uuid的关系 |
| 14 | + FRIEND_LIST_KEY = "CATCAFE_FRIEND_LIST_KEY" //玩家的好友列表的key,需要在末尾加死":uuid" | ||
| 15 | + FRIEND_APPLYLIST_KEY = "CATCAFE_FRIEND_APPLYLIST_KEY" //玩家申请好友列表,需要在末尾加死":uuid" | ||
| 16 | + FRIEND_APPROVELIST_KEY = "CATCAFE_FRIEND_APPROVELIST_KEY" //待批准好友列表,需要在末尾加死":uuid" | ||
| 14 | ) | 17 | ) |