89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package weektask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
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 ModelWeektask struct {
|
|
modules.MCompModel
|
|
module *WeekTask
|
|
}
|
|
|
|
func (this *ModelWeektask) 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.TableWeeltask
|
|
this.module = module.(*WeekTask)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取用户全部的埋点数据
|
|
func (this *ModelWeektask) getUserDTasks(uid string) (results *pb.DBWeektask, err error) {
|
|
results = &pb.DBWeektask{}
|
|
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
results = &pb.DBWeektask{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Activity: 0,
|
|
Tasks: make([]int32, 0),
|
|
Tcomplete: make(map[int32]bool),
|
|
Acomplete: make(map[int32]bool),
|
|
Rtime: configure.Now().Unix(),
|
|
}
|
|
if opencmd, errdata := this.module.sys.QueryOpenCondData(uid); errdata != nil {
|
|
err = fmt.Errorf("sys.QueryOpenCondData err:%s", errdata.Message)
|
|
return
|
|
} else {
|
|
if err = this.inquireActivations(results, opencmd); err != nil {
|
|
return
|
|
}
|
|
}
|
|
err = this.Add(uid, results)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 查询可接取任务列表
|
|
func (this *ModelWeektask) inquireActivations(info *pb.DBWeektask, opencmd map[string]int32) (err error) {
|
|
var (
|
|
confs []*cfg.GameTaskRoundData
|
|
ok bool
|
|
)
|
|
if confs, err = this.module.configure.getGameTaskRoundDatas(); err != nil {
|
|
return
|
|
}
|
|
info.Tasks = make([]int32, 0)
|
|
for _, v := range confs {
|
|
|
|
if _, ok = info.Tcomplete[v.Key]; ok { //已完成
|
|
continue
|
|
}
|
|
|
|
if v.Open != "" && opencmd[v.Open] != 2 { //功能未开启
|
|
continue
|
|
}
|
|
if v.IdBefore != 0 && !info.Tcomplete[v.Key] { //前置任务未完成
|
|
continue
|
|
}
|
|
info.Tasks = append(info.Tasks, v.Key)
|
|
}
|
|
return
|
|
}
|