72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package mline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.MlineGetRewardReq) (code pb.ErrorCode) {
|
|
if req.CId == 0 || req.Star == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
// 领取奖励
|
|
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.MlineGetRewardReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
var (
|
|
curChapter *pb.DBMline // 当前章节信息
|
|
update map[string]interface{}
|
|
rsp *pb.MlineGetRewardResp
|
|
)
|
|
rsp = &pb.MlineGetRewardResp{}
|
|
update = make(map[string]interface{})
|
|
if code = this.GetRewardCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
mLineConf := this.module.configure.GetMainChapterConf(req.CId)
|
|
if mLineConf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
list, _ := this.module.modelMline.getMainlineList(session.GetUserId())
|
|
for _, v := range list {
|
|
if req.CId == v.ChapterId {
|
|
curChapter = v
|
|
break
|
|
}
|
|
}
|
|
if curChapter == nil {
|
|
code = pb.ErrorCode_MainlineNotFindChapter
|
|
return
|
|
}
|
|
if b, ok := curChapter.Award[req.Star]; ok && b { // 重复领奖
|
|
code = pb.ErrorCode_MainlineRepeatReward
|
|
return
|
|
}
|
|
|
|
curChapter.Award[req.Star] = true
|
|
update["award"] = curChapter.Award
|
|
awardConf := this.module.configure.GetMainStarRewardConf(mLineConf.Starreward)
|
|
for _, v := range awardConf {
|
|
if v.Starnum == req.Star {
|
|
if code = this.module.DispenseRes(session, v.Reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
for _, v := range v.Reward {
|
|
rsp.Reward = append(rsp.Reward, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
rsp.Data = curChapter
|
|
this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update)
|
|
session.SendMsg(string(this.module.GetType()), MlineGetRewardResp, rsp) // 数据推送
|
|
return
|
|
}
|