go_dreamfactory/modules/activity/module.go

208 lines
4.9 KiB
Go

package activity
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
)
type Activity struct {
modules.ModuleBase
api *apiComp
configure *configureComp
service core.IService
modelhdList *modelHdList
modelhdData *modelhdData
//warorder comm.IWarorder // 战令
}
func NewModule() core.IModule {
return &Activity{}
}
func (this *Activity) GetType() core.M_Modules {
return comm.ModuleActivity
}
func (this *Activity) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
// ticker := time.NewTicker(time.Second * 10)
// go func() {
// for {
// select {
// case <-ticker.C:
// this.CreateHdData()
// return
// }
// }
// }()
return
}
func (this *Activity) Start() (err error) {
err = this.ModuleBase.Start()
if !db.IsCross() {
if rst, err := this.modelhdList.getHdInfoByHdType(comm.HdTypeWarorder); err == nil {
// 服务启动 获取活动信息
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleWarorder); err == nil {
if m, ok := module.(comm.IWarorder); ok {
m.ActivityOpenNotice(rst)
}
}
}
if rst, err := this.modelhdList.getHdInfoByHdType(comm.HdTypePay); err == nil {
// 服务启动 获取活动信息
var module core.IModule
if module, err = this.service.GetModule(comm.ModulePay); err == nil {
if m, ok := module.(comm.IPay); ok {
m.ActivityOpenNotice(rst)
}
}
}
// ac := &pb.DBActivityData{
// Id: "",
// Uid: "",
// Hdoid: "64c8a90e510317d18960964a",
// Gotarr: map[int32]bool{},
// Lasttime: configure.Now().Unix(),
// Val: 1,
// }
// this.modelhdData.InsertHddata("", ac)
this.modelhdList.LoadActivityData()
}
return
}
func (this *Activity) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelhdData = this.RegisterComp(new(modelhdData)).(*modelhdData)
this.modelhdList = this.RegisterComp(new(modelHdList)).(*modelHdList)
}
// 创建一条活动数据
// func (this *Activity) CreateHdData() (err error) {
// var db *pb.DBHuodong
// db = &pb.DBHuodong{
// Id: primitive.NewObjectID().Hex(),
// Hdid: 10001,
// Rtime: 1680105599,
// Itype: 0,
// Name: "累计充值活动",
// Img: "",
// Showtime: "03月15日00:00-03月20日23:59",
// PressImg: "huodong_btn4_1.png",
// Intr: "累计充值,限时福利",
// Etime: 1680105599,
// NormalImg: "huodong_btn4.png",
// Stime: 1679414400,
// Tab: 2,
// Ttype: 0,
// Icon: "ico_event_yxjl",
// Open: 1,
// Order: 102,
// Stype: 10009,
// Htype: 9,
// Data: &pb.ActivityInfo{},
// }
// for i := 0; i < 6; i++ {
// var p []*pb.UserAssets
// p = append(p, &pb.UserAssets{
// A: "item",
// T: "10000001",
// N: 1,
// })
// db.Data.Prize = append(db.Data.Prize, &pb.Arr{
// Prize: p,
// Val: int32(i) + 1,
// })
// }
// this.modelhdList.addHdInfo(db)
// fmt.Printf("%v", db)
// return
// }
func (this *Activity) CreateHdData() (err error) {
this.modelhdList.getHdInfo()
return
}
func (this *Activity) GetAllHdInfo() (activity map[int32][]*pb.DBHuodong) {
return this.modelhdList.getHdInfo()
}
func (this *Activity) GetHdInfoByItype(itype int32) (result []*pb.DBHuodong, err error) {
if c := this.modelhdList.getHdInfo(); c != nil {
if _, ok := c[itype]; ok {
result = c[itype]
return
}
}
err = fmt.Errorf("Not found :%d type activity", itype)
return
}
// 通过活动ID查找
func (this *Activity) GetHdInfoByHdId(oid string) (result *pb.DBHuodong, err error) {
result, err = this.modelhdList.getHdListByHdId(oid)
return
}
// 大转盘奖励
func (this *Activity) Turntable(drawIndex int32, reward []int32) (item *cfg.Gameatn, err error) {
var (
conf *cfg.GameVenturegiftsDrawData
szW []int32 // 权重
szpool []int32 // drawkey
)
if conf, err = this.configure.GetVenturegiftsDraw(drawIndex); err != nil {
return
}
// 过滤已经获得的道具
for _, v := range this.configure.pool1 {
bFound := false
for _, v1 := range reward {
if v.Drawkey == v1 {
bFound = true
break
}
}
if !bFound {
szW = append(szW, v.Weight)
szpool = append(szpool, v.Drawkey)
}
}
if conf.Type == 2 {
for _, v := range this.configure.pool2 {
bFound := false
for _, v1 := range reward {
if v.Drawkey == v1 {
bFound = true
break
}
}
if !bFound {
szW = append(szW, v.Weight)
szpool = append(szpool, v.Drawkey)
}
}
}
if c, err := this.configure.GetVenturegiftsDraw(szpool[comm.GetRandW(szW)]); err != nil {
item = c.Id // 最终获得的道具
}
return
}