go_dreamfactory/modules/oldtimes/api_finish.go
2023-04-25 18:27:51 +08:00

45 lines
1.2 KiB
Go

package oldtimes
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
func (this *apiComp) FinishCheck(session comm.IUserSession, req *pb.OldtimesFinishReq) (code pb.ErrorCode) {
if req.ChapterId <= 0 || req.LevelId <= 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) Finish(session comm.IUserSession, req *pb.OldtimesFinishReq) (code pb.ErrorCode, data *pb.ErrorData) {
if code = this.FinishCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
rsp := &pb.OldtimesFinishResp{}
ot := this.module.modelOldtimes.getDBOldtimes(uid)
if ot == nil {
code = pb.ErrorCode_DataNotFound
return
}
chapter := this.module.modelOldtimes.getChatper(req.ChapterId, ot)
level := this.module.modelOldtimes.getLevel(req.LevelId, chapter)
if level != nil && level.Status == 3 {
code = pb.ErrorCode_OldtimesLevelOver
return
}
if !this.module.modelOldtimes.isPreFinished(req.ChapterId, req.LevelId, ot) {
code = pb.ErrorCode_OldtimesPreLevelNoFinished
return
}
this.module.modelOldtimes.levelFinish(uid, req.ChapterId, req.LevelId, ot)
session.SendMsg(string(this.module.GetType()), "finish", rsp)
return
}