153 lines
3.7 KiB
Go
153 lines
3.7 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.UserAssets) {
|
|
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:%s", 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
|
|
}
|
|
|
|
info.Item[conf.Id] = &pb.DBShopCenterItem{
|
|
Id: conf.Id,
|
|
Vip: true,
|
|
Open: true,
|
|
Buytime: configure.Now().Unix(),
|
|
Record: make(map[int32]bool),
|
|
}
|
|
items = make([]*pb.UserAssets, 0)
|
|
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
|
|
}
|