70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
/// 赛季塔
|
|
type ModelSeasonPagoda struct {
|
|
modules.MCompModel
|
|
module *Pagoda
|
|
}
|
|
|
|
func (this *ModelSeasonPagoda) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableSeasonPagoda)
|
|
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 *ModelSeasonPagoda) getSeasonPagodaList(uid string) (result *pb.DBSeasonPagoda, err error) {
|
|
result = &pb.DBSeasonPagoda{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if redis.RedisNil != err {
|
|
result = nil
|
|
}
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
// 修改爬塔数据信息
|
|
func (this *ModelSeasonPagoda) modifySeasonPagodaDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// 创建一个新的赛季塔数据
|
|
func (this *ModelSeasonPagoda) addNewSeasonPagoda(uId string, data *pb.DBSeasonPagoda) (err error) {
|
|
//err = this.InsertModelLogs(this.TableName, uId, []interface{}{data}) // 不需要经过redis
|
|
if err = this.Add(uId, data); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 赛季结束 清理所有塔数据
|
|
func (this *ModelSeasonPagoda) DleAllSeasonData() {
|
|
this.DB.DeleteMany(core.SqlTable(this.TableName), bson.M{})
|
|
err := this.Redis.Ltrim(comm.TablePagodaRecord, 0, -1)
|
|
if err != nil {
|
|
log.Errorf("delete failed")
|
|
}
|
|
return
|
|
}
|