package plunder import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "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, Ctime: configure.Now().Unix(), } for i := 0; i < 3; i++ { // 队列固定三条 info.Line = append(info.Line, &pb.PlunderLine{}) } info.Line = append(info.Line, &pb.PlunderLine{ Closetime: -1, // 需要手动解锁 }) err = this.Add(uid, info) } return } func (this *modelPlunder) changePlunderData(uid string, update map[string]interface{}) (err error) { err = this.Change(uid, update) return } // 批量查询 func (this *modelPlunder) getPlunderDataByUids(uid []string) (info []*pb.DBPlunder, err error) { if _, err = this.GetByUids(uid, &info); err != nil { this.module.Errorln(err) return } return }