go_dreamfactory/modules/warorder/module.go
2023-07-12 11:31:33 +08:00

91 lines
2.1 KiB
Go

package warorder
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
const modulename = "战令"
type Warorder struct {
modules.ModuleBase
service core.IService
api *apiComp
configure *configureComp
modelWarorder *modelWarorder
}
func NewModule() core.IModule {
return &Warorder{}
}
func (this *Warorder) GetType() core.M_Modules {
return comm.ModuleWarorder
}
func (this *Warorder) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
return
}
func (this *Warorder) Start() (err error) {
err = this.ModuleBase.Start()
return
}
func (this *Warorder) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelWarorder = this.RegisterComp(new(modelWarorder)).(*modelWarorder)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 发货
func (this *Warorder) Delivery(session comm.IUserSession, pid string) (errdata *pb.ErrorData, items []*pb.UserAssets) {
var (
product map[string]int32 //商品id
warorders *pb.DBWarorders
info *pb.Warorder
wtype int32
err error
ok bool
)
product = this.configure.getproduct()
if _, ok = product[pid]; !ok {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.String(),
Message: fmt.Sprintf("no found pid:%s", pid),
}
return
}
wtype = product[pid]
if warorders, err = this.modelWarorder.getUserWarorders(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if info, ok = warorders.Items[wtype]; !ok {
info = &pb.Warorder{
Vip: false,
Free: make([]int32, 0),
Pay: make([]int32, 0),
Progress: 0,
}
warorders.Items[wtype] = info
}
info.Vip = true
this.modelWarorder.updateUserWarorders(session.GetUserId(), warorders)
return
}