From 3f8f56b741161cc447e1c6b822bc9c028bcedba6 Mon Sep 17 00:00:00 2001 From: liwei <2211068034@qq.com> Date: Tue, 18 Jul 2023 14:29:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=94=AF=E4=BB=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/pay/api_activitybuy.go | 6 +-- modules/pay/api_dailybuy.go | 2 +- modules/pay/modelActivity.go | 64 ++++++++++++++++++++++++++ modules/pay/modelDaily.go | 48 ++++++++++++++++++++ modules/pay/module.go | 6 +++ modules/uniongve/core.go | 5 +++ modules/uniongve/modelUniongve.go | 33 ++++++++++++++ pb/uniongve_db.pb.go | 74 +++++++++++++++++++------------ 8 files changed, 205 insertions(+), 33 deletions(-) create mode 100644 modules/uniongve/core.go diff --git a/modules/pay/api_activitybuy.go b/modules/pay/api_activitybuy.go index abc547080..092e1473d 100644 --- a/modules/pay/api_activitybuy.go +++ b/modules/pay/api_activitybuy.go @@ -18,7 +18,7 @@ func (this *apiComp) ActivityBuyCheck(session comm.IUserSession, req *pb.PayActi return } -// /获取系统公告 +// 获取系统公告 func (this *apiComp) ActivityBuy(session comm.IUserSession, req *pb.PayActivityBuyReq) (errdata *pb.ErrorData) { var ( info *pb.DBActivityGiftbag @@ -69,11 +69,9 @@ func (this *apiComp) ActivityBuy(session comm.IUserSession, req *pb.PayActivityB return } } - - if errdata, items = this.module.modelActivity.delivery(session, conf.Packagetype); errdata != nil { + if errdata, items = this.module.modelActivity.deliverybyid(session, conf.Id); errdata != nil { return } - session.SendMsg(string(this.module.GetType()), "activitybuy", &pb.PayDailyBuyResp{Isucc: true, Items: items}) return } diff --git a/modules/pay/api_dailybuy.go b/modules/pay/api_dailybuy.go index 1b602dffa..dae4a748d 100644 --- a/modules/pay/api_dailybuy.go +++ b/modules/pay/api_dailybuy.go @@ -62,7 +62,7 @@ func (this *apiComp) DailyBuy(session comm.IUserSession, req *pb.PayDailyBuyReq) } } - if errdata, items = this.module.modelDaily.delivery(session, conf.Packagetype); errdata != nil { + if errdata, items = this.module.modelDaily.deliverybyid(session, conf.Id); errdata != nil { return } diff --git a/modules/pay/modelActivity.go b/modules/pay/modelActivity.go index 0ea2a8104..ec4e7d313 100644 --- a/modules/pay/modelActivity.go +++ b/modules/pay/modelActivity.go @@ -80,6 +80,70 @@ func (this *modelActivityComp) updateActivitys(uid string, data *pb.DBActivityGi return } +// 每日礼包发货 +func (this *modelActivityComp) deliverybyid(session comm.IUserSession, id int32) (errdata *pb.ErrorData, items []*pb.UserAssets) { + var ( + info *pb.DBActivityGiftbag + item *pb.ActivityGiftbagItem + conf *cfg.GamePayGiftpackData + ok bool + err error + ) + if conf, err = this.module.configure.getPayGiftpackeData(id); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if info, err = this.getUserActivitys(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + if item, ok = info.Activitys[conf.Type]; !ok { + item = &pb.ActivityGiftbagItem{ + Opentime: 0, + Items: make(map[int32]*pb.PayActivityGiftbagItem), + } + info.Activitys[conf.Type] = item + } + + if _, ok = item.Items[conf.Id]; ok { + item.Items[conf.Id] = &pb.PayActivityGiftbagItem{ + Id: conf.Id, + } + return + } + item.Items[conf.Id].Buyunm++ + item.Items[conf.Id].Totalbuynum++ + if err = this.updateActivitys(session.GetUserId(), info); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + + items = make([]*pb.UserAssets, len(conf.Item)) + for i, v := range conf.Item { + items[i] = &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + } + } + if errdata = this.module.DispenseRes(session, conf.Item, true); errdata != nil { + return + } + return +} + // 每日礼包发货 func (this *modelActivityComp) delivery(session comm.IUserSession, pid string) (errdata *pb.ErrorData, items []*pb.UserAssets) { var ( diff --git a/modules/pay/modelDaily.go b/modules/pay/modelDaily.go index 22ef950cd..336656efe 100644 --- a/modules/pay/modelDaily.go +++ b/modules/pay/modelDaily.go @@ -57,6 +57,54 @@ func (this *modelDailyComp) updateUserDaily(info *pb.DBPayDaily) (err error) { return } +// 每日礼包发货 +func (this *modelDailyComp) deliverybyid(session comm.IUserSession, id int32) (errdata *pb.ErrorData, items []*pb.UserAssets) { + var ( + info *pb.DBPayDaily + conf *cfg.GamePayPackageData + err error + ) + if conf, err = this.module.configure.getPayPackageData(id); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if info, err = this.queryUserDaily(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if info.Items[conf.Id] == nil { + info.Items[conf.Id] = &pb.PayDailyItem{ + Id: conf.Id, + Buyunm: 0, + Lastrefresh: configure.Now().Unix(), + } + } + info.Items[conf.Id].Buyunm++ + if err = this.updateUserDaily(info); err != nil { + return + } + items = make([]*pb.UserAssets, len(conf.Item)) + for i, v := range conf.Item { + items[i] = &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + } + } + if errdata = this.module.DispenseRes(session, conf.Item, true); errdata != nil { + return + } + return +} + // 每日礼包发货 func (this *modelDailyComp) delivery(session comm.IUserSession, pid string) (errdata *pb.ErrorData, items []*pb.UserAssets) { var ( diff --git a/modules/pay/module.go b/modules/pay/module.go index 4db6594dd..02bb6701f 100644 --- a/modules/pay/module.go +++ b/modules/pay/module.go @@ -149,6 +149,12 @@ func (this *Pay) Rpc_ModulePayDelivery(ctx context.Context, args *pb.PayDelivery return } break + case 5: + if errdata, items = this.modelActivity.delivery(session, args.Productid); errdata != nil { + reply.Code = errdata.Code + return + } + break } for _, v := range res { items = append(items, &pb.UserAssets{A: v.A, T: v.T, N: v.N}) diff --git a/modules/uniongve/core.go b/modules/uniongve/core.go new file mode 100644 index 000000000..ccd98d3c2 --- /dev/null +++ b/modules/uniongve/core.go @@ -0,0 +1,5 @@ +package uniongve + +const ( + UnionGveBoosCoonfKey = "UnionGveBoosCoonf" +) diff --git a/modules/uniongve/modelUniongve.go b/modules/uniongve/modelUniongve.go index debd85c0a..08a153c70 100644 --- a/modules/uniongve/modelUniongve.go +++ b/modules/uniongve/modelUniongve.go @@ -26,6 +26,12 @@ func (this *ModelUniongve) Init(service core.IService, module core.IModule, comp return } +func (this *ModelUniongve) Start() (err error) { + err = this.MCompModel.Start() + err = this.loadGlobalBoos() + return +} + // 获取用户全部的埋点数据 func (this *ModelUniongve) getUnionGve(unionid string) (results *pb.DBUnionGve, err error) { results = &pb.DBUnionGve{} @@ -45,6 +51,31 @@ func (this *ModelUniongve) getUnionGve(unionid string) (results *pb.DBUnionGve, return } +// 刷新全局配置 +func (this *ModelUniongve) loadGlobalBoos() (err error) { + var ( + bossconf *pb.DBUnionGveBossConf = &pb.DBUnionGveBossConf{} + ) + if err = this.module.ModuleTools.GetGlobalData(UnionGveBoosCoonfKey, bossconf); err != nil && err != mgo.MongodbNil { + this.module.Errorln(err) + return + } + + if err == mgo.MongodbNil { + err = this.refreshGlobalBoos() + return + } + this.conflock.Lock() + this.bossconf = bossconf + this.conflock.Unlock() + return +} + +func (this *ModelUniongve) getGlobalBoos() (conf *pb.DBUnionGveBossConf, err error) { + this. + return +} + // 刷新全局配置 func (this *ModelUniongve) refreshGlobalBoos() (err error) { var ( @@ -61,6 +92,7 @@ func (this *ModelUniongve) refreshGlobalBoos() (err error) { } rands = comm.RandShuffle(len(booss)) bossconf = &pb.DBUnionGveBossConf{ + Key: UnionGveBoosCoonfKey, Rtime: configure.Now().Unix(), Boos: make([]int32, 5), } @@ -70,5 +102,6 @@ func (this *ModelUniongve) refreshGlobalBoos() (err error) { this.conflock.Lock() this.bossconf = bossconf this.conflock.Unlock() + this.module.ModuleTools.UpdateGlobalData(UnionGveBoosCoonfKey, bossconf) return } diff --git a/pb/uniongve_db.pb.go b/pb/uniongve_db.pb.go index a6bc3bb85..67581adcf 100644 --- a/pb/uniongve_db.pb.go +++ b/pb/uniongve_db.pb.go @@ -26,8 +26,9 @@ type DBUnionGveBossConf struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Rtime int64 `protobuf:"varint,1,opt,name=rtime,proto3" json:"rtime"` //刷新时间 - Boos []int32 `protobuf:"varint,2,rep,packed,name=boos,proto3" json:"boos"` //boosid + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key" bson:"_id"` //刷新时间 //唯一ID + Rtime int64 `protobuf:"varint,2,opt,name=rtime,proto3" json:"rtime"` //刷新时间 + Boos []int32 `protobuf:"varint,3,rep,packed,name=boos,proto3" json:"boos"` //boosid } func (x *DBUnionGveBossConf) Reset() { @@ -62,6 +63,13 @@ func (*DBUnionGveBossConf) Descriptor() ([]byte, []int) { return file_uniongve_uniongve_db_proto_rawDescGZIP(), []int{0} } +func (x *DBUnionGveBossConf) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + func (x *DBUnionGveBossConf) GetRtime() int64 { if x != nil { return x.Rtime @@ -86,7 +94,8 @@ type DBUnionGve struct { Notice string `protobuf:"bytes,2,opt,name=notice,proto3" json:"notice"` //公告 Fire int32 `protobuf:"varint,3,opt,name=fire,proto3" json:"fire"` //火力 Currstage int32 `protobuf:"varint,4,opt,name=currstage,proto3" json:"currstage"` //当前第几阶段 - Boos []*DBUnionGveBoss `protobuf:"bytes,5,rep,name=boos,proto3" json:"boos"` //boos列表 + Rtime int64 `protobuf:"varint,5,opt,name=rtime,proto3" json:"rtime"` //刷新时间 + Boos []*DBUnionGveBoss `protobuf:"bytes,6,rep,name=boos,proto3" json:"boos"` //boos列表 } func (x *DBUnionGve) Reset() { @@ -149,6 +158,13 @@ func (x *DBUnionGve) GetCurrstage() int32 { return 0 } +func (x *DBUnionGve) GetRtime() int64 { + if x != nil { + return x.Rtime + } + return 0 +} + func (x *DBUnionGve) GetBoos() []*DBUnionGveBoss { if x != nil { return x.Boos @@ -280,32 +296,34 @@ var File_uniongve_uniongve_db_proto protoreflect.FileDescriptor var file_uniongve_uniongve_db_proto_rawDesc = []byte{ 0x0a, 0x1a, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x2f, 0x75, 0x6e, 0x69, 0x6f, 0x6e, - 0x67, 0x76, 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3e, 0x0a, 0x12, + 0x67, 0x76, 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x50, 0x0a, 0x12, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x42, 0x6f, 0x73, 0x73, 0x43, 0x6f, - 0x6e, 0x66, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x6f, 0x73, - 0x18, 0x02, 0x20, 0x03, 0x28, 0x05, 0x52, 0x04, 0x62, 0x6f, 0x6f, 0x73, 0x22, 0x95, 0x01, 0x0a, - 0x0a, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x75, - 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, 0x6e, - 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, - 0x04, 0x66, 0x69, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x66, 0x69, 0x72, - 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x75, 0x72, 0x72, 0x73, 0x74, 0x61, 0x67, 0x65, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x73, 0x74, 0x61, 0x67, 0x65, 0x12, - 0x23, 0x0a, 0x04, 0x62, 0x6f, 0x6f, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, - 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x42, 0x6f, 0x73, 0x73, 0x52, 0x04, - 0x62, 0x6f, 0x6f, 0x73, 0x22, 0x5e, 0x0a, 0x0e, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, - 0x76, 0x65, 0x42, 0x6f, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x0e, - 0x0a, 0x02, 0x68, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x68, 0x70, 0x12, 0x24, - 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, - 0x2e, 0x44, 0x42, 0x47, 0x76, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x22, 0x3d, 0x0a, 0x0b, 0x44, 0x42, 0x47, 0x76, 0x65, 0x52, 0x65, 0x63, - 0x6f, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x6e, 0x66, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, + 0x6f, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x05, 0x52, 0x04, 0x62, 0x6f, 0x6f, 0x73, 0x22, 0xab, + 0x01, 0x0a, 0x0a, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x12, 0x18, 0x0a, + 0x07, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x74, 0x69, 0x63, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x66, 0x69, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x66, + 0x69, 0x72, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x75, 0x72, 0x72, 0x73, 0x74, 0x61, 0x67, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x73, 0x74, 0x61, 0x67, + 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x04, 0x62, 0x6f, 0x6f, 0x73, 0x18, + 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, + 0x76, 0x65, 0x42, 0x6f, 0x73, 0x73, 0x52, 0x04, 0x62, 0x6f, 0x6f, 0x73, 0x22, 0x5e, 0x0a, 0x0e, + 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x42, 0x6f, 0x73, 0x73, 0x12, 0x16, + 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, + 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x68, 0x70, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x02, 0x68, 0x70, 0x12, 0x24, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x47, 0x76, 0x65, 0x52, 0x65, + 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x3d, 0x0a, 0x0b, + 0x44, 0x42, 0x47, 0x76, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1c, 0x0a, + 0x09, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x09, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (