90 lines
2.2 KiB
Go
90 lines
2.2 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
type ModelSociatyTask struct {
|
|
modules.MCompModel
|
|
moduleSociaty *Sociaty
|
|
service core.IService
|
|
}
|
|
|
|
func (this *ModelSociatyTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableSociatyTask
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleSociaty = module.(*Sociaty)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
// 初始化公会任务 加入成员时初始化
|
|
func (this *ModelSociatyTask) initSociatyTask(uid, sociatyId string) error {
|
|
ggt, err := this.moduleSociaty.configure.getSociatyTaskCfg()
|
|
if err != nil || ggt == nil {
|
|
return errors.New("SociatyTaskCfg not found")
|
|
}
|
|
sociatyTask := &pb.DBSociatyTask{
|
|
SociatyId: sociatyId,
|
|
Uid: uid,
|
|
}
|
|
var taskList []*pb.SociatyTask
|
|
|
|
list := ggt.GetDataList()
|
|
// 大于4条配置
|
|
if len(list) > 4 {
|
|
//随机4条任务
|
|
randInts := utils.Numbers(0, len(list)-1, 4)
|
|
for _, v := range randInts {
|
|
taskList = append(taskList, &pb.SociatyTask{
|
|
TaskId: list[v].Id,
|
|
})
|
|
}
|
|
} else {
|
|
for _, v := range list {
|
|
taskList = append(taskList, &pb.SociatyTask{
|
|
TaskId: v.Id,
|
|
})
|
|
}
|
|
}
|
|
sociatyTask.List = taskList
|
|
return this.moduleSociaty.modelSociatyTask.AddList(sociatyId, uid, sociatyTask)
|
|
}
|
|
|
|
//任务列表
|
|
func (this *ModelSociatyTask) taskList(uid, sociatyId string) (task *pb.DBSociatyTask) {
|
|
task = &pb.DBSociatyTask{}
|
|
this.GetListObj(sociatyId, uid, task)
|
|
return
|
|
}
|
|
|
|
// 删除公会任务
|
|
func (this *ModelSociatyTask) deleTask(sociatyId, uid string) error {
|
|
return this.DelListlds(sociatyId, uid)
|
|
}
|
|
|
|
// 奖励领取
|
|
func (this *ModelSociatyTask) receive(taskId int32, sociatyId, uid string) error {
|
|
sociatyTask := &pb.DBSociatyTask{}
|
|
this.GetListObj(sociatyId, uid, sociatyTask)
|
|
for _, t := range sociatyTask.List {
|
|
if t.TaskId == taskId {
|
|
t.Status = 1 //领取
|
|
}
|
|
}
|
|
update := map[string]interface{}{
|
|
"list": sociatyTask.List,
|
|
}
|
|
return this.ChangeList(sociatyId, uid, update)
|
|
}
|
|
|
|
// 活跃度领取
|
|
func (this *ModelSociatyTask) activityReceive() error {
|
|
return nil
|
|
}
|