package weektask import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.WeekTaskReceiveReq) (errdata *pb.ErrorData) { return } // /获取自己的排行榜信息 func (this *apiComp) Receive(session comm.IUserSession, req *pb.WeekTaskReceiveReq) (errdata *pb.ErrorData) { var ( info *pb.DBWeektask conf *cfg.GameTaskRoundData confs []*cfg.GameTaskRoundData tasks []int32 progress []*pb.ConIProgress award []*pb.UserAssets ok bool opencmd map[string]int32 err error ) if errdata = this.ReceiveCheck(session, req); errdata != nil { return } if info, err = this.module.modelWeektask.getUserDTasks(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if conf, err = this.module.configure.getGameTaskRoundData(req.Tid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if _, ok = info.Tcomplete[req.Tid]; ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: "task no complete!", } return } award = make([]*pb.UserAssets, 0) for _, v := range conf.Reword { award = append(award, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } if errdata = this.module.DispenseRes(session, conf.Reword, true); errdata != nil { return } info.Activity += conf.Active info.Tcomplete[req.Tid] = true if opencmd, errdata = this.module.sys.QueryOpenCondData(session.GetUserId()); errdata != nil { return } else { if err = this.module.modelWeektask.inquireActivations(info, opencmd); err != nil { return } } if confs, err = this.module.configure.getGameTaskRoundDatasByids(info.Tasks); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } } tasks = make([]int32, 0, len(confs)) for _, v := range confs { tasks = append(tasks, v.TypeId) } if progress, err = this.module.ModuleBuried.CheckCondition(session.GetUserId(), tasks...); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ExternalModule, Title: pb.ErrorCode_ExternalModule.ToString(), Message: err.Error(), } return } this.module.modelWeektask.Change(session.GetUserId(), map[string]interface{}{ "activity": info.Activity, "tasks": info.Tasks, "tcomplete": info.Tcomplete, }) session.SendMsg(string(this.module.GetType()), "receive", &pb.WeekTaskReceiveResp{Tid: req.Tid, Activity: info.Activity, Tasks: info.Tasks, Progress: progress, Award: award}) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "WeekTaskReceiveReq", award) }) return }