72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type ModelRace struct {
|
|
modules.MCompModel
|
|
module *Pagoda
|
|
}
|
|
|
|
func (this *ModelRace) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableRacePagoda)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Pagoda)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取爬塔信息
|
|
func (this *ModelRace) getPagodaRaceList(uid string) (result *pb.DBPagodaRace, err error) {
|
|
result = &pb.DBPagodaRace{
|
|
Race: map[int32]*pb.RaceData{},
|
|
}
|
|
if err = this.Get(uid, result); err != nil && err == mgo.MongodbNil { // 初始一条数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
result.Race = make(map[int32]*pb.RaceData)
|
|
if c := this.module.configure.GetRaceCirculateConf(); len(c) > 0 {
|
|
result.Race[c[0]] = &pb.RaceData{ // 第一赛季阵营id默认就是10
|
|
Race: c[0],
|
|
Task: []int32{},
|
|
Rtime: configure.Now().Unix(),
|
|
Defeat: 0,
|
|
Endtime: this.module.GetSeasonData(),
|
|
Curfloor: 0,
|
|
}
|
|
}
|
|
err = this.addPagodaRace(uid, result)
|
|
|
|
return
|
|
}
|
|
|
|
return result, err
|
|
}
|
|
|
|
// 修改爬塔数据信息
|
|
func (this *ModelRace) ModifyPagodaRaceDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// 创建一个新的塔数据
|
|
func (this *ModelRace) addPagodaRace(uId string, data *pb.DBPagodaRace) (err error) {
|
|
if err = this.Add(uId, data); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return nil
|
|
}
|