package wtask import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "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 ModelWTask struct { modules.MCompModel module *WTask } func (this *ModelWTask) 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.TableWtask this.module = module.(*WTask) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } // 获取用户全部的埋点数据 func (this *ModelWTask) getUserWTasks(uid string) (results *pb.DBWTask, err error) { results = &pb.DBWTask{} if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } if err == mgo.MongodbNil { err = nil results = &pb.DBWTask{ Id: primitive.NewObjectID().Hex(), Uid: uid, Currchapter: 0, Activations: make([]int32, 0), Accepts: make([]int32, 0), Completes: make([]int32, 0), Groups: make(map[int32]int32), Boxs: make(map[int32]*pb.DBWTaskBox), } err = this.Add(uid, results) } return } func (this *ModelWTask) updateUserWTasks(uid string, data *pb.DBWTask) (err error) { if err = this.Change(uid, map[string]interface{}{ "currchapter": data.Currchapter, "activations": data.Activations, "accepts": data.Accepts, "completes": data.Completes, "groups": data.Groups, "boxs": data.Boxs, "dailytaskgroup": data.Dailytaskgroup, }); err != nil { this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()}) return } return }