diff --git a/modules/shopcenter/api_Info.go b/modules/shopcenter/api_Info.go index 22523eace..4a059c114 100644 --- a/modules/shopcenter/api_Info.go +++ b/modules/shopcenter/api_Info.go @@ -3,6 +3,7 @@ package shopcenter import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 @@ -14,13 +15,16 @@ func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.ShopCenterInfo // /获取自己的排行榜信息 func (this *apiComp) Info(session comm.IUserSession, req *pb.ShopCenterInfoReq) (errdata *pb.ErrorData) { var ( - info *pb.DBShopCenter - err error + info *pb.DBShopCenter + conf *cfg.GameShopCenterControlData + activitys map[int32]*pb.DBHuodong + ok bool + err error ) if errdata = this.InfoCheck(session, req); errdata != nil { return } - + activitys = this.module.modelshop.getactivity() if info, err = this.module.modelshop.getUserShopCenter(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, @@ -30,6 +34,33 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.ShopCenterInfoReq) return } + for _, v := range info.Item { + if conf, err = this.module.configure.getGameShopCenterControl(v.Id); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if conf.Type == 1 || conf.Type == 2 { + v.Open = true + continue + } + if _, ok = activitys[comm.XSFundPhysical]; ok && conf.Type == 3 { + v.Open = true + continue + } + if _, ok = activitys[comm.XSFundRecruit]; ok && conf.Type == 4 { + v.Open = true + continue + } + if _, ok = activitys[comm.XSFundExp]; ok && conf.Type == 5 { + v.Open = true + continue + } + } + session.SendMsg(string(this.module.GetType()), "info", &pb.ShopCenterInfoResp{Info: info}) return } diff --git a/modules/shopcenter/modelShop.go b/modules/shopcenter/modelShop.go index 272b32e06..5af869489 100644 --- a/modules/shopcenter/modelShop.go +++ b/modules/shopcenter/modelShop.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "sync" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" @@ -15,6 +16,7 @@ import ( type ModelShop struct { modules.MCompModel module *ShopCenter + lock sync.RWMutex activitys map[int32]*pb.DBHuodong } @@ -25,9 +27,26 @@ func (this *ModelShop) Init(service core.IService, module core.IModule, comp cor this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) + this.activitys = make(map[int32]*pb.DBHuodong) return } +func (this *ModelShop) addactivity(id int32, activity *pb.DBHuodong) { + this.lock.Lock() + this.activitys[id] = activity + this.lock.Unlock() +} +func (this *ModelShop) delactivity(id int32, activity *pb.DBHuodong) { + this.lock.Lock() + delete(this.activitys, id) + this.lock.Unlock() +} +func (this *ModelShop) getactivity() map[int32]*pb.DBHuodong { + this.lock.RLock() + defer this.lock.RUnlock() + return this.activitys +} + // 获取用户全部的埋点数据 func (this *ModelShop) getUserShopCenter(uid string) (results *pb.DBShopCenter, err error) { results = &pb.DBShopCenter{} diff --git a/modules/shopcenter/module.go b/modules/shopcenter/module.go index 040de2734..1405c25a0 100644 --- a/modules/shopcenter/module.go +++ b/modules/shopcenter/module.go @@ -51,23 +51,33 @@ func (this *ShopCenter) OnInstallComp() { } // 活动开启 -func (this *ShopCenter) ActivityNotice(hdlist *pb.DBHuodong) { +func (this *ShopCenter) ActivityOpenNotice(hdlist *pb.DBHuodong) { switch hdlist.Itype { case comm.XSFundPhysical: - this.open = true + this.modelshop.addactivity(comm.XSFundPhysical, hdlist) break case comm.XSFundRecruit: - this.open = true + this.modelshop.addactivity(comm.XSFundRecruit, hdlist) break case comm.XSFundExp: - this.open = true + this.modelshop.addactivity(comm.XSFundExp, hdlist) break } } -// 活动关闭 +// 移除关闭 func (this *ShopCenter) ActivityCloseNotice(hdlist *pb.DBHuodong) { - + switch hdlist.Itype { + case comm.XSFundPhysical: + this.modelshop.delactivity(comm.XSFundPhysical, hdlist) + break + case comm.XSFundRecruit: + this.modelshop.delactivity(comm.XSFundRecruit, hdlist) + break + case comm.XSFundExp: + this.modelshop.delactivity(comm.XSFundExp, hdlist) + break + } } // 发货