52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package monkey
|
|
|
|
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 modelComp struct {
|
|
modules.MCompModel
|
|
module *Monkey
|
|
}
|
|
|
|
func (this *modelComp) 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.TableMonkey
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取猴拳基本数据
|
|
func (this *modelComp) getMonkeyData(uid string) (info *pb.DBMonkey, err error) {
|
|
info = &pb.DBMonkey{}
|
|
if err = this.Get(uid, info); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
info = &pb.DBMonkey{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Reward: map[int32]int32{},
|
|
Data: map[int32]*pb.ChapterData{},
|
|
}
|
|
err = this.Add(uid, info)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *modelComp) changeMonkeyData(uid string, update map[string]interface{}) (err error) {
|
|
err = this.Change(uid, update)
|
|
return
|
|
}
|