go_dreamfactory/modules/worldtask/model_worldtask.go
2022-11-10 21:16:30 +08:00

65 lines
1.5 KiB
Go

package worldtask
import (
"errors"
"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) acceptTask(groupId, taskId int32, task *pb.DBWorldtask) error {
if task == nil {
return errors.New("worldtask is nil")
}
return nil
}
// 完成任务
func (this *ModelWorldtask) finishTask(groupId, taskId int32, task *pb.DBWorldtask) error {
if task == nil {
return errors.New("worldtask is nil")
}
update := map[string]interface{}{}
if task.LastTaskIds == nil {
task.LastTaskIds = make(map[int32]int32)
}
update["uid"] = task.Uid
task.TaskList = append(task.TaskList, &pb.Worldtask{
TaskId: taskId,
Status: 1, //完成
})
task.LastTaskIds[groupId] = taskId
update["taskList"] = task.TaskList
update["lastTaskIds"] = task.LastTaskIds
return this.Change(task.Uid, update)
}