54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelWorldtask struct {
|
|
modules.MCompModel
|
|
moduleWorldtask *Worldtask
|
|
}
|
|
|
|
func (this *ModelWorldtask) 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.TableWorldtask
|
|
this.moduleWorldtask = module.(*Worldtask)
|
|
return
|
|
}
|
|
|
|
func (this *ModelWorldtask) getWorldtask(uid string) (*pb.DBWorldtask, error) {
|
|
d := &pb.DBWorldtask{}
|
|
if err := this.Get(uid, d); err != nil {
|
|
if err != mongo.ErrNoDocuments {
|
|
return d, err
|
|
}
|
|
}
|
|
return d, nil
|
|
}
|
|
|
|
// 完成任务
|
|
func (this *ModelWorldtask) finishTask(taskId int32, task *pb.DBWorldtask) error {
|
|
if len(task.TaskList) == 0 {
|
|
task.TaskList = append(task.TaskList, &pb.Worldtask{
|
|
TaskId: taskId,
|
|
Status: 1, //完成
|
|
})
|
|
} else {
|
|
for _, v := range task.TaskList {
|
|
if v.TaskId == taskId {
|
|
v.Status = 1 //完成
|
|
}
|
|
}
|
|
}
|
|
|
|
update := map[string]interface{}{
|
|
"taskList": task.TaskList,
|
|
}
|
|
return this.Change(task.Uid, update)
|
|
}
|