go_dreamfactory/modules/sociaty/model_sociatytask.go
2022-11-17 20:33:44 +08:00

105 lines
2.8 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"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 {
sociatyTask := &pb.DBSociatyTask{
SociatyId: sociatyId,
Uid: uid,
}
var taskList []*pb.SociatyTask
taskListConf := this.moduleSociaty.sociatyTaskConf.GetDataList()
globalConf := this.moduleSociaty.globalConf
// 大于4条配置
if len(taskListConf) > int(globalConf.GuildTaskNum) {
//随机4条任务
randInts := utils.RandomNumbers(0, len(taskListConf)-1, int(globalConf.GuildTaskNum))
for _, v := range randInts {
taskList = append(taskList, &pb.SociatyTask{
TaskId: taskListConf[v].TypeId,
})
}
} else {
for _, v := range taskListConf {
taskList = append(taskList, &pb.SociatyTask{
TaskId: v.TypeId,
})
}
}
sociatyTask.TaskList = taskList
sociatyTask.LastUpdateTime = configure.Now().Unix()
return this.moduleSociaty.modelSociatyTask.AddList(sociatyId, uid, sociatyTask)
}
//公会任务列表
func (this *ModelSociatyTask) getUserTask(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.TaskList {
if t.TaskId == taskId {
t.Status = 1 //领取
break
}
}
update := map[string]interface{}{
"taskList": sociatyTask.TaskList,
}
return this.ChangeList(sociatyId, uid, update)
}
// 活跃度奖励领取
func (this *ModelSociatyTask) activityReceive(id int32, sociatyId, uid string) error {
sociatyTask := &pb.DBSociatyTask{}
this.GetListObj(sociatyId, uid, sociatyTask)
var isUpdate bool
for _, t := range sociatyTask.ActivityList {
if t.Id == id {
t.Status = 1 //领取
isUpdate = true
break
}
}
if isUpdate {
update := map[string]interface{}{
"activityList": sociatyTask.ActivityList,
}
return this.ChangeList(sociatyId, uid, update)
}
return nil
}