go_dreamfactory/modules/plunder/model_plunder.go
2024-01-16 16:35:06 +08:00

50 lines
1.2 KiB
Go

package plunder
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 modelPlunder struct {
modules.MCompModel
module *Plunder
}
func (this *modelPlunder) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompModel.Init(service, module, comp, options)
this.TableName = comm.TablePlunder
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 获取猴拳基本数据
func (this *modelPlunder) getPlunderData(uid string) (info *pb.DBPlunder, err error) {
info = &pb.DBPlunder{}
if err = this.Get(uid, info); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
if err == mgo.MongodbNil {
info = &pb.DBPlunder{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
}
err = this.Add(uid, info)
}
return
}
func (this *modelPlunder) changePlunderData(uid string, update map[string]interface{}) (err error) {
err = this.Change(uid, update)
return
}