71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ActivateCheck(session comm.IUserSession, req *pb.PagodaActivateReq) (code pb.ErrorCode) {
|
|
|
|
return
|
|
}
|
|
|
|
///获取主线关卡信息
|
|
func (this *apiComp) Activate(session comm.IUserSession, req *pb.PagodaActivateReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
list *pb.DBPagoda
|
|
)
|
|
list, err := this.module.modelPagoda.getPagodaList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, list.PagodaId+1)
|
|
if Nomalcfg == nil && !list.Complete {
|
|
list.Complete = true
|
|
this.module.ModifyPagodaData(session.GetUserId(), map[string]interface{}{
|
|
"complete": true,
|
|
})
|
|
}
|
|
if list.Complete {
|
|
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
|
|
|
|
dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn)
|
|
if err = dbModel.Add(session.GetUserId(), season); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
|
|
}
|
|
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()), PagodaActivateResp, &pb.PagodaActivateResp{Data: list})
|
|
return
|
|
}
|