package logic import ( "HttpServer/redishandler" "common/logger" "common/redis" "encoding/json" "net/http" "sort" "strconv" "strings" "time" ) func SetHeader(w http.ResponseWriter) { w.Header().Set("Access-Control-Allow-Origin", "*") //允许访问所有域 w.Header().Set("Content-Type", "application/json") w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Uuid") } func (tinfo *TeamInfo) DoAddBuffTimee(btype int,muti int,resp *AddTeamBuffResp) { addtime := 1800*muti index := 0 for k,val := range tinfo.BInfo.Buff { if val.Type == btype { index = k } } for i:=0;i= nowtime { tinfo.BInfo.Buff[index].BuffInfo[len(tinfo.BInfo.Buff[index].BuffInfo)-1].EndTime += addTime } else { var tmp TeamBuffInfo tmp.BeginTime = nowtime tmp.EndTime = nowtime + addTime tinfo.BInfo.Buff[index].BuffInfo = append(tinfo.BInfo.Buff[index].BuffInfo,tmp) } }else { tinfo.BInfo.Buff[index].BuffInfo[len(tinfo.BInfo.Buff[index].BuffInfo)-1].EndTime += 86399 } //删除掉无用的 yestime := nowtime-86400 for i:=0;i sumlen{ begin = sumlen - 10 } if end > sumlen { end = sumlen - 1 } return rtslice[begin:end],nil,sumlen } func GetTeamListByNameCond(shopnum int,page int, name string) (TeamSlice,error,int) { if page < 0 { logger.Error("GetTeamListByCond invalid page=%v",page) page = 1 } var rtslice TeamSlice vv,err := redishandler.GetRedisClient().HGetAllValues(redis.TEAM_INFO) if err != nil { logger.Error("GetTeamListByCond err") return nil,err,0 } for _,val := range vv { one := new(TeamInfo) bytestr := val.([]byte) err = json.Unmarshal(bytestr, one) if err == nil { if one.BaseInfo.Num <= shopnum && strings.Index(one.BaseInfo.Name,name) != -1{ rtslice = append(rtslice,one) } } } //排序 sort.Sort(rtslice) begin := (page-1) * 10 end := begin + 9 sumlen := len(rtslice) if begin > sumlen{ begin = sumlen - 10 } if end > sumlen { end = sumlen - 1 } return rtslice[begin:end],nil,sumlen } func (alist *ApproveList) InApproveList(uuid int) bool { for _,val := range alist.Approve_info { if val.Uuid == uuid { return true } } return false } //待批准列表 func GetUserApproveList(uuid int) (*ApproveList,error) { rt := new(ApproveList) //存储为hset key为 固定key+uuid ,field为被添加者的uuid,fieldW为FriendInfo userkey := redis.FRIEND_APPROVELIST_KEY + ":" + strconv.Itoa(uuid) vv,err := redishandler.GetRedisClient().HGetAllValues(userkey) if err != nil { logger.Error("GetUserApproveList err") return nil,err } nowtime:= int(time.Now().Unix()) for _,val := range vv { one := new(ApplyInfo) bytestr := val.([]byte) err = json.Unmarshal(bytestr, one) if err!= nil { //需要剔除超过时间的 if nowtime <= one.Apply_time + 3*86400 { rt.Approve_info = append(rt.Approve_info,*one) }else { //已经超时,需要删除 redishandler.GetRedisClient().HDel(userkey,strconv.Itoa(one.Uuid)) } } } return rt,nil } func SaveUserApproveList(uuid int,adduuid int) error { userkey := redis.FRIEND_APPROVELIST_KEY + ":" + strconv.Itoa(uuid) var finfo ApplyInfo finfo.Uuid = adduuid finfo.Apply_time = int(time.Now().Unix()) str,err := json.Marshal(&finfo) if err != nil { logger.Error("SaveUserApproveList failed,err=%v",err) } err = redishandler.GetRedisClient().HSet(userkey,strconv.Itoa(adduuid),string(str)) return err } func (alist *ApplyList) InApplyList(uuid int) bool { for _,val := range alist.Apply_info { if val.Uuid == uuid { return true } } return false } func GetUserApplyList(uuid int) (*ApplyList,error) { rt := new(ApplyList) //存储为hset key为 固定key+uuid ,field为被添加者的uuid,fieldW为FriendInfo userkey := redis.FRIEND_APPLYLIST_KEY + ":" + strconv.Itoa(uuid) vv,err := redishandler.GetRedisClient().HGetAllValues(userkey) if err != nil { logger.Error("GetUserApplyList err") return nil,err } nowtime:= int(time.Now().Unix()) for _,val := range vv { one := new(ApplyInfo) bytestr := val.([]byte) err = json.Unmarshal(bytestr, one) if err!= nil { //需要剔除超过时间的 if nowtime <= one.Apply_time + 86400 { rt.Apply_info = append(rt.Apply_info,*one) }else { //已经超时,需要删除 redishandler.GetRedisClient().HDel(userkey,strconv.Itoa(one.Uuid)) } } } return rt,nil } func SaveUserApplyList(uuid int,adduuid int) error { userkey := redis.FRIEND_APPLYLIST_KEY + ":" + strconv.Itoa(uuid) var finfo ApplyInfo finfo.Uuid = adduuid finfo.Apply_time = int(time.Now().Unix()) str,err := json.Marshal(&finfo) if err != nil { logger.Error("SaveUserApplyList failed,err=%v",err) } err = redishandler.GetRedisClient().HSet(userkey,strconv.Itoa(adduuid),string(str)) return err } func GetUserFriendList(uuid int) (*FriendList,error) { //todo rt := new(FriendList) //存储为hset key为 固定key+uuid ,field为被添加者的uuid,fieldW为FriendInfo userkey := redis.FRIEND_LIST_KEY + ":" + strconv.Itoa(uuid) vv,err := redishandler.GetRedisClient().HGetAllValues(userkey) if err != nil { logger.Error("GetUserFriendList err") return nil,err } for _,val := range vv { one := new(FriendInfo) bytestr := val.([]byte) err = json.Unmarshal(bytestr, one) if err!= nil { rt.Friends = append(rt.Friends,*one) } } return rt,nil } func SaveUserFriendList(uuid int,adduuid int) error { userkey := redis.FRIEND_LIST_KEY + ":" + strconv.Itoa(uuid) var finfo FriendInfo finfo.Uuid = adduuid finfo.Status = 0 str,err := json.Marshal(&finfo) if err != nil { logger.Error("SaveUserFriendList failed,err=%v",err) } err = redishandler.GetRedisClient().HSet(userkey,strconv.Itoa(adduuid),string(str)) return err } //判断是否已经是好友 func (flist *FriendList) IsInFreiendList(uuid int) bool { for _,val := range flist.Friends { if val.Uuid == uuid && val.Status == 0 { return true } } return false }