package oldtimes import ( "go_dreamfactory/comm" "go_dreamfactory/pb" ) func (this *apiComp) EnterCheck(session comm.IUserSession, req *pb.OldtimesEnterReq) (code pb.ErrorCode) { if req.ChapterId <= 0 || req.LevelId <= 0 { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) Enter(session comm.IUserSession, req *pb.OldtimesEnterReq) (code pb.ErrorCode, data *pb.ErrorData) { if code = this.EnterCheck(session, req); code != pb.ErrorCode_Success { return } rsp := &pb.OldtimesEnterResp{} uid := session.GetUserId() ot := this.module.modelOldtimes.getDBOldtimes(uid) if ot == nil { code = pb.ErrorCode_DataNotFound return } chapter := this.module.modelOldtimes.getChatper(req.ChapterId, ot) if chapter != nil { if chapter.Status == 3 { code = pb.ErrorCode_OldtimesFinished return } var exist bool for _, l := range chapter.Levels { if l.Lid == req.LevelId { if l.Status == 3 { code = pb.ErrorCode_OldtimesLevelOver return } else { l.Status = 2 } exist = true break } } if !exist { chapter.Levels = append(chapter.Levels, &pb.Level{ Lid: req.LevelId, Status: 1, }) } } this.module.modelOldtimes.updateOldtimes(uid, ot) session.SendMsg(string(this.module.GetType()), "enter", rsp) return }