|
|
|
package serviceGame
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"log"
|
|
|
|
"tyj_admin/api/v1/game"
|
|
|
|
"tyj_admin/internal/dao"
|
|
|
|
"tyj_admin/internal/model/entity"
|
|
|
|
"tyj_admin/internal/serviceGame/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IGamePub interface {
|
|
|
|
GetId(ctx context.Context, req *game.GetOutIdReq) (res *game.GetOutIdRes, err error)
|
|
|
|
LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes, err error)
|
|
|
|
ItemRecord(ctx context.Context, req *game.ItemRecordReq) (res *game.ItemRecordRes, err error)
|
|
|
|
ShopRecords(ctx context.Context, req *game.ShopRecordReq) (res *game.ShopRecordRes, err error)
|
|
|
|
GetAuditMode(ctx context.Context, req *game.GetAuditModeReq) (res *game.GetAuditModeRes, err error)
|
|
|
|
SetOpenId(ctx context.Context, req *game.SetOpenIdReq) (res *game.SetOpenIdRes, err error)
|
|
|
|
GetOpenId(ctx context.Context, req *game.GetOpenIdReq) (res *game.GetOpenIdRes, err error)
|
|
|
|
GetServerConfig(ctx context.Context, req *game.GetServerConfigReq) (res *game.GetServerConfigRes, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type gamePubImpl struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
var gamePubService = gamePubImpl{}
|
|
|
|
|
|
|
|
func GamePub() IGamePub {
|
|
|
|
return &gamePubService
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) GetId(ctx context.Context, req *game.GetOutIdReq) (res *game.GetOutIdRes, err error) {
|
|
|
|
//ip := libUtils.GetClientIp(ctx)
|
|
|
|
//fmt.Println("ip: ", ip)
|
|
|
|
g.Try(ctx, func(ctx context.Context) {
|
|
|
|
res = new(game.GetOutIdRes)
|
|
|
|
res.Id, err = internal.GetIdToUid(ctx, req.Uid)
|
|
|
|
if res.Id > 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
res.Id, err = internal.GetIdIncrease(ctx)
|
|
|
|
internal.AddIdToUid(ctx, res.Id, req.Uid)
|
|
|
|
return
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes, err error) {
|
|
|
|
//ip := libUtils.GetClientIp(ctx)
|
|
|
|
//fmt.Println("ip: ", ip)
|
|
|
|
g.Try(ctx, func(ctx context.Context) {
|
|
|
|
res = new(game.LoginOutRes)
|
|
|
|
res, err = internal.LoginOut(ctx, req)
|
|
|
|
return
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) ItemRecord(ctx context.Context, req *game.ItemRecordReq) (res *game.ItemRecordRes, err error) {
|
|
|
|
//ip := libUtils.GetClientIp(ctx)
|
|
|
|
//fmt.Println("ip: ", ip)
|
|
|
|
g.Try(ctx, func(ctx context.Context) {
|
|
|
|
res = new(game.ItemRecordRes)
|
|
|
|
res, err = internal.ItemIncomeExpenseRecords(ctx, req)
|
|
|
|
return
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) ShopRecords(ctx context.Context, req *game.ShopRecordReq) (res *game.ShopRecordRes, err error) {
|
|
|
|
res, err = internal.ShopRecords(ctx, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) GetAuditMode(ctx context.Context, req *game.GetAuditModeReq) (res *game.GetAuditModeRes, err error) {
|
|
|
|
res = new(game.GetAuditModeRes)
|
|
|
|
|
|
|
|
//if 1 == internal.GetEnableHotfix(ctx, req.Channel) {
|
|
|
|
// res.AuditMode = 1
|
|
|
|
//}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) SetOpenId(ctx context.Context, req *game.SetOpenIdReq) (res *game.SetOpenIdRes, err error) {
|
|
|
|
res = new(game.SetOpenIdRes)
|
|
|
|
if req.InitUnit == 2 {
|
|
|
|
res, err = internal.SetOpenId(ctx, req)
|
|
|
|
} else if req.InitUnit == 1 {
|
|
|
|
internal.SetUid(ctx)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) GetOpenId(ctx context.Context, req *game.GetOpenIdReq) (res *game.GetOpenIdRes, err error) {
|
|
|
|
res = new(game.GetOpenIdRes)
|
|
|
|
res.State, err = internal.GetOpenId(ctx, req)
|
|
|
|
//res.State = 1
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *gamePubImpl) GetServerConfig(ctx context.Context, req *game.GetServerConfigReq) (res *game.GetServerConfigRes, err error) {
|
|
|
|
res = new(game.GetServerConfigRes)
|
|
|
|
err1 := g.Try(ctx, func(ctx context.Context) {
|
|
|
|
general := []entity.GameServerJsonGeneral{}
|
|
|
|
err := dao.GameServerJsonGeneral.Ctx(ctx).Where("id=?", 1).Scan(&general)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
loginUrl := []entity.GameLoginUrl{}
|
|
|
|
err = dao.GameLoginUrl.Ctx(ctx).Where("id=?", req.ServerId).Scan(&loginUrl)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(general) == 0 || len(loginUrl) == 0 {
|
|
|
|
log.Println("为查询到服务器配置!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Id = loginUrl[0].Id
|
|
|
|
res.GameDifficulty = loginUrl[0].Difficulty
|
|
|
|
res.CreateTime = loginUrl[0].CreateTime.Unix()
|
|
|
|
res.GameDbUrl = loginUrl[0].GameDbUrl
|
|
|
|
res.GameDbName = loginUrl[0].GameDbName
|
|
|
|
res.Platform = loginUrl[0].Platform
|
|
|
|
res.InnerIp = loginUrl[0].InnerIp
|
|
|
|
res.SdkAddress = general[0].SdkAddress
|
|
|
|
res.UniqueAddress = general[0].UniqueAddress
|
|
|
|
res.IdentityCheckAddress = general[0].IdentityCheckAddress
|
|
|
|
res.RechargeWhiteListIps = general[0].RechargeWhiteListIps
|
|
|
|
res.GmWhiteListUrl = general[0].GmWhiteListUrl
|
|
|
|
res.BackstageRechargeUrl = general[0].BackstageRechargeUrl
|
|
|
|
})
|
|
|
|
|
|
|
|
log.Println(err1)
|
|
|
|
return
|
|
|
|
}
|