go_dreamfactory/modules/hunting/model_hunting.go
2022-12-23 10:00:51 +08:00

61 lines
1.4 KiB
Go

package hunting
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"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 {
return
}
err = nil
return result, err
}
// 红点检测
func (this *modelHunting) checkReddot32(uid string) bool {
conf := this.module.configure.GetGlobalConf()
if conf == nil {
return false
}
costRes := conf.HuntingCos
if costRes == nil {
return false
}
amount := int32(this.module.ModuleItems.QueryItemAmount(uid, costRes.T)) // 获取当前数量
if amount > 0 {
return true
}
return false
}