70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package viking
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelViking struct {
|
|
modules.MCompModel
|
|
module *Viking
|
|
}
|
|
|
|
func (this *modelViking) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableViking)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Viking)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err error) {
|
|
result = &pb.DBViking{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if mgo.MongodbNil == err {
|
|
result = &pb.DBViking{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Boss: make(map[int32]int32),
|
|
BossTime: make(map[string]int32),
|
|
Ps: make(map[int32]int32),
|
|
}
|
|
err = nil
|
|
this.module.modelViking.Add(uid, result)
|
|
}
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
func (this *modelViking) modifyVikingDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// 红点检测
|
|
func (this *modelViking) checkReddot31(session comm.IUserSession) bool {
|
|
|
|
if list, err := this.module.modelViking.getVikingList(session.GetUserId()); err == nil {
|
|
if _, ok := list.Boss[1]; ok {
|
|
if conf, _ := this.module.configure.GetVikingBossConfigData(1, 1); conf != nil {
|
|
if errdata := this.module.CheckRes(session, conf.PsConsume); errdata == nil {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|