package sociaty import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/bson" ) 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 var condIds []int32 // 大于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, }) condIds = append(condIds, taskListConf[v].TypeId) } } else { for _, v := range taskListConf { taskList = append(taskList, &pb.SociatyTask{ TaskId: v.TypeId, }) condIds = append(condIds, v.TypeId) } } sociatyTask.TaskList = taskList sociatyTask.LastUpdateTime = configure.Now().Unix() // 激活所有任务 this.moduleSociaty.ModuleBuried.ActiveCondition(uid, condIds...) 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, []string{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.Received = 1 //领取 break } } update := map[string]interface{}{ "taskList": sociatyTask.TaskList, } if err := this.Redis.HMSet(fmt.Sprintf("%s:%s-%s", this.TableName, sociatyId, uid), update); err != nil { log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()}) return err } if err := this.UpdateModelLogs(this.TableName, uid, bson.M{"sociatyid": sociatyId, "uid": uid}, update); err != nil { return err } return nil } // 活跃度奖励领取 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 } // 更新任务列表 func (this *ModelSociatyTask) updateTaskList(sociatyId, uid string, taskList []*pb.SociatyTask) error { update := map[string]interface{}{ "taskList": taskList, } return this.ChangeList(sociatyId, uid, update) }