go_dreamfactory/modules/worldtask/api_chapterreward.go
2023-05-30 15:53:01 +08:00

62 lines
1.4 KiB
Go

package worldtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
func (this *apiComp) ChapterrewardCheck(session comm.IUserSession, req *pb.WorldtaskChapterrewardReq) (code pb.ErrorCode) {
if req.GroupId <= 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) Chapterreward(session comm.IUserSession, req *pb.WorldtaskChapterrewardReq) (code pb.ErrorCode, data *pb.ErrorData) {
if code = this.ChapterrewardCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
rsp := &pb.WorldtaskChapterrewardResp{}
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
if err != nil {
code = pb.ErrorCode_DBError
data.Title = code.String()
return
}
if stats, ok := myWorldtask.Chapters[req.GroupId]; !ok {
code = pb.ErrorCode_WorldtaskChapterUnFinished
data.Title = code.String()
return
} else {
if stats == 2 {
code = pb.ErrorCode_WorldtaskChapterReceived
data.Title = code.String()
return
}
}
gwa, err := this.module.configure.getWorldAllCfg()
if err != nil || gwa == nil {
code = pb.ErrorCode_ConfigNoFound
data.Title = code.String()
data.Message = err.Error()
return
}
rewardCnf := gwa.GetDataMap()[req.GroupId]
if rewardCnf == nil {
code = pb.ErrorCode_ConfigNoFound
data.Title = code.String()
return
}
this.module.DispenseRes(session, rewardCnf.Reword, true)
this.sendMsg(session, WorldtaskChapterReward, rsp)
return
}