71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package hunting
|
|
|
|
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 modelHunting struct {
|
|
modules.MCompModel
|
|
module *Hunting
|
|
}
|
|
|
|
func (this *modelHunting) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableHunting)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Hunting)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelHunting) modifyHuntingDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// 获取列表信息
|
|
func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err error) {
|
|
result = &pb.DBHunting{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if mgo.MongodbNil == err {
|
|
result = &pb.DBHunting{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Boss: make(map[int32]int32),
|
|
BossTime: make(map[string]int32),
|
|
Ps: map[int32]int32{},
|
|
}
|
|
|
|
this.Add(uid, result)
|
|
err = nil
|
|
}
|
|
return
|
|
}
|
|
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
// 红点检测
|
|
func (this *modelHunting) checkReddot32(session comm.IUserSession) bool {
|
|
if list, err := this.module.modelHunting.getHuntingList(session.GetUserId()); err == nil {
|
|
if _, ok := list.Boss[1]; ok {
|
|
conf, _ := this.module.configure.GetHuntingBossConfigData(1, 1)
|
|
if errdata := this.module.CheckRes(session, conf.PsConsume); errdata == nil {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|