You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
7.0 KiB
214 lines
7.0 KiB
package serviceGame |
|
|
|
import ( |
|
"context" |
|
"github.com/gogf/gf/v2/encoding/gjson" |
|
"github.com/gogf/gf/v2/frame/g" |
|
"log" |
|
"strings" |
|
"time" |
|
"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) |
|
ItemRecordTwo(ctx context.Context, req *game.ItemRecordTwoReq) (res *game.ItemRecordTwoRes, err error) |
|
ShopRecords(ctx context.Context, req *game.ShopRecordReq) (res *game.ShopRecordRes, 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) |
|
CheckFirstRebate(ctx context.Context, req *game.CheckFirstRebateReq) (res *game.CheckFirstRebateRes, err error) |
|
CheckSecondRebate(ctx context.Context, req *game.CheckSecondRebateReq) (res *game.CheckSecondRebateRes, 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) |
|
if req.Uid == -1 { |
|
res.Id, err = internal.GetUnitIdIncrease(ctx) |
|
return |
|
} |
|
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) ItemRecordTwo(ctx context.Context, req *game.ItemRecordTwoReq) (res *game.ItemRecordTwoRes, err error) { |
|
//ip := libUtils.GetClientIp(ctx) |
|
//fmt.Println("ip: ", ip) |
|
g.Try(ctx, func(ctx context.Context) { |
|
res = new(game.ItemRecordTwoRes) |
|
res, err = internal.ItemRecordsTwo(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) 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) |
|
} else if req.InitUnit == 3 { |
|
list := strings.Split(req.OpenId, ";") |
|
var data []interface{} |
|
for _, v := range list { |
|
data = append(data, v, 1) |
|
} |
|
err = internal.HMSetOpenId(ctx, data) |
|
} |
|
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 |
|
res.ActivityDbUrl = general[0].ActivityDbUrl |
|
res.ActivityDbName = general[0].ActivityDbName |
|
}) |
|
|
|
log.Println(err1) |
|
return |
|
} |
|
|
|
func (c *gamePubImpl) CheckFirstRebate(ctx context.Context, req *game.CheckFirstRebateReq) (res *game.CheckFirstRebateRes, err error) { |
|
res = new(game.CheckFirstRebateRes) |
|
_ = g.Try(ctx, func(ctx context.Context) { |
|
general := []entity.GameRecharge{} |
|
err = dao.GameRecharge.Ctx(ctx). |
|
Where(`UNIX_TIMESTAMP(createTime)>?`, time.Date(2025, 4, 19, 10, 0, 0, 0, time.Local).Unix()). |
|
Where(`UNIX_TIMESTAMP(createTime)<?`, time.Date(2025, 4, 20, 0, 0, 0, 0, time.Local).Unix()). |
|
Where(`tradeNo NOT LIKE 'GM%'`).Where(`status=2`).Where("unitId=?", req.Id).Where("server=?", req.ServerId).Scan(&general) |
|
if err != nil { |
|
log.Println("CheckFirstRebate data err", err) |
|
return |
|
} |
|
if len(general) == 0 { |
|
log.Println("CheckFirstRebate data nil", gjson.MustEncodeString(req)) |
|
return |
|
} |
|
|
|
for _, v := range general { |
|
res.Amount += v.Amount / 100 |
|
} |
|
|
|
log.Printf("CheckFirstRebate: unit: %s res %d", gjson.MustEncodeString(req), res.Amount) |
|
}) |
|
|
|
return |
|
} |
|
|
|
func (c *gamePubImpl) CheckSecondRebate(ctx context.Context, req *game.CheckSecondRebateReq) (res *game.CheckSecondRebateRes, err error) { |
|
res = new(game.CheckSecondRebateRes) |
|
_ = g.Try(ctx, func(ctx context.Context) { |
|
|
|
general := []entity.GameRecharge{} |
|
err = dao.GameRecharge.Ctx(ctx). |
|
Where(`UNIX_TIMESTAMP(createTime)>=?`, time.Date(2025, 4, 20, 0, 0, 0, 0, time.Local).Unix()). |
|
Where(`UNIX_TIMESTAMP(createTime)<?`, time.Date(2025, 4, 20, 17, 0, 0, 0, time.Local).Unix()). |
|
Where(`tradeNo NOT LIKE 'GM%'`).Where(`status=2`).Where("unitId=?", req.Id).Where("server=?", req.ServerId).Scan(&general) |
|
if err != nil { |
|
log.Println("CheckSecondRebateReq data err", err) |
|
return |
|
} |
|
if len(general) == 0 { |
|
log.Println("CheckSecondRebateReq data nil", gjson.MustEncodeString(req)) |
|
return |
|
} |
|
|
|
for _, v := range general { |
|
res.Amount += v.Amount / 100 |
|
} |
|
log.Printf("CheckSecondRebateReq: unit: %s res %d", gjson.MustEncodeString(req), res.Amount) |
|
}) |
|
|
|
return |
|
}
|
|
|