上传充值代金券代码
This commit is contained in:
parent
c1ca3484ea
commit
10cb6e5545
@ -606,6 +606,7 @@ const (
|
|||||||
const (
|
const (
|
||||||
Gold int32 = 1 //金币
|
Gold int32 = 1 //金币
|
||||||
Diamond int32 = 2 //钻石
|
Diamond int32 = 2 //钻石
|
||||||
|
Vouchers string = "10000035" //代金券
|
||||||
)
|
)
|
||||||
|
|
||||||
// 排行算虚拟币最低值
|
// 排行算虚拟币最低值
|
||||||
|
@ -166,6 +166,7 @@ type (
|
|||||||
GetUserSessions(uids []string) []*pb.CacheUser
|
GetUserSessions(uids []string) []*pb.CacheUser
|
||||||
//查询用户属性值 例如 金币 经验
|
//查询用户属性值 例如 金币 经验
|
||||||
QueryAttributeValue(uid string, attr string) (value int64)
|
QueryAttributeValue(uid string, attr string) (value int64)
|
||||||
|
QueryAttributeValues(uid string, attr map[string]int64)
|
||||||
//添加/减少属性值 第四个参数控制是否推送给前端
|
//添加/减少属性值 第四个参数控制是否推送给前端
|
||||||
// AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData)
|
// AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData)
|
||||||
// 批量处理
|
// 批量处理
|
||||||
|
@ -20,6 +20,7 @@ func (this *apiComp) DeliveryCheck(session comm.IUserSession, req *pb.PayDeliver
|
|||||||
func (this *apiComp) Delivery(session comm.IUserSession, req *pb.PayDeliveryReq) (errdata *pb.ErrorData) {
|
func (this *apiComp) Delivery(session comm.IUserSession, req *pb.PayDeliveryReq) (errdata *pb.ErrorData) {
|
||||||
var (
|
var (
|
||||||
conf *cfg.GameRechargeData
|
conf *cfg.GameRechargeData
|
||||||
|
need []*cfg.Gameatn
|
||||||
order *pb.DBPayOrder
|
order *pb.DBPayOrder
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
@ -44,12 +45,19 @@ func (this *apiComp) Delivery(session comm.IUserSession, req *pb.PayDeliveryReq)
|
|||||||
Price: conf.Amount,
|
Price: conf.Amount,
|
||||||
Amount: 1,
|
Amount: 1,
|
||||||
}
|
}
|
||||||
|
need = []*cfg.Gameatn{{A: comm.ItemType, T: comm.Vouchers, N: conf.Amount / 100}}
|
||||||
|
|
||||||
|
if errdata = this.module.ConsumeRes(session, need, true); errdata != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err = this.module.model.create(order); err != nil {
|
if err = this.module.model.create(order); err != nil {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_DBError,
|
Code: pb.ErrorCode_DBError,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = this.module.Rpc_ModulePayDelivery(context.Background(), &pb.HttpPayDeliveryReq{
|
if err = this.module.Rpc_ModulePayDelivery(context.Background(), &pb.HttpPayDeliveryReq{
|
||||||
Uid: session.GetUserId(),
|
Uid: session.GetUserId(),
|
||||||
Orderid: order.Orderid,
|
Orderid: order.Orderid,
|
||||||
|
@ -41,7 +41,15 @@ func (this *ModuleRobot_Combat) OncePipeline(robot IRobot) (err error) {
|
|||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_Combat) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_Combat) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
conf *cfg.GameCombatLevelData
|
||||||
|
)
|
||||||
|
conf = this.GetCombatLevelData()[0]
|
||||||
|
if _, errdata = robot.SendMessage("combat", "in", &pb.CombatInReq{Level: conf.Id}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,24 +30,25 @@ func (this *ModuleRobot_Practice) Receive(robot IRobot, stype string, message pr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *ModuleRobot_Practice) OncePipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_Practice) OncePipeline(robot IRobot) (err error) {
|
||||||
|
if _, errdata := robot.SendMessage("practice", "info", &pb.PracticeInfoReq{}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_Practice) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_Practice) DoPipeline(robot IRobot) (err error) {
|
||||||
|
if _, errdata := robot.SendMessage("practice", "info", &pb.PracticeInfoReq{}); errdata != nil {
|
||||||
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//做任务
|
//做任务
|
||||||
func (this *ModuleRobot_Practice) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
func (this *ModuleRobot_Practice) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||||
var (
|
|
||||||
errdata *pb.ErrorData
|
|
||||||
)
|
|
||||||
if _, errdata = robot.SendMessage("practice", "info", &pb.PracticeInfoReq{}); errdata != nil {
|
|
||||||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch comm.TaskType(condconf.Type) {
|
switch comm.TaskType(condconf.Type) {
|
||||||
case comm.Rtype149:
|
case comm.Rtype149:
|
||||||
for i := 1; i < 4; i++ {
|
for i := 1; i < 4; i++ {
|
||||||
|
@ -36,6 +36,8 @@ type Robot struct {
|
|||||||
cycle bool
|
cycle bool
|
||||||
pipeline []*Pipeline //执行流水线
|
pipeline []*Pipeline //执行流水线
|
||||||
statistics []*RobotStatistics
|
statistics []*RobotStatistics
|
||||||
|
receiveNum map[string]int32 //接收消息统计
|
||||||
|
receiveSize map[string]int64 //接收消息统计
|
||||||
wtaskerror error
|
wtaskerror error
|
||||||
awaitState int32 //状态 1没有等待 2等待回应 3关闭
|
awaitState int32 //状态 1没有等待 2等待回应 3关闭
|
||||||
}
|
}
|
||||||
@ -61,6 +63,8 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
|
|||||||
this.await = make(chan *MessageResp)
|
this.await = make(chan *MessageResp)
|
||||||
this.modules = make(map[core.M_Modules]IModuleRobot)
|
this.modules = make(map[core.M_Modules]IModuleRobot)
|
||||||
this.statistics = make([]*RobotStatistics, 0, 100)
|
this.statistics = make([]*RobotStatistics, 0, 100)
|
||||||
|
this.receiveNum = make(map[string]int32)
|
||||||
|
this.receiveSize = make(map[string]int64)
|
||||||
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
||||||
this.modules[comm.ModuleSys] = new(ModuleRobot_Sys)
|
this.modules[comm.ModuleSys] = new(ModuleRobot_Sys)
|
||||||
this.modules[comm.ModuleGM] = new(ModuleRobot_GM)
|
this.modules[comm.ModuleGM] = new(ModuleRobot_GM)
|
||||||
@ -78,6 +82,7 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
|
|||||||
this.modules[comm.ModuleCaravan] = new(ModuleRobot_Caravan)
|
this.modules[comm.ModuleCaravan] = new(ModuleRobot_Caravan)
|
||||||
this.modules[comm.ModuleHoroscope] = new(ModuleRobot_Horoscope)
|
this.modules[comm.ModuleHoroscope] = new(ModuleRobot_Horoscope)
|
||||||
this.modules[comm.ModuleCombat] = new(ModuleRobot_Combat)
|
this.modules[comm.ModuleCombat] = new(ModuleRobot_Combat)
|
||||||
|
this.modules[comm.ModuleSmithy] = new(ModuleRobot_Smithy)
|
||||||
|
|
||||||
for _, v := range this.modules {
|
for _, v := range this.modules {
|
||||||
v.Init()
|
v.Init()
|
||||||
@ -99,6 +104,8 @@ func (this *Robot) Receive(msg *pb.UserMessage) (err error) {
|
|||||||
if msgpath == "gateway.heartbeat" { //心跳 屏蔽掉
|
if msgpath == "gateway.heartbeat" { //心跳 屏蔽掉
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.receiveNum[msgpath]++
|
||||||
|
this.receiveSize[msgpath] += int64(len(msg.Data.Value))
|
||||||
// log.Debug("[机器人 Resp]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: msgpath})
|
// log.Debug("[机器人 Resp]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: msgpath})
|
||||||
//序列化用户消息对象
|
//序列化用户消息对象
|
||||||
if message, err = msg.Data.UnmarshalNew(); err != nil {
|
if message, err = msg.Data.UnmarshalNew(); err != nil {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/utils"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
@ -22,6 +23,8 @@ type statisticalComp struct {
|
|||||||
curonlineNum int32 //当前在线人数
|
curonlineNum int32 //当前在线人数
|
||||||
maxonlineNum int32 //最大在线人数
|
maxonlineNum int32 //最大在线人数
|
||||||
robotdata map[string][]*RobotStatistics //机器人统计数据
|
robotdata map[string][]*RobotStatistics //机器人统计数据
|
||||||
|
receiveMsg map[string]int32 //接收消息数统计
|
||||||
|
receiveMsgSize map[string]int64 //接收消息数统计
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
start time.Time //开始时间
|
start time.Time //开始时间
|
||||||
end time.Time //结束时间
|
end time.Time //结束时间
|
||||||
@ -32,6 +35,8 @@ func (this *statisticalComp) Init(service core.IService, module core.IModule, co
|
|||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.module = module.(*RobotModule)
|
this.module = module.(*RobotModule)
|
||||||
this.robotdata = make(map[string][]*RobotStatistics)
|
this.robotdata = make(map[string][]*RobotStatistics)
|
||||||
|
this.receiveMsg = make(map[string]int32)
|
||||||
|
this.receiveMsgSize = make(map[string]int64)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +66,12 @@ func (this *statisticalComp) AddFailClient(robot *Robot, err error) {
|
|||||||
func (this *statisticalComp) RobotFinishedTest(robot *Robot) {
|
func (this *statisticalComp) RobotFinishedTest(robot *Robot) {
|
||||||
this.lock.Lock()
|
this.lock.Lock()
|
||||||
this.robotdata[robot.Account()] = robot.statistics
|
this.robotdata[robot.Account()] = robot.statistics
|
||||||
|
for k, v := range robot.receiveNum {
|
||||||
|
this.receiveMsg[k] += v
|
||||||
|
}
|
||||||
|
for k, v := range robot.receiveSize {
|
||||||
|
this.receiveMsgSize[k] += v
|
||||||
|
}
|
||||||
this.curonlineNum--
|
this.curonlineNum--
|
||||||
this.succclientNum++
|
this.succclientNum++
|
||||||
this.end = time.Now()
|
this.end = time.Now()
|
||||||
@ -71,10 +82,14 @@ func (this *statisticalComp) RobotFinishedTest(robot *Robot) {
|
|||||||
func (this *statisticalComp) OutReport() {
|
func (this *statisticalComp) OutReport() {
|
||||||
var (
|
var (
|
||||||
messages map[string][]int64 = make(map[string][]int64)
|
messages map[string][]int64 = make(map[string][]int64)
|
||||||
|
receive map[string]int32 = make(map[string]int32)
|
||||||
|
receiveSize map[string]int64 = make(map[string]int64)
|
||||||
totalmessage int32
|
totalmessage int32
|
||||||
|
totalreceive int32
|
||||||
|
totalreceiveSize int64
|
||||||
ok bool
|
ok bool
|
||||||
)
|
)
|
||||||
this.lock.Lock()
|
this.lock.RLock()
|
||||||
for _, datas := range this.robotdata {
|
for _, datas := range this.robotdata {
|
||||||
for _, v := range datas {
|
for _, v := range datas {
|
||||||
totalmessage++
|
totalmessage++
|
||||||
@ -84,7 +99,15 @@ func (this *statisticalComp) OutReport() {
|
|||||||
messages[v.message] = append(messages[v.message], v.time)
|
messages[v.message] = append(messages[v.message], v.time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.lock.Unlock()
|
for k, v := range this.receiveMsg {
|
||||||
|
receive[k] = v
|
||||||
|
totalreceive += v
|
||||||
|
}
|
||||||
|
for k, v := range this.receiveMsgSize {
|
||||||
|
receiveSize[k] = v
|
||||||
|
totalreceiveSize += v
|
||||||
|
}
|
||||||
|
this.lock.RUnlock()
|
||||||
file, err := os.OpenFile(this.module.options.OutFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
file, err := os.OpenFile(this.module.options.OutFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@ -97,6 +120,7 @@ func (this *statisticalComp) OutReport() {
|
|||||||
file.WriteString(fmt.Sprintf("最大同时在线人数: %d\n", this.maxonlineNum))
|
file.WriteString(fmt.Sprintf("最大同时在线人数: %d\n", this.maxonlineNum))
|
||||||
file.WriteString(fmt.Sprintf("压测执行时长: %.2f秒\n", this.end.Sub(this.start).Seconds()))
|
file.WriteString(fmt.Sprintf("压测执行时长: %.2f秒\n", this.end.Sub(this.start).Seconds()))
|
||||||
file.WriteString(fmt.Sprintf("消息总请求数: %d\n", totalmessage))
|
file.WriteString(fmt.Sprintf("消息总请求数: %d\n", totalmessage))
|
||||||
|
file.WriteString(fmt.Sprintf("消息总接收数: %d 接收消息总大小:%s\n", totalreceive, utils.FormatByesSize(totalreceiveSize)))
|
||||||
file.WriteString(fmt.Sprintf("QPS: %.2f\n", float64(totalmessage)/this.end.Sub(this.start).Seconds()))
|
file.WriteString(fmt.Sprintf("QPS: %.2f\n", float64(totalmessage)/this.end.Sub(this.start).Seconds()))
|
||||||
file.WriteString("---消息压测详情----------------------------------------------------------------------------------------------------\n")
|
file.WriteString("---消息压测详情----------------------------------------------------------------------------------------------------\n")
|
||||||
for message, data := range messages {
|
for message, data := range messages {
|
||||||
@ -118,6 +142,10 @@ func (this *statisticalComp) OutReport() {
|
|||||||
}
|
}
|
||||||
file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 耗时最小:%-5dms 耗时最大:%-5dms 平均耗时:%-5.2fms 中位耗时:%-5.2fms \n", message, len(data), min, max, avg, median))
|
file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 耗时最小:%-5dms 耗时最大:%-5dms 平均耗时:%-5.2fms 中位耗时:%-5.2fms \n", message, len(data), min, max, avg, median))
|
||||||
}
|
}
|
||||||
|
file.WriteString("---消息压测接收回包消息统计----------------------------------------------------------------------------------------------------\n")
|
||||||
|
for k, v := range receive {
|
||||||
|
file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 请求总大小:%s\n", k, v, utils.FormatByesSize(receiveSize[k])))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *statisticalComp) run() {
|
func (this *statisticalComp) run() {
|
||||||
|
@ -396,6 +396,71 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int64) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *User) QueryAttributeValues(uid string, attr map[string]int64) {
|
||||||
|
var (
|
||||||
|
user *pb.DBUser
|
||||||
|
userEx *pb.DBUserExpand
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
user, err = this.modelUser.GetUser(uid)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userEx, err = this.GetUserExpand(uid)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if user == nil || userEx == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for k, _ := range attr {
|
||||||
|
switch k {
|
||||||
|
case comm.ResGold:
|
||||||
|
attr[k] = user.Gold
|
||||||
|
case comm.ResExp:
|
||||||
|
attr[k] = user.Exp
|
||||||
|
case comm.VipExp:
|
||||||
|
attr[k] = user.Vipexp
|
||||||
|
case comm.StarCoin:
|
||||||
|
attr[k] = user.Starcoin
|
||||||
|
case comm.ResDiamond:
|
||||||
|
attr[k] = user.Diamond
|
||||||
|
case comm.ResPs:
|
||||||
|
attr[k] = int64(user.Ps)
|
||||||
|
case comm.SociatyCoin:
|
||||||
|
attr[k] = int64(userEx.Guildcoin)
|
||||||
|
case comm.ArenaCoin:
|
||||||
|
attr[k] = int64(userEx.Arenacoin)
|
||||||
|
case comm.ResFriend:
|
||||||
|
attr[k] = int64(userEx.FriendPoint)
|
||||||
|
case comm.Moongold:
|
||||||
|
attr[k] = int64(user.Moongold)
|
||||||
|
case comm.Talent1:
|
||||||
|
attr[k] = int64(user.Talent1)
|
||||||
|
case comm.Talent2:
|
||||||
|
attr[k] = int64(user.Talent2)
|
||||||
|
case comm.Talent3:
|
||||||
|
attr[k] = int64(user.Talent3)
|
||||||
|
case comm.Talent4:
|
||||||
|
attr[k] = int64(user.Talent4)
|
||||||
|
case comm.Merchantmoney:
|
||||||
|
attr[k] = int64(user.Merchantmoney)
|
||||||
|
case comm.Integral:
|
||||||
|
attr[k] = int64(user.Integral)
|
||||||
|
case comm.Profit:
|
||||||
|
attr[k] = int64(user.Profit)
|
||||||
|
case comm.Consumeexp:
|
||||||
|
attr[k] = int64(user.Consumeexp)
|
||||||
|
case comm.Consumemoney:
|
||||||
|
attr[k] = int64(user.Consumemoney)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atno []*pb.UserAtno, change *pb.UserResChangedPush, errdata *pb.ErrorData) {
|
func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atno []*pb.UserAtno, change *pb.UserResChangedPush, errdata *pb.ErrorData) {
|
||||||
uid := session.GetUserId()
|
uid := session.GetUserId()
|
||||||
var (
|
var (
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -95,3 +96,21 @@ func ToInt64(s string) int64 {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 字节的单位转换 保留两位小数
|
||||||
|
func FormatByesSize(fileSize int64) (size string) {
|
||||||
|
if fileSize < 1024 {
|
||||||
|
//return strconv.FormatInt(fileSize, 10) + "B"
|
||||||
|
return fmt.Sprintf("%.2fB", float64(fileSize)/float64(1))
|
||||||
|
} else if fileSize < (1024 * 1024) {
|
||||||
|
return fmt.Sprintf("%.2fKB", float64(fileSize)/float64(1024))
|
||||||
|
} else if fileSize < (1024 * 1024 * 1024) {
|
||||||
|
return fmt.Sprintf("%.2fMB", float64(fileSize)/float64(1024*1024))
|
||||||
|
} else if fileSize < (1024 * 1024 * 1024 * 1024) {
|
||||||
|
return fmt.Sprintf("%.2fGB", float64(fileSize)/float64(1024*1024*1024))
|
||||||
|
} else if fileSize < (1024 * 1024 * 1024 * 1024 * 1024) {
|
||||||
|
return fmt.Sprintf("%.2fTB", float64(fileSize)/float64(1024*1024*1024*1024))
|
||||||
|
} else { //if fileSize < (1024 * 1024 * 1024 * 1024 * 1024 * 1024)
|
||||||
|
return fmt.Sprintf("%.2fPB", float64(fileSize)/float64(1024*1024*1024*1024*1024))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user