diff --git a/modules/wtask/api_exchange.go b/modules/wtask/api_exchange.go index d86cc33bc..f6fbb0199 100644 --- a/modules/wtask/api_exchange.go +++ b/modules/wtask/api_exchange.go @@ -15,15 +15,17 @@ func (this *apiComp) ExchangeCheck(session comm.IUserSession, req *pb.WTaskExcha // /获取系统公告 func (this *apiComp) Exchange(session comm.IUserSession, req *pb.WTaskExchangeReq) (errdata *pb.ErrorData) { var ( - info *pb.DBWTask - conf *cfg.GameWorldDealData - err error + info *pb.DBWTask + confs []*cfg.GameWorldDealData + need []*cfg.Gameatn + money []*cfg.Gameatn + err error ) if errdata = this.ExchangeCheck(session, req); errdata != nil { return } - if conf, err = this.module.configure.getGameWorldDeal(req.Eid); err != nil { + if confs, err = this.module.configure.getGameWorldDeal(req.Eid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), @@ -41,23 +43,28 @@ func (this *apiComp) Exchange(session comm.IUserSession, req *pb.WTaskExchangeRe return } - if info.Exchange[req.Eid] >= conf.Buy { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ReqParameterError, - Title: pb.ErrorCode_ReqParameterError.ToString(), - Message: err.Error(), + for i, v := range req.Eid { + if info.Exchange[v] >= confs[i].Buy { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: err.Error(), + } + return } + need = append(need, confs[i].Item...) + money = append(need, confs[i].Money...) + info.Exchange[v]++ + } + + if errdata = this.module.ConsumeRes(session, need, true); errdata != nil { return } - if errdata = this.module.ConsumeRes(session, conf.Item, true); errdata != nil { + if errdata = this.module.DispenseRes(session, money, true); errdata != nil { return } - if errdata = this.module.DispenseRes(session, conf.Money, true); errdata != nil { - return - } - info.Exchange[req.Eid]++ if err = this.module.modelwtask.Change(session.GetUserId(), map[string]interface{}{ "exchange": info.Exchange, }); err != nil { diff --git a/modules/wtask/configure.go b/modules/wtask/configure.go index d8289384b..7c39a054b 100644 --- a/modules/wtask/configure.go +++ b/modules/wtask/configure.go @@ -239,18 +239,23 @@ func (this *configureComp) getGameSearchitemBox(id int32) (conf *cfg.GameSearchi return } -func (this *configureComp) getGameWorldDeal(id int32) (conf *cfg.GameWorldDealData, err error) { +func (this *configureComp) getGameWorldDeal(ids []int32) (confs []*cfg.GameWorldDealData, err error) { var ( - v interface{} - ok bool + v interface{} + conf *cfg.GameWorldDealData + ok bool ) if v, err = this.GetConfigure(game_worlddeal); err != nil { return } else { - if conf, ok = v.(*cfg.GameWorldDeal).GetDataMap()[id]; !ok { - err = comm.NewNotFoundConfErr(modulename, gameWorldTask, id) - this.module.Errorf("err:%v", err) - return + confs = make([]*cfg.GameWorldDealData, 0) + for _, id := range ids { + if conf, ok = v.(*cfg.GameWorldDeal).GetDataMap()[id]; !ok { + err = comm.NewNotFoundConfErr(modulename, gameWorldTask, v) + this.module.Errorf("err:%v", err) + return + } + confs = append(confs, conf) } } diff --git a/pb/wtask_msg.pb.go b/pb/wtask_msg.pb.go index be5b009c1..2d3113b2c 100644 --- a/pb/wtask_msg.pb.go +++ b/pb/wtask_msg.pb.go @@ -1057,7 +1057,7 @@ type WTaskExchangeReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Eid int32 `protobuf:"varint,1,opt,name=eid,proto3" json:"eid"` + Eid []int32 `protobuf:"varint,1,rep,packed,name=eid,proto3" json:"eid"` } func (x *WTaskExchangeReq) Reset() { @@ -1092,11 +1092,11 @@ func (*WTaskExchangeReq) Descriptor() ([]byte, []int) { return file_wtask_wtask_msg_proto_rawDescGZIP(), []int{19} } -func (x *WTaskExchangeReq) GetEid() int32 { +func (x *WTaskExchangeReq) GetEid() []int32 { if x != nil { return x.Eid } - return 0 + return nil } //世界任务兑换物品 请求 @@ -1105,7 +1105,7 @@ type WTaskExchangeResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Eid int32 `protobuf:"varint,1,opt,name=eid,proto3" json:"eid"` + Eid []int32 `protobuf:"varint,1,rep,packed,name=eid,proto3" json:"eid"` Award []*UserAssets `protobuf:"bytes,2,rep,name=award,proto3" json:"award"` //奖励 } @@ -1141,11 +1141,11 @@ func (*WTaskExchangeResp) Descriptor() ([]byte, []int) { return file_wtask_wtask_msg_proto_rawDescGZIP(), []int{20} } -func (x *WTaskExchangeResp) GetEid() int32 { +func (x *WTaskExchangeResp) GetEid() []int32 { if x != nil { return x.Eid } - return 0 + return nil } func (x *WTaskExchangeResp) GetAward() []*UserAssets { @@ -1265,10 +1265,10 @@ var file_wtask_wtask_msg_proto_rawDesc = []byte{ 0x77, 0x61, 0x72, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x22, 0x24, 0x0a, 0x10, 0x57, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, - 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x05, 0x52, 0x03, 0x65, 0x69, 0x64, 0x22, 0x48, 0x0a, 0x11, 0x57, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x69, 0x64, 0x12, 0x21, 0x0a, 0x05, 0x61, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x05, 0x52, 0x03, 0x65, 0x69, 0x64, 0x12, 0x21, 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,