package library import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.LibraryGetRewardReq) (code pb.ErrorCode) { if req.ObjId == "" || req.Fetterlv == 0 { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) GetReward(session comm.IUserSession, req *pb.LibraryGetRewardReq) (code pb.ErrorCode, data proto.Message) { code = this.GetRewardCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } rsp := &pb.LibraryGetListResp{} defer session.SendMsg(string(this.module.GetType()), LibraryGetListResp, rsp) fetter := this.module.getLibraryByObjID(session.GetUserId(), req.ObjId) if fetter == nil { code = pb.ErrorCode_LibraryNoData return } conf := this.configure.GetLibraryFetter(fetter.Fid, req.Fetterlv) if conf == nil { code = pb.ErrorCode_ConfigNoFound return } for k := range fetter.Prize { if k == req.Fetterlv { code = pb.ErrorCode_LibraryReward return } } fetter.Prize[req.Fetterlv] = 1 // 发奖 if code = this.module.DispenseRes(session, conf.Prize, true); code != pb.ErrorCode_Success { // return } mapData := make(map[string]interface{}, 0) mapData["prize"] = fetter.Prize this.module.ModifyLibraryData(session.GetUserId(), fetter.Id, mapData) // 更新内存信息 return }