go_dreamfactory/modules/pvp/modelPvp.go
2023-04-12 18:18:36 +08:00

69 lines
1.7 KiB
Go

package pvp
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
)
///Pvp 数据组件
type modelPvpComp struct {
modules.MCompModel
module *Pvp
}
//组件初始化接口 此表不写入到数据库中
func (this *modelPvpComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Pvp)
this.TableName = comm.TablePvp
//创建uid索引
// this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
// Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
// })
return
}
//查询用户重置数据
func (this *modelPvpComp) querypvps() (result []*pb.DBPvpBattle, err error) {
result = make([]*pb.DBPvpBattle, 0)
if err = this.GetList("", &result); err != nil && err != mgo.MongodbNil {
this.module.Errorf("err:%v", err)
}
if err == mgo.MongodbNil {
err = nil
}
return
}
//查询用户重置数据
func (this *modelPvpComp) querypvp(id string) (result *pb.DBPvpBattle, err error) {
result = &pb.DBPvpBattle{}
if err = this.GetListObj("", id, result); err != nil && err != mgo.MongodbNil {
this.module.Errorf("err:%v", err)
}
if err == mgo.MongodbNil {
err = nil
}
return
}
//记录战斗信息
func (this *modelPvpComp) addpvp(battle *pb.DBPvpBattle) (err error) {
if err = this.AddList("", battle.Id, battle, db.SetDBMgoLog(false)); err != nil {
this.module.Errorln(err)
}
return
}
//删除pvp记录
func (this *modelPvpComp) delpvp(battleid string) (err error) {
if err = this.DelListlds("", []string{battleid}, db.SetDBMgoLog(false)); err != nil {
this.module.Errorln(err)
}
return
}