go_dreamfactory/modules/dailytask/modelDailytask.go
2023-07-20 17:43:32 +08:00

68 lines
1.8 KiB
Go

package dailytask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type ModelDailytask struct {
modules.MCompModel
module *Dailytask
}
func (this *ModelDailytask) 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.TableDailytask
this.module = module.(*Dailytask)
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 获取用户全部的埋点数据
func (this *ModelDailytask) getUserDTasks(uid string) (results *pb.DBDailytask, err error) {
results = &pb.DBDailytask{}
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
if err == mgo.MongodbNil {
results = &pb.DBDailytask{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Groups: make([]*pb.DBDailytaskGroup, 0),
Rtime: 0,
}
err = this.Add(uid, results)
}
return
}
// 重置任务
func (this *ModelDailytask) resetUserDTasks(ulv int32) (group []int32, err error) {
var (
conf *cfg.GameAnnulartaskAllData
task *cfg.GameAnnulartask_LibraryData
)
if conf, err = this.module.configure.getAnnulartaskAll(); err != nil {
return
}
group = make([]int32, 0)
for _, v := range conf.Taskdetail {
if task, err = this.module.configure.getAnnulartaskLibrary(ulv, v); err != nil {
return
}
group = append(group, task.Itemid)
}
return
}