50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package moonfantasy
|
|
|
|
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 modelUserMF struct {
|
|
modules.MCompModel
|
|
module *Moonfantasy
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *modelUserMF) 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.(*Moonfantasy)
|
|
this.TableName = comm.TableUserMFantasy
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
///查询用户秘境列表
|
|
func (this *modelUserMF) queryUsermfantasy(uId string) (fantasy *pb.DBUserMFantasy, err error) {
|
|
fantasy = &pb.DBUserMFantasy{}
|
|
if err = this.Get(uId, fantasy); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorf("err:%v", err)
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
fantasy.Id = primitive.NewObjectID().Hex()
|
|
fantasy.Uid = uId
|
|
fantasy.Mfantasys = make([]string, 0)
|
|
if err = this.Add(uId, fantasy); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
}
|
|
err = nil
|
|
}
|
|
return
|
|
}
|