package pagoda import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/redis/pipe" "go_dreamfactory/pb" "go_dreamfactory/sys/db" "github.com/go-redis/redis/v8" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.PagodaGetListReq) (code pb.ErrorCode) { uid := session.GetUserId() if !this.module.IsCross() { if conn, err := db.Cross(); err == nil { //userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) // newData := &pb.DBPagodaRecord{ // Id: primitive.NewObjectID().Hex(), // Uid: session.GetUserId(), // PagodaId: 111, // Type: 201, // Nickname: userinfo.Name, // Icon: "", // icon 暂无 // Lv: userinfo.Lv, // CostTime: 1002, // } //conn.Mgo.InsertOne(comm.TablePagodaRecord, newData) var ( pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO()) menbers *redis.Z ) menbers = &redis.Z{Score: float64(500), Member: uid} if cmd := pipe.ZAdd("pagodaList", menbers); cmd != nil { this.module.Errorln(err) dock, err1 := cmd.Result() this.module.Errorln(dock, err1) } if _, err = pipe.Exec(); err != nil { this.module.Errorln(err) return } //rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567") rd := pipe.ZRange("pagodaList", 1, 5) if _, err = pipe.Exec(); err != nil { this.module.Errorln(err) return } _data3 := rd.Val() _data, err2 := rd.Result() this.module.Errorln(_data, err2, _data3) } } return } ///获取主线关卡信息 func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq) (code pb.ErrorCode, data proto.Message) { var ( list *pb.DBPagoda ) this.GetListCheck(session, req) expand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } if !expand.CompletePagoda { // 普通塔 list, _ = this.module.modelPagoda.getPagodaList(session.GetUserId()) if list == nil { // redis没有数据 list = &pb.DBPagoda{} list.Id = primitive.NewObjectID().Hex() list.Uid = session.GetUserId() list.PagodaId = 0 // 初始数据0层 list.Type = comm.PagodaType this.module.modelPagoda.addNewPagoda(session.GetUserId(), list) } } else { season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) if season.Id == "" { season.Id = primitive.NewObjectID().Hex() season.Uid = session.GetUserId() season.PagodaId = 0 // 初始数据0层 if conn, err := db.Cross(); err == nil { rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) server := &pb.DBServerData{} rst.Decode(server) season.Type = server.SeasonType } this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), season) } list = &pb.DBPagoda{ Id: season.Id, Uid: season.Uid, PagodaId: season.PagodaId, Reward: season.Reward, Type: season.Type, } } session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) return }