Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,410 @@
|
||||
package gameServerMgr
|
||||
|
||||
import (
|
||||
"Framework/managecenterModel"
|
||||
"goutil/stringUtil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChargeUtil_GetChargeConfigList(t *testing.T) {
|
||||
/*
|
||||
渠道充值配置:[{"ProductId":"fzxh_00060","ChargePoint":6,"GamePoint":60,"Ratio":10,"GiveGamePoint":6,"FirstGiveGamePoint":60,"GiveRatio":0.1,"VipLv":0,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00300","ChargePoint":30,"GamePoint":300,"Ratio":10,"GiveGamePoint":30,"FirstGiveGamePoint":300,"GiveRatio":0.1,"VipLv":0,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00500","ChargePoint":50,"GamePoint":550,"Ratio":11,"GiveGamePoint":110,"FirstGiveGamePoint":550,"GiveRatio":0.2,"VipLv":1,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00980","ChargePoint":98,"GamePoint":1470,"Ratio":15,"GiveGamePoint":441,"FirstGiveGamePoint":1470,"GiveRatio":0.3,"VipLv":5,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_restriction_18","ChargePoint":18,"GamePoint":90,"Ratio":5,"GiveGamePoint":0,"FirstGiveGamePoint":0,"GiveRatio":0,"VipLv":3,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":true},{"ProductId":"fzxh_restriction_50","ChargePoint":50,"GamePoint":300,"Ratio":6,"GiveGamePoint":0,"FirstGiveGamePoint":0,"GiveRatio":0,"VipLv":1,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":true}]
|
||||
*/
|
||||
|
||||
var managecenterUrl = "http://managecenterapitest-xxx.79yougame.com/"
|
||||
var serverGroupId int32 = 20001
|
||||
var partnerId int32 = 1001
|
||||
|
||||
//激活器服务器,获取mc配置
|
||||
error := ActiveServer(managecenterUrl, serverGroupId)
|
||||
if error != nil {
|
||||
t.Fatalf("激活服务器出现错误:%v", error)
|
||||
}
|
||||
|
||||
type VipRange struct {
|
||||
MinVip byte
|
||||
MaxVip byte
|
||||
}
|
||||
|
||||
var isMonthCard = false
|
||||
var maxVip byte = 20
|
||||
|
||||
vipMap := make(map[VipRange][]float64)
|
||||
vipMap[VipRange{MinVip: 0, MaxVip: 0}] = []float64{6, 30}
|
||||
vipMap[VipRange{MinVip: 1, MaxVip: 4}] = []float64{6, 30, 50}
|
||||
vipMap[VipRange{MinVip: 5, MaxVip: maxVip}] = []float64{6, 30, 50, 98}
|
||||
|
||||
isExistsChargeConfig := func(configs []*managecenterModel.ChargeConfig, point float64) bool {
|
||||
for _, item := range configs {
|
||||
if item.ChargePoint == point {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
//每个VIP等级都获取一遍充值档位
|
||||
for vipRange, points := range vipMap {
|
||||
for vip := vipRange.MinVip; vip <= vipRange.MaxVip; vip++ {
|
||||
showChargeList, exists, error := ChargeUtilObj.GetChargeConfigList(partnerId, vip, isMonthCard, func(config *managecenterModel.ChargeConfig) bool {
|
||||
if config.IfFirstShow == 1 && config.IfSecondShow == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if error != nil {
|
||||
t.Fatalf("获取充值配置列表出现错误:%v", error)
|
||||
}
|
||||
|
||||
if !exists {
|
||||
t.Fatalf("PartnerId[%d],Vip[%d],IsMonthCard[%v],未找到充值配置列表", partnerId, vip, isMonthCard)
|
||||
}
|
||||
|
||||
for _, point := range points {
|
||||
if !isExistsChargeConfig(showChargeList, point) {
|
||||
t.Fatalf("PartnerId[%d],Vip[%d],IsMonthCard[%v],金额[%f]未找到充值配置", partnerId, vip, isMonthCard, point)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 测试生成订单号
|
||||
func TestChargeUtil_GenerateOrderId(t *testing.T) {
|
||||
var chargeServerUrl = "https://chargetest-xht.moqikaka.com/API/GenerateOrderId.ashx"
|
||||
var serverGroupId int32 = 20001
|
||||
var partnerId int32 = 1001
|
||||
var productId = "fzxh_00060"
|
||||
var userId = stringUtil.GetNewGUID()
|
||||
var playerId = stringUtil.GetNewGUID()
|
||||
var isMonthCard = true
|
||||
|
||||
//生成订单号
|
||||
orderId, error := ChargeUtilObj.GenerateOrderId(
|
||||
chargeServerUrl, productId, partnerId, serverGroupId, userId, playerId, "macmacmacmac", "idfa", "ip", "imei", "extra", isMonthCard)
|
||||
if error != nil {
|
||||
t.Fatalf("生成订单号[GenerateOrderId]出现错误:%v", error)
|
||||
}
|
||||
|
||||
t.Logf("生成订单号[GenerateOrderId]:%s", orderId)
|
||||
}
|
||||
|
||||
// 测试验证充值回调签名
|
||||
func TestChargeUtil_CheckChargeSign(t *testing.T) {
|
||||
var managecenterUrl = "http://managecenterapitest-xxx.79yougame.com/"
|
||||
var serverGroupId int32 = 20001
|
||||
var partnerId int32 = 1001
|
||||
var playerId = "04bade21-d7f7-4188-bc7c-8914c5330a23"
|
||||
var orderId = "1001_20001_1590394423_2"
|
||||
var productId = "fzxh_00060"
|
||||
var deviceIdentifier = "deviceIdentifier"
|
||||
//var loginKey = "a0482eaf-14e8-4a65-950e-864214f62da5"
|
||||
|
||||
//激活器服务器,获取mc配置
|
||||
error := ActiveServer(managecenterUrl, serverGroupId)
|
||||
if error != nil {
|
||||
t.Fatalf("激活服务器出现错误:%v", error)
|
||||
}
|
||||
|
||||
//充值服务器生成的签名
|
||||
var targetSign = "02bd33319fc0f520a3e801f725973017"
|
||||
|
||||
//验证充值回调签名是否正确
|
||||
if !ChargeUtilObj.CheckChargeSign(partnerId, serverGroupId, playerId, orderId, productId, deviceIdentifier, targetSign) {
|
||||
t.Fatalf("验证充值回调签名失败!目标签名:%s", targetSign)
|
||||
}
|
||||
}
|
||||
|
||||
// 测试获取充值配置
|
||||
func TestChargeUtil_GetChargeConfigItem(t *testing.T) {
|
||||
/*
|
||||
渠道充值配置:[{"ProductId":"fzxh_00060","ChargePoint":6,"GamePoint":60,"Ratio":10,"GiveGamePoint":6,"FirstGiveGamePoint":60,"GiveRatio":0.1,"VipLv":0,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00300","ChargePoint":30,"GamePoint":300,"Ratio":10,"GiveGamePoint":30,"FirstGiveGamePoint":300,"GiveRatio":0.1,"VipLv":0,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00500","ChargePoint":50,"GamePoint":550,"Ratio":11,"GiveGamePoint":110,"FirstGiveGamePoint":550,"GiveRatio":0.2,"VipLv":1,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00980","ChargePoint":98,"GamePoint":1470,"Ratio":15,"GiveGamePoint":441,"FirstGiveGamePoint":1470,"GiveRatio":0.3,"VipLv":5,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_restriction_18","ChargePoint":18,"GamePoint":90,"Ratio":5,"GiveGamePoint":0,"FirstGiveGamePoint":0,"GiveRatio":0,"VipLv":3,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":true},{"ProductId":"fzxh_restriction_50","ChargePoint":50,"GamePoint":300,"Ratio":6,"GiveGamePoint":0,"FirstGiveGamePoint":0,"GiveRatio":0,"VipLv":1,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":true}]
|
||||
*/
|
||||
|
||||
var managecenterUrl = "http://managecenterapitest-xxx.79yougame.com/"
|
||||
var serverGroupId int32 = 20001
|
||||
var partnerId int32 = 1001
|
||||
var maxVip byte = 20
|
||||
|
||||
//激活器服务器,获取mc配置
|
||||
error := ActiveServer(managecenterUrl, serverGroupId)
|
||||
if error != nil {
|
||||
t.Fatalf("激活服务器出现错误:%v", error)
|
||||
}
|
||||
|
||||
type VipRange struct {
|
||||
MinVip byte
|
||||
MaxVip byte
|
||||
}
|
||||
|
||||
//#region 测试获取普通充值配置
|
||||
|
||||
isMonthCard := false
|
||||
vipMap := make(map[VipRange][]float64)
|
||||
vipMap[VipRange{MinVip: 0, MaxVip: 0}] = []float64{6, 30}
|
||||
vipMap[VipRange{MinVip: 1, MaxVip: 4}] = []float64{6, 30, 50}
|
||||
vipMap[VipRange{MinVip: 5, MaxVip: maxVip}] = []float64{6, 30, 50, 98}
|
||||
|
||||
//每个VIP等级都获取一遍充值档位
|
||||
for vipRange, points := range vipMap {
|
||||
for vip := vipRange.MinVip; vip <= vipRange.MaxVip; vip++ {
|
||||
for _, point := range points {
|
||||
//获取充值配置
|
||||
chargeConfig, exists, error := ChargeUtilObj.GetChargeConfigItem(partnerId, vip, isMonthCard, point)
|
||||
if error != nil {
|
||||
t.Fatalf("普通充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]获取充值档位出现错误:%v", vip, point, error)
|
||||
}
|
||||
|
||||
if !exists {
|
||||
t.Fatalf("普通充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]未找到充值档位配置", vip, point)
|
||||
}
|
||||
|
||||
if chargeConfig == nil {
|
||||
t.Fatalf("普通充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]找到的充值档位配置为nil", vip, point)
|
||||
}
|
||||
|
||||
if chargeConfig.ChargePoint != point {
|
||||
t.Fatalf("普通充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]找到的充值档位ChargePoint[%f]错误", vip, point, chargeConfig.ChargePoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 测试获取月卡充值配置
|
||||
|
||||
isMonthCard = true
|
||||
vipMap = make(map[VipRange][]float64)
|
||||
vipMap[VipRange{MinVip: 1, MaxVip: 1}] = []float64{50}
|
||||
vipMap[VipRange{MinVip: 3, MaxVip: maxVip}] = []float64{18, 50}
|
||||
|
||||
//每个VIP等级都获取一遍充值档位
|
||||
for vipRange, points := range vipMap {
|
||||
for vip := vipRange.MinVip; vip <= vipRange.MaxVip; vip++ {
|
||||
for _, point := range points {
|
||||
//获取充值配置
|
||||
chargeConfig, exists, error := ChargeUtilObj.GetChargeConfigItem(partnerId, vip, isMonthCard, point)
|
||||
if error != nil {
|
||||
t.Fatalf("月卡充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]获取充值档位出现错误:%v", vip, point, error)
|
||||
}
|
||||
|
||||
if !exists {
|
||||
t.Fatalf("月卡充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]未找到充值档位配置", vip, point)
|
||||
}
|
||||
|
||||
if chargeConfig == nil {
|
||||
t.Fatalf("月卡充值,Vip[%d],Point[%f]找到的充值档位配置为nil", vip, point)
|
||||
}
|
||||
|
||||
if chargeConfig.ChargePoint != point {
|
||||
t.Fatalf("月卡充值,获取充值配置[GetChargeConfigItem],Vip[%d],Point[%f]找到的充值档位ChargePoint[%f]错误", vip, point, chargeConfig.ChargePoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
||||
// 测试计算充值获得的游戏货币
|
||||
func TestChargeUtil_CalcChargeAllGamePoint(t *testing.T) {
|
||||
/*
|
||||
渠道充值配置:[{"ProductId":"fzxh_00060","ChargePoint":6,"GamePoint":60,"Ratio":10,"GiveGamePoint":6,"FirstGiveGamePoint":60,"GiveRatio":0.1,"VipLv":0,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00300","ChargePoint":30,"GamePoint":300,"Ratio":10,"GiveGamePoint":30,"FirstGiveGamePoint":300,"GiveRatio":0.1,"VipLv":0,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00500","ChargePoint":50,"GamePoint":550,"Ratio":11,"GiveGamePoint":110,"FirstGiveGamePoint":550,"GiveRatio":0.2,"VipLv":1,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_00980","ChargePoint":98,"GamePoint":1470,"Ratio":15,"GiveGamePoint":441,"FirstGiveGamePoint":1470,"GiveRatio":0.3,"VipLv":5,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":false},{"ProductId":"fzxh_restriction_18","ChargePoint":18,"GamePoint":90,"Ratio":5,"GiveGamePoint":0,"FirstGiveGamePoint":0,"GiveRatio":0,"VipLv":3,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":true},{"ProductId":"fzxh_restriction_50","ChargePoint":50,"GamePoint":300,"Ratio":6,"GiveGamePoint":0,"FirstGiveGamePoint":0,"GiveRatio":0,"VipLv":1,"IfFirstShow":1,"IfSecondShow":1,"IsMonthCard":true}]
|
||||
*/
|
||||
|
||||
var managecenterUrl = "http://managecenterapitest-xxx.79yougame.com/"
|
||||
var serverGroupId int32 = 20001
|
||||
var partnerId int32 = 1001
|
||||
|
||||
//激活器服务器,获取mc配置
|
||||
error := ActiveServer(managecenterUrl, serverGroupId)
|
||||
if error != nil {
|
||||
t.Fatalf("激活服务器出现错误:%v", error)
|
||||
}
|
||||
|
||||
//输入订单信息
|
||||
type OrderItem struct {
|
||||
Vip byte
|
||||
Money float64
|
||||
ActivityMoney float64
|
||||
ProductId string
|
||||
IsFirstCharge bool
|
||||
IsMonthCard bool
|
||||
}
|
||||
|
||||
//计算结果
|
||||
type GamePointResult struct {
|
||||
ChargeGamePoint int
|
||||
GiveGamePoint int
|
||||
ActivityGamePoint int
|
||||
TotalGamePoint int
|
||||
}
|
||||
|
||||
testOrderMap := make(map[OrderItem]GamePointResult)
|
||||
|
||||
//#region 普通充值
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 0,
|
||||
Money: 6,
|
||||
ActivityMoney: 1,
|
||||
ProductId: "fzxh_00060",
|
||||
IsFirstCharge: true,
|
||||
IsMonthCard: false,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 60, //GamePoint
|
||||
GiveGamePoint: 60, //FirstGiveGamePoint
|
||||
ActivityGamePoint: 10, //ActivityMoney*Ratio = 1*10
|
||||
TotalGamePoint: 130,
|
||||
} //首充6元,活动金额1元
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 0,
|
||||
Money: 6,
|
||||
ActivityMoney: 1,
|
||||
ProductId: "fzxh_00060",
|
||||
IsFirstCharge: false,
|
||||
IsMonthCard: false,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 60, //GamePoint
|
||||
GiveGamePoint: 6, //GiveGamePoint 6
|
||||
ActivityGamePoint: 10, //ActivityMoney*Ratio = 1*10
|
||||
TotalGamePoint: 76,
|
||||
} //非首充6元,活动金额1元
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 0,
|
||||
Money: 0,
|
||||
ActivityMoney: 1,
|
||||
ProductId: "fzxh_00060",
|
||||
IsFirstCharge: false,
|
||||
IsMonthCard: false,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 60, //Money*Ratio = 6*10
|
||||
GiveGamePoint: 6, //GiveGamePoint 6
|
||||
ActivityGamePoint: 10, //ActivityMoney*Ratio = 1*10
|
||||
TotalGamePoint: 76,
|
||||
} //无金额匹配6元,活动金额1元
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 0,
|
||||
Money: 10,
|
||||
ActivityMoney: 3,
|
||||
ProductId: "",
|
||||
IsFirstCharge: false,
|
||||
IsMonthCard: false,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 100, //Money*Ratio = 10*10
|
||||
GiveGamePoint: 10, //Money*Ratio*GiveRatio 10 * 10 * 0.1
|
||||
ActivityGamePoint: 30, //ActivityMoney*Ratio = 3*10
|
||||
TotalGamePoint: 140,
|
||||
} //无对应档位配置,模糊匹配10元,活动金额1元,实际匹配到6元档位
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 3,
|
||||
Money: 98,
|
||||
ActivityMoney: 3,
|
||||
ProductId: "",
|
||||
IsFirstCharge: false,
|
||||
IsMonthCard: false,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 1078, //Money*Ratio = 98*11
|
||||
GiveGamePoint: 216, //Money*Ratio*GiveRatio 98 * 11 * 0.2 = 215.6
|
||||
ActivityGamePoint: 33, //ActivityMoney*Ratio = 3*11
|
||||
TotalGamePoint: 1327,
|
||||
} //Vip限制,匹配98元,实际匹配到50档位,活动金额3元
|
||||
|
||||
//#endregion
|
||||
|
||||
for order, result := range testOrderMap {
|
||||
//计算充值获得的游戏币
|
||||
chargeGamePoint, giveGamePoint, activityGamePoint, totalGamePoint, exists, err := ChargeUtilObj.CalcChargeAllGamePoint(
|
||||
partnerId, order.Vip, order.IsMonthCard, order.Money, order.ActivityMoney, order.ProductId, order.IsFirstCharge)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("普通充值,计算充值获得游戏币[CalcChargeAllGamePoint],金额[%f] error:%v", order.Money, err)
|
||||
}
|
||||
|
||||
if !exists {
|
||||
t.Fatalf("普通充值,计算充值获得游戏币[CalcChargeAllGamePoint],金额[%f]未找到充值配置:%v", order.Money, exists)
|
||||
}
|
||||
|
||||
if chargeGamePoint != result.ChargeGamePoint {
|
||||
t.Fatalf("普通充值,计算充值获得游戏币[CalcChargeAllGamePoint],ChargeGamePoint计算结果不正确,金额[%f],期望[%d],结果[%d]", order.Money, result.ChargeGamePoint, chargeGamePoint)
|
||||
}
|
||||
|
||||
if giveGamePoint != result.GiveGamePoint {
|
||||
t.Fatalf("普通充值,计算充值获得游戏币[CalcChargeAllGamePoint],GiveGamePoint计算结果不正确,金额[%f],期望[%d],结果[%d]", order.Money, result.GiveGamePoint, giveGamePoint)
|
||||
}
|
||||
|
||||
if activityGamePoint != result.ActivityGamePoint {
|
||||
t.Fatalf("普通充值,计算充值获得游戏币[CalcChargeAllGamePoint],ActivityGamePoint计算结果不正确,金额[%f],期望[%d],结果[%d]", order.Money, result.ActivityGamePoint, activityGamePoint)
|
||||
}
|
||||
|
||||
if totalGamePoint != result.TotalGamePoint {
|
||||
t.Fatalf("普通充值,计算充值获得游戏币[CalcChargeAllGamePoint],TotalGamePoint计算结果不正确,金额[%f],期望[%d],结果[%d]", order.Money, result.TotalGamePoint, totalGamePoint)
|
||||
}
|
||||
}
|
||||
|
||||
//#region 月卡充值
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 3,
|
||||
Money: 18,
|
||||
ProductId: "fzxh_restriction_18",
|
||||
IsMonthCard: true,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 90, //GamePoint
|
||||
} //18元月卡
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 0,
|
||||
Money: 50,
|
||||
ProductId: "fzxh_restriction_50",
|
||||
IsMonthCard: true,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 250, //Money * Ratio = 50 * 5
|
||||
} //VIP限制,匹配50元月卡,实际匹配到18元月卡
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 1,
|
||||
Money: 0,
|
||||
ProductId: "fzxh_restriction_50",
|
||||
IsMonthCard: true,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 300, //GamePoint
|
||||
} //无金额匹配50元月卡
|
||||
|
||||
testOrderMap[OrderItem{
|
||||
Vip: 0,
|
||||
Money: 0,
|
||||
ProductId: "fzxh_restriction_50",
|
||||
IsMonthCard: true,
|
||||
}] = GamePointResult{
|
||||
ChargeGamePoint: 0, //匹配不成功
|
||||
} //VIP限制,无金额匹配50元月卡
|
||||
|
||||
for order, result := range testOrderMap {
|
||||
//计算充值获得的游戏币
|
||||
chargeGamePoint, exists, err := ChargeUtilObj.CalcChargeGamePoint(
|
||||
partnerId, order.Vip, order.IsMonthCard, order.Money, order.ProductId)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("月卡充值,计算充值获得游戏币[CalcChargeGamePoint],金额[%f] error:%v", order.Money, err)
|
||||
}
|
||||
|
||||
if !exists {
|
||||
t.Fatalf("月卡充值,计算充值获得游戏币[CalcChargeGamePoint],金额[%f]未找到充值配置:%v", order.Money, exists)
|
||||
}
|
||||
|
||||
if chargeGamePoint != result.ChargeGamePoint {
|
||||
t.Fatalf("月卡充值,计算充值获得游戏币[CalcChargeGamePoint],ChargeGamePoint计算结果不正确,金额[%f],期望[%d],结果[%d]", order.Money, result.ChargeGamePoint, chargeGamePoint)
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package managecenterMgr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"Framework/managecenterModel"
|
||||
. "Framework/managecenterModel"
|
||||
"goutil/logUtil"
|
||||
"goutil/webUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
areaMap = make(map[int32]*Area, 128)
|
||||
areaHash string
|
||||
)
|
||||
|
||||
// 重新加载大区数据
|
||||
func reloadArea(isInit bool) error {
|
||||
//logUtil.DebugLog("开始刷新大区列表")
|
||||
|
||||
// 连接服务器,以获取数据
|
||||
url := getManageCenterUrl("/API/AreaList.ashx")
|
||||
|
||||
// 定义请求参数
|
||||
postDict := make(map[string]string)
|
||||
postDict["HashValue"] = areaHash
|
||||
|
||||
//请求url,请求头
|
||||
header := webUtil.GetFormHeader()
|
||||
transport := webUtil.NewTransport()
|
||||
transport.DisableKeepAlives = true
|
||||
transport = webUtil.GetTimeoutTransport(transport, 30)
|
||||
|
||||
statusCode, returnBytes, err := webUtil.PostMapData(url, postDict, header, transport)
|
||||
//statusCode, returnBytes, err := webUtil.PostMapData(url, postDict, header, nil)
|
||||
if err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取大区列表出错,url:%s,错误信息为:%s", url, err))
|
||||
return err
|
||||
}
|
||||
if statusCode != 200 {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取大区列表出错,url:%s,错误码为:%d", url, statusCode))
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析返回值
|
||||
returnObj := new(ReturnObject)
|
||||
if err = json.Unmarshal(returnBytes, &returnObj); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取大区列表出错,反序列化返回值出错,错误信息为:%s, str:%s", err, string(returnBytes)))
|
||||
return err
|
||||
}
|
||||
|
||||
// 判断返回状态是否为成功
|
||||
if returnObj.Code != 0 {
|
||||
// 数据没有变化,所以没有获取到新的数据,不能算错误。
|
||||
if returnObj.Code == 47 || returnObj.Message == "DataNotChanged" {
|
||||
//如果本地集合为空,且数据又没变化时,重新初始化一下本地hash值
|
||||
if len(areaMap) == 0 {
|
||||
areaHash = ""
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
msg := fmt.Sprintf("获取大区列表出错,返回状态:%d,信息为:%s", returnObj.Code, returnObj.Message)
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// 解析Data
|
||||
tmpAreaList := make([]*Area, 0, 128)
|
||||
if data, ok := returnObj.Data.(string); !ok {
|
||||
msg := "获取大区列表出错,返回的数据不是string类型"
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
} else {
|
||||
if err = json.Unmarshal([]byte(data), &tmpAreaList); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取大区列表出错,反序列化数据出错,错误信息为:%s", err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//logUtil.DebugLog(fmt.Sprintf("刷新大区信息结束,大区数量:%d", len(tmpAreaList)))
|
||||
|
||||
tmpAreaMap := make(map[int32]*Area)
|
||||
for _, item := range tmpAreaList {
|
||||
tmpAreaMap[item.AreaId] = item
|
||||
}
|
||||
|
||||
// 赋值给最终的areaMap
|
||||
areaMap = tmpAreaMap
|
||||
areaHash = returnObj.HashValue
|
||||
|
||||
// 通知变更
|
||||
mcDataChangeCallBack(managecenterModel.AreaData, isInit)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据区服ID获取所属大区ID
|
||||
func GetAreaIdByServerId(serverId int32) (areaId int32, exist bool) {
|
||||
for _, item := range areaMap {
|
||||
if item.CheckServerIdIsInRange(serverId) {
|
||||
areaId = item.AreaId
|
||||
exist = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 根据服务器组id获取大区对象数据
|
||||
func GetAreaDBByGroupId(groupId int32) (areaDB *Area, exist bool) {
|
||||
//如果没有大区数据,返回空
|
||||
exist = false
|
||||
if areaMap == nil || len(areaMap) < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range areaMap {
|
||||
if item.CheckServerIdIsInRange(groupId) {
|
||||
areaDB = item
|
||||
exist = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取所有大区信息
|
||||
func GetAllAreaDB() []*Area {
|
||||
tempList := make([]*Area, 8)
|
||||
for _, item := range areaMap {
|
||||
tempList = append(tempList, item)
|
||||
}
|
||||
return tempList
|
||||
}
|
||||
|
||||
// 根据大区ID获取大区信息
|
||||
func GetAreaDBbyAreaID(areaId int32) (areaDB *Area, exist bool) {
|
||||
//如果没有大区数据,返回空
|
||||
exist = false
|
||||
if areaMap == nil || len(areaMap) < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
if item, ok := areaMap[areaId]; ok {
|
||||
areaDB = item
|
||||
exist = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 根据服务器ID获取大区页签信息
|
||||
func GetAreaLabelDBByGroupId(groupId int32) (areaLabelDB *AreaLabel, exist bool) {
|
||||
areaDB, exist := GetAreaDBByGroupId(groupId)
|
||||
if !exist {
|
||||
return nil, false
|
||||
}
|
||||
if areaDB.AreaLabelList == nil || len(areaDB.AreaLabelList) < 1 {
|
||||
return nil, false
|
||||
|
||||
}
|
||||
//校服务器ID是否在大区页签服务器范围内
|
||||
for _, item := range areaDB.AreaLabelList {
|
||||
if exist := item.CheckServerIdIsInLabelRange(groupId); exist {
|
||||
return item, true
|
||||
}
|
||||
}
|
||||
|
||||
//如果没找到,则返回空
|
||||
return nil, false
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package configYaml
|
||||
|
||||
// FunctionConfig
|
||||
//
|
||||
// @description: 功能开关配置
|
||||
type FunctionConfig struct {
|
||||
|
||||
// 游戏代码
|
||||
GameCode string
|
||||
|
||||
// 仙术副本 清理过期房间信息时间 5 分钟
|
||||
MagicCopyTeamOutTime int
|
||||
|
||||
// 请求青瓷的Url
|
||||
QCSdk_Url string
|
||||
|
||||
// 请求青瓷的GameCode
|
||||
QCSdk_GameCode string
|
||||
|
||||
// 请求青瓷的GameId
|
||||
QCSdk_GameId string
|
||||
|
||||
// 请求青瓷的加密signKey
|
||||
QCSdk_SignKey string
|
||||
}
|
||||
|
||||
var (
|
||||
// 功能开关配置对象
|
||||
functionConfigObj *FunctionConfig
|
||||
)
|
||||
|
||||
// initFunctionConfig
|
||||
//
|
||||
// @description: 加载功能开关配置
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @configObj: 开关配置
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @error: 错误信息
|
||||
func initFunctionConfig() error {
|
||||
functionConfigObj = &FunctionConfig{}
|
||||
|
||||
functionConfig := ConfigYaml.Root.FunctionConfig
|
||||
|
||||
functionConfigObj.GameCode = functionConfig.GameCode
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFunctionConfigObj
|
||||
//
|
||||
// @description: 获取功能开关配置对象
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
//
|
||||
// @*FunctionConfig:
|
||||
func GetFunctionConfigObj() *FunctionConfig {
|
||||
return functionConfigObj
|
||||
}
|
||||
Reference in New Issue
Block a user