package library import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) UseGiftCheck(session comm.IUserSession, req *pb.LibraryUseGiftReq) (code pb.ErrorCode) { if req.Heroid == "" || len(req.Items) == 0 { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftReq) (code pb.ErrorCode, data proto.Message) { var ( res []*cfg.Gameatn ) code = this.UseGiftCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } rsp := &pb.LibraryUseGiftResp{} _heroObj := this.module.modelFetter.getOneHeroFetter(session.GetUserId(), req.Heroid) if _heroObj == nil { code = pb.ErrorCode_HeroNoExist // 没找到对应的英雄信息 return } for k, v := range req.Items { // 校验数量 res = append(res, &cfg.Gameatn{ A: "item", T: k, N: v, }) } if code = this.module.CheckRes(session, res); code != pb.ErrorCode_Success { // 道具不够直接返回 return } session.SendMsg(string(this.module.GetType()), LibraryUseGiftResp, rsp) return }