65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
func (this *apiComp) ChapterrewardCheck(session comm.IUserSession, req *pb.WorldtaskChapterrewardReq) (errdata *pb.ErrorData) {
|
|
if req.GroupId <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Chapterreward(session comm.IUserSession, req *pb.WorldtaskChapterrewardReq) (errdata *pb.ErrorData) {
|
|
if code = this.ChapterrewardCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
data = &pb.ErrorData{}
|
|
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
|
|
}
|