60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package linestory
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 章节奖励领取
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.LinestoryReceiveReq) (code pb.ErrorCode) {
|
|
if req.ChapterId == 0 {
|
|
this.moduleLinestory.Error("参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.LinestoryReceiveReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
if code = this.ReceiveCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
conf := this.moduleLinestory.configure.getChapterCfgById(req.ChapterId)
|
|
if conf == nil {
|
|
this.moduleLinestory.Error("配置未找到", log.Field{Key: "uid", Value: uid}, log.Field{Key: "chapterId", Value: req.ChapterId})
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
if err := this.moduleLinestory.modelLinestory.receive(uid, req.ChapterId); err != nil {
|
|
var customErr = new(comm.CustomError)
|
|
if errors.As(err, &customErr) {
|
|
code = customErr.Code
|
|
} else {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
this.moduleLinestory.Error("章节奖励领取失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "chapterId", Value: req.ChapterId}, log.Field{Key: "code", Value: code})
|
|
return
|
|
}
|
|
|
|
//发奖
|
|
if code = this.moduleLinestory.DispenseRes(session, conf.Reward, true); code != pb.ErrorCode_Success {
|
|
this.moduleLinestory.Error("奖励发放失败",
|
|
log.Field{Key: "uid", Value: uid}, log.Field{Key: "chapterId", Value: req.ChapterId}, log.Field{Key: "reward", Value: conf.Reward},
|
|
)
|
|
return
|
|
}
|
|
|
|
rsp := &pb.LinestoryReceiveResp{
|
|
ChapterId: req.ChapterId,
|
|
UserAssets: utils.ConvertReward(conf.Reward...),
|
|
}
|
|
if err := session.SendMsg(string(this.moduleLinestory.GetType()), LinestorySubTypeReceive, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
return
|
|
}
|