109 lines
2.8 KiB
Go
109 lines
2.8 KiB
Go
package pay
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
/*
|
|
模块名:支付系统
|
|
描述:充值商城
|
|
开发:李伟
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(Pay)
|
|
return m
|
|
}
|
|
|
|
type Pay struct {
|
|
modules.ModuleBase
|
|
service base.IRPCXService
|
|
api *apiComp
|
|
modelPay *modelPayComp
|
|
modelDaily *modelDailyComp
|
|
configure *configureComp
|
|
}
|
|
|
|
//模块名
|
|
func (this *Pay) GetType() core.M_Modules {
|
|
return comm.ModulePay
|
|
}
|
|
|
|
//模块初始化接口 注册用户创建角色事件
|
|
func (this *Pay) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service.(base.IRPCXService)
|
|
return
|
|
}
|
|
func (this *Pay) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
this.service.RegisterFunctionName(string(comm.Rpc_ModulePayDelivery), this.Rpc_ModulePayDelivery)
|
|
return
|
|
}
|
|
|
|
//装备组件
|
|
func (this *Pay) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelPay = this.RegisterComp(new(modelPayComp)).(*modelPayComp)
|
|
this.modelDaily = this.RegisterComp(new(modelDailyComp)).(*modelDailyComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
//RPC-----------------------------------------------------------------------------------------------------------------------
|
|
func (this *Pay) Rpc_ModulePayDelivery(ctx context.Context, args *pb.PayDeliveryReq, reply *pb.PayDeliveryResp) (err error) {
|
|
this.Debug("Rpc_ModulePayDelivery", log.Field{Key: "args", Value: args.String()})
|
|
var (
|
|
conf *cfg.GameRechargeData
|
|
res []*cfg.Gameatn
|
|
session comm.IUserSession
|
|
online bool
|
|
)
|
|
|
|
if conf, err = this.configure.getGameRecharge(args.Productid); err != nil {
|
|
reply.Code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
if session, online = this.GetUserSession(args.Uid); online {
|
|
if reply.Code = this.DispenseRes(session, res, true); reply.Code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if err = session.Push(); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
} else {
|
|
session = comm.NewUserSessionByPools(this.service)
|
|
session.SetSession("", "", "", "", args.Uid)
|
|
if reply.Code = this.DispenseRes(session, res, false); reply.Code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
if err = this.modelPay.addUserPayOrder(&pb.DBPayOrder{
|
|
Orderid: args.Orderid,
|
|
Uid: args.Uid,
|
|
Productid: args.Productid,
|
|
Ctime: time.Now().Unix(),
|
|
}); err != nil {
|
|
reply.Code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
switch conf.RechargeType {
|
|
case 1:
|
|
break
|
|
case 2:
|
|
reply.Code = this.modelDaily.delivery(args.Uid, args.Productid)
|
|
break
|
|
}
|
|
return
|
|
}
|