package linestory import ( "errors" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/utils" "google.golang.org/protobuf/proto" ) // 章节奖励领取 func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.LinestoryReceiveReq) (code pb.ErrorCode) { if req.ChapterId == 0 { this.moduleLinestory.Error("参数错误", log.Fields{"uid": session.GetUserId(), "params": req}) code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) Receive(session comm.IUserSession, req *pb.LinestoryReceiveReq) (code pb.ErrorCode, data proto.Message) { 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.Fields{"uid": uid, "chapterId": 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.Fields{"uid": uid, "chapterId": req.ChapterId, "code": code}) return } //发奖 if code = this.moduleLinestory.DispenseRes(session, conf.Reward, true); code != pb.ErrorCode_Success { this.moduleLinestory.Error("奖励发放失败", log.Fields{"uid": uid, "chapterId": req.ChapterId, "reward": 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 }