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 module *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.module = module.(*Sociaty) this.service = service return } // 初始化公会任务 加入成员时初始化 func (this *ModelSociatyTask) initSociatyTask(session comm.IUserSession, sociatyId string) error { uid := session.GetUserId() sociatyTask := &pb.DBSociatyTask{ SociatyId: sociatyId, Uid: uid, } var taskList map[int32]int32 = make(map[int32]int32) taskListConf := this.module.sociatyTaskConf.GetDataList() globalConf := this.module.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[taskListConf[v].TypeId] = 0 condIds = append(condIds, taskListConf[v].TypeId) } } else { for _, v := range taskListConf { taskList[v.TypeId] = 0 condIds = append(condIds, v.TypeId) } } sociatyTask.TaskList = taskList sociatyTask.LastUpdateTime = configure.Now().Unix() // 激活所有任务 this.module.ModuleBuried.ActiveCondition(session, condIds...) return this.module.modelSociatyTask.AddList(sociatyId, uid, sociatyTask) } // 公会任务列表 func (this *ModelSociatyTask) getUserTask(uid, sociatyId string) (task *pb.DBSociatyTask, err error) { task = &pb.DBSociatyTask{} err = this.GetListObj(sociatyId, uid, task) return } // 删除公会任务 func (this *ModelSociatyTask) deleTask(sociatyId, uid string) error { return this.DelListlds(sociatyId, []string{uid}) } // 任务奖励领取 func (this *ModelSociatyTask) receive(sociatyTask *pb.DBSociatyTask) error { update := map[string]interface{}{ "taskList": sociatyTask.TaskList, } if err := this.Redis.HMSet(fmt.Sprintf("%s-%s:%s-%s", this.module.service.GetTag(), this.TableName, sociatyTask.SociatyId, sociatyTask.Uid), update); err != nil { log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()}) return err } if err := this.UpdateModelLogs(this.TableName, sociatyTask.Uid, bson.M{"sociatyid": sociatyTask.SociatyId, "_id": sociatyTask.Uid}, update); err != nil { return err } return nil }