46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package egghunt
|
|
|
|
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 *Egghunt
|
|
}
|
|
|
|
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.TableEgghunt
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取用户全部的埋点数据
|
|
func (this *modelComp) getModel(uid string) (info *pb.DBEgghunt, err error) {
|
|
info = &pb.DBEgghunt{}
|
|
if err = this.Get(uid, info); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
info = &pb.DBEgghunt{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Egg: make(map[int32]int64),
|
|
}
|
|
err = this.Add(uid, info)
|
|
}
|
|
return
|
|
}
|