@ -2,6 +2,11 @@ package serviceGame
import (
import (
"context"
"context"
"fmt"
"github.com/gogf/gf/v2/encoding/gcharset"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"log"
"log"
"tyj_admin/api/v1/game"
"tyj_admin/api/v1/game"
"tyj_admin/internal/serviceGame/internal"
"tyj_admin/internal/serviceGame/internal"
@ -18,6 +23,7 @@ type IGameRank interface {
InsertAward ( ctx context . Context , req * game . InsertRankAwardReq ) ( res * game . InsertRankAwardRes , err error )
InsertAward ( ctx context . Context , req * game . InsertRankAwardReq ) ( res * game . InsertRankAwardRes , err error )
AddRankGroup ( ctx context . Context , req * game . AddRankGroupReq ) ( res * game . AddRankGroupRes , err error )
AddRankGroup ( ctx context . Context , req * game . AddRankGroupReq ) ( res * game . AddRankGroupRes , err error )
GetGameRank ( ctx context . Context , req * game . GetGameRankReq ) ( res * game . GetGameRankRes , err error )
GetGameRank ( ctx context . Context , req * game . GetGameRankReq ) ( res * game . GetGameRankRes , err error )
DeleteGameRank ( ctx context . Context , req * game . DeleteGameRankReq ) ( res * game . DeleteGameRankRes , err error )
}
}
type gameRankImpl struct {
type gameRankImpl struct {
@ -29,66 +35,94 @@ func GameRank() IGameRank {
return & gameRankService
return & gameRankService
}
}
func ( g * gameRankImpl ) GetAward ( ctx context . Context , req * game . GetRankAwardReq ) ( res * game . GetRankAwardRes , err error ) {
func ( r * gameRankImpl ) GetAward ( ctx context . Context , req * game . GetRankAwardReq ) ( res * game . GetRankAwardRes , err error ) {
res = new ( game . GetRankAwardRes )
res = new ( game . GetRankAwardRes )
res . RankAward , err = internal . GetRankAward ( ctx , req . Id , req . Type )
res . RankAward , err = internal . GetRankAward ( ctx , req . Id , req . Type )
log . Print ( "GetRankAward " , res )
log . Print ( "GetRankAward " , res )
return
return
}
}
func ( g * gameRankImpl ) UpdateAward ( ctx context . Context , req * game . UpdateRankAwardReq ) ( res * game . UpdateRankAwardRes , err error ) {
func ( r * gameRankImpl ) UpdateAward ( ctx context . Context , req * game . UpdateRankAwardReq ) ( res * game . UpdateRankAwardRes , err error ) {
err = internal . UpdateRankAward ( ctx , req . RankAward )
err = internal . UpdateRankAward ( ctx , req . RankAward )
log . Print ( "UpdateRankAward" , err )
log . Print ( "UpdateRankAward" , err )
return
return
}
}
func ( g * gameRankImpl ) InsertAward ( ctx context . Context , req * game . InsertRankAwardReq ) ( res * game . InsertRankAwardRes , err error ) {
func ( r * gameRankImpl ) InsertAward ( ctx context . Context , req * game . InsertRankAwardReq ) ( res * game . InsertRankAwardRes , err error ) {
err = internal . InsertRankAward ( ctx , req . RankAward )
err = internal . InsertRankAward ( ctx , req . RankAward )
log . Print ( "InsertRankAward" , err )
log . Print ( "InsertRankAward" , err )
return
return
}
}
func ( g * gameRankImpl ) Get ( ctx context . Context , req * game . GetRankReq ) ( res * game . GetRankRes , err error ) {
func ( r * gameRankImpl ) Get ( ctx context . Context , req * game . GetRankReq ) ( res * game . GetRankRes , err error ) {
res , err = internal . GetRank ( ctx , req )
res , err = internal . GetRank ( ctx , req )
log . Print ( "GetRankAward " , res )
log . Print ( "GetRankAward " , res )
return
return
}
}
func ( g * gameRankImpl ) Update ( ctx context . Context , req * game . UpdateRankReq ) ( res * game . UpdateRankRes , err error ) {
func ( r * gameRankImpl ) Update ( ctx context . Context , req * game . UpdateRankReq ) ( res * game . UpdateRankRes , err error ) {
err = internal . UpdateRank ( ctx , req . Rank )
err = internal . UpdateRank ( ctx , req . Rank )
log . Print ( "UpdateRankAward" , err )
log . Print ( "UpdateRankAward" , err )
return
return
}
}
func ( g * gameRankImpl ) Insert ( ctx context . Context , req * game . InsertRankReq ) ( res * game . InsertRankRes , err error ) {
func ( r * gameRankImpl ) Insert ( ctx context . Context , req * game . InsertRankReq ) ( res * game . InsertRankRes , err error ) {
err = internal . InsertRank ( ctx , req . Rank )
err = internal . InsertRank ( ctx , req . Rank )
log . Print ( "InsertRank" , err )
log . Print ( "InsertRank" , err )
return
return
}
}
func ( g * gameRankImpl ) Del ( ctx context . Context , req * game . DelRankReq ) ( res * game . DelRankRes , err error ) {
func ( r * gameRankImpl ) Del ( ctx context . Context , req * game . DelRankReq ) ( res * game . DelRankRes , err error ) {
err = internal . DelRank ( ctx , req . Rank )
err = internal . DelRank ( ctx , req . Rank )
log . Print ( "InsertRank" , err )
log . Print ( "InsertRank" , err )
return
return
}
}
func ( g * gameRankImpl ) Check ( ctx context . Context , req * game . CheckRankReq ) ( res * game . CheckRankRes , err error ) {
func ( r * gameRankImpl ) Check ( ctx context . Context , req * game . CheckRankReq ) ( res * game . CheckRankRes , err error ) {
res = new ( game . CheckRankRes )
res = new ( game . CheckRankRes )
res . Rank , res . StringId , err = internal . CheckRank ( ctx , req . Rank )
res . Rank , res . StringId , err = internal . CheckRank ( ctx , req . Rank )
log . Print ( "InsertRank" , err )
log . Print ( "InsertRank" , err )
return
return
}
}
func ( g * gameRankImpl ) AddRankGroup ( ctx context . Context , req * game . AddRankGroupReq ) ( res * game . AddRankGroupRes , err error ) {
func ( r * gameRankImpl ) AddRankGroup ( ctx context . Context , req * game . AddRankGroupReq ) ( res * game . AddRankGroupRes , err error ) {
res = new ( game . AddRankGroupRes )
res = new ( game . AddRankGroupRes )
res , err = internal . AddRankGroup ( ctx , req )
res , err = internal . AddRankGroup ( ctx , req )
log . Print ( "InsertRank" , err )
log . Print ( "InsertRank" , err )
return
return
}
}
func ( g * gameRankImpl ) GetGameRank ( ctx context . Context , req * game . GetGameRankReq ) ( res * game . GetGameRankRes , err error ) {
func ( r * gameRankImpl ) GetGameRank ( ctx context . Context , req * game . GetGameRankReq ) ( res * game . GetGameRankRes , err error ) {
res = new ( game . GetGameRankRes )
res = new ( game . GetGameRankRes )
res , err = internal . GetGameRank ( ctx , req )
res , err = internal . GetGameRank ( ctx , req )
log . Print ( "GetGameRank" , err )
log . Print ( "GetGameRank" , err )
return
return
}
}
func ( r * gameRankImpl ) DeleteGameRank ( ctx context . Context , req * game . DeleteGameRankReq ) ( res * game . DeleteGameRankRes , err error ) {
res = new ( game . DeleteGameRankRes )
ip := internal . ServerConfig [ fmt . Sprint ( req . ServerId ) ]
url := "http://" + ip + "/deleteRank?unitId="
uid , _ := internal . GetIdToUid ( ctx , req . Uid )
url += fmt . Sprint ( uid )
bytes := g . Client ( ) . GetBytes ( ctx , url )
fmt . Println ( "DeleteGameRank: " , url )
src := string ( bytes )
if g . IsEmpty ( src ) {
g . Log ( ) . Printf ( ctx , "%d DeleteGameRank: gerror.New(\"空回调,发送失败\")" , req . ServerId )
return res , nil
}
srcCharset := "UTF-8"
tmp , _ := gcharset . ToUTF8 ( srcCharset , src )
fmt . Println ( "DeleteGameRank: " , tmp )
json , err := gjson . DecodeToJson ( tmp )
if err != nil {
return
}
fmt . Println ( "DeleteGameRank: " , gjson . MustEncodeString ( json ) )
if json . Get ( "Error" ) . Int ( ) == 200 {
return nil , gerror . New ( json . Get ( "Message" ) . String ( ) )
}
return
}