go_dreamfactory/modules/shopcenter/module.go
2024-01-05 17:47:41 +08:00

157 lines
3.9 KiB
Go

package shopcenter
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
)
type ShopCenter struct {
modules.ModuleBase
service core.IService
api *apiComp
configure *configureComp
modelshop *ModelShop
mainline comm.IMainline
open bool
}
func NewModule() core.IModule {
return &ShopCenter{}
}
func (this *ShopCenter) GetType() core.M_Modules {
return comm.ModuleShopCenter
}
func (this *ShopCenter) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
if err = this.ModuleBase.Init(service, module, options); err != nil {
return
}
this.service = service
return
}
func (this *ShopCenter) Start() (err error) {
if err = this.ModuleBase.Start(); err != nil {
return
}
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleMainline); err != nil {
return
}
this.mainline = module.(comm.IMainline)
return
}
func (this *ShopCenter) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelshop = this.RegisterComp(new(ModelShop)).(*ModelShop)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 活动开启
func (this *ShopCenter) ActivityOpenNotice(hdlist *pb.DBHuodong) {
switch hdlist.Itype {
case pb.HdType_XSFundPhysical:
this.modelshop.addactivity(pb.HdType_XSFundPhysical, hdlist)
break
case pb.HdType_XSFundRecruit:
this.modelshop.addactivity(pb.HdType_XSFundRecruit, hdlist)
break
case pb.HdType_XSFundExp:
this.modelshop.addactivity(pb.HdType_XSFundExp, hdlist)
break
case pb.HdType_ShopCenterPayPakcge:
this.modelshop.addactivity(pb.HdType_ShopCenterPayPakcge, hdlist)
break
}
}
// 移除关闭
func (this *ShopCenter) ActivityCloseNotice(hdlist *pb.DBHuodong) {
switch hdlist.Itype {
case pb.HdType_XSFundPhysical:
this.modelshop.delactivity(pb.HdType_XSFundPhysical, hdlist)
break
case pb.HdType_XSFundRecruit:
this.modelshop.delactivity(pb.HdType_XSFundRecruit, hdlist)
break
case pb.HdType_XSFundExp:
this.modelshop.delactivity(pb.HdType_XSFundExp, hdlist)
break
case pb.HdType_ShopCenterPayPakcge:
this.modelshop.delactivity(pb.HdType_ShopCenterPayPakcge, hdlist)
break
}
}
// 发货
func (this *ShopCenter) Delivery(session comm.IUserSession, pId int32) (errdata *pb.ErrorData, items []*pb.UserAtno) {
var (
confs []*cfg.GameShopCenterControlData
conf *cfg.GameShopCenterControlData
info *pb.DBShopCenter
err error
)
if confs, err = this.configure.getGameShopCenterControls(); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.String(),
Message: err.Error(),
}
return
}
for _, v := range confs {
if v.Id == pId {
conf = v
}
}
if conf == nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.String(),
Message: fmt.Sprintf("no found Point:%d", pId),
}
return
}
if info, err = this.modelshop.getUserShopCenter(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if _, ok := info.Item[conf.Id]; ok {
info.Item[conf.Id].Open = true
info.Item[conf.Id].Vip = true
info.Item[conf.Id].Buytime = configure.Now().Unix()
info.Item[conf.Id].Record = make(map[int32]bool)
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.String(),
Message: fmt.Sprintf("no found Point:%d", pId),
}
return
}
if err = this.modelshop.Change(session.GetUserId(), map[string]interface{}{
"item": info.Item,
}); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
}
return
}