73 lines
2.2 KiB
Go
73 lines
2.2 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) (errdata *pb.ErrorData) {
|
|
if req.ChapterId == 0 {
|
|
this.module.Error("参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.LinestoryReceiveReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
conf := this.module.configure.getChapterCfgById(req.ChapterId)
|
|
if conf == nil {
|
|
this.module.Error("配置未找到", log.Field{Key: "uid", Value: uid}, log.Field{Key: "chapterId", Value: req.ChapterId})
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := this.module.modelLinestory.receive(uid, req.ChapterId); err != nil {
|
|
var customErr = new(comm.CustomError)
|
|
if errors.As(err, &customErr) {
|
|
code := customErr.Code
|
|
errdata = &pb.ErrorData{
|
|
Code: code,
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
this.module.Error("章节奖励领取失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "chapterId", Value: req.ChapterId})
|
|
return
|
|
}
|
|
|
|
//发奖
|
|
if errdata = this.module.DispenseRes(session, conf.Reward, true); errdata != nil {
|
|
this.module.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...),
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), LinestorySubTypeReceive, rsp)
|
|
return
|
|
}
|