package task import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 活跃度领取 func (this *apiComp) ActiveReceiveCheck(session comm.IUserSession, req *pb.TaskActiveReceiveReq) (errdata *pb.ErrorData) { var code pb.ErrorCode if req.Id == 0 { code = pb.ErrorCode_TaskIdEmpty } else if req.TaskTag <= 0 || req.TaskTag > 2 { code = pb.ErrorCode_TaskTagEmpty } errdata = &pb.ErrorData{ Code: code, Title: code.ToString(), } return } func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActiveReceiveReq) (errdata *pb.ErrorData) { if errdata = this.ActiveReceiveCheck(session, req); errdata != nil { return } uid := session.GetUserId() ue, err := this.module.ModuleUser.GetUserExpand(uid) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if ue == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_UserExpandNull, Title: pb.ErrorCode_UserExpandNull.ToString(), Message: err.Error(), } return } var rewards []*cfg.Gameatn var flag bool update := map[string]interface{}{} // 玩家的 activeList := this.module.modelTaskActive.getActiveList(uid) // var activityData *pb.ActivityData for _, v := range activeList { if v.TaskId == req.Id { if v.Received != 1 { conf := this.module.configure.getTaskActiveById(v.TaskId) if conf == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if req.TaskTag == int32(comm.TASK_DAILY) { if ue.Activeday < conf.Active { errdata = &pb.ErrorData{ Code: pb.ErrorCode_TaskActiveNoenough, Title: pb.ErrorCode_TaskActiveNoenough.ToString(), Message: err.Error(), } return } } else if req.TaskTag == int32(comm.TASK_WEEKLY) { if ue.Activeweek < conf.Active { errdata = &pb.ErrorData{ Code: pb.ErrorCode_TaskActiveNoenough, Title: pb.ErrorCode_TaskActiveNoenough.ToString(), Message: err.Error(), } return } } v.Received = 1 flag = true rewards = append(rewards, conf.Reword...) } break } } if flag { update["activityList"] = activeList if err := this.module.modelTaskActive.Change(session.GetUserId(), update); err != nil { this.module.Errorf("updateReceive err %v", err) errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } } if len(rewards) > 0 { //派发奖励 if errdata = this.module.DispenseRes(session, rewards, true); errdata != nil { this.module.Error("活跃度奖励", log.Field{Key: "uid", Value: uid}, log.Field{Key: "rewards", Value: rewards}, ) } go this.module.ModuleBuried.TriggerBuried(uid, comm.GetBuriedParam(comm.Rtype171, 1)) } resp := &pb.TaskActiveReceiveResp{ TaskTag: req.TaskTag, Id: req.Id, } session.SendMsg(string(this.module.GetType()), TaskSubTypeActiveReceive, resp) return }