@ -27,6 +27,7 @@ type IGameOrder interface {
ChangeCoin ( ctx context . Context , req * game . AddCoinReq ) ( res * game . AddCoinRes , err error )
Deposit ( ctx context . Context , req * game . OrderDepositReq ) ( res * game . OrderDepositRes , err error )
GetOrderLog ( ctx context . Context , req * game . OrderLogReq ) ( res * game . OrderLogRes , err error )
GetOrderLogPlatform ( ctx context . Context , req * game . OrderLogPlatformReq ) ( res * game . OrderLogPlatformRes , err error )
GetOrderBehavior ( ctx context . Context , req * game . OrderBehaviorReq ) ( res * game . OrderBehaviorRes , err error )
GetRechargePer ( ctx context . Context , req * game . RechargePerReq ) ( res * game . RechargePerRes , err error )
GameRechargeControl ( ctx context . Context , req * game . RechargeControlReq ) ( res * game . RechargeControlRes , err error )
@ -35,6 +36,9 @@ type IGameOrder interface {
DeleteRechargeControl ( ctx context . Context , req * game . DeleteRechargeControlReq ) ( res * game . DeleteRechargeControlRes , err error )
ChangeOrderState ( ctx context . Context , req * game . ChangeOrderStateReq ) ( res * game . ChangeOrderStateRes , err error )
GetGMOrderList ( ctx context . Context , req * game . GetGMOrderListReq ) ( res * game . GetGMOrderListRes , err error )
CheckRechargeSign ( ctx context . Context , req * game . CheckRechargeSignReq ) ( res * game . CheckRechargeSignRes , err error )
AddRechargeSign ( ctx context . Context , req * game . AddRechargeSignReq ) ( res * game . AddRechargeSignRes , err error )
ResetRechargeSign ( ctx context . Context , req * game . ResetRechargeSignReq ) ( res * game . ResetRechargeSignRes , err error )
}
type gameOrderImpl struct {
@ -289,8 +293,7 @@ func (o gameOrderImpl) GetOrderCount(ctx context.Context, req *game.OrderCountRe
}
res . Orders [ k ] . Uid = int32 ( uid )
}
data , _ := json . Marshal ( res . Orders )
log . Println ( "GetOrderCount 4 : " , string ( data ) )
log . Println ( "GetOrderCount 4 : " , gjson . MustEncodeString ( res . Orders ) )
return
}
@ -329,7 +332,7 @@ func (o gameOrderImpl) GetOrderLog(ctx context.Context, req *game.OrderLogReq) (
sql += fmt . Sprintf ( ` and r.server=%d ` , req . ServerId )
}
}
sql += fmt . Sprint ( " group by u.account" )
sql += fmt . Sprint ( " group by u.account,r.channel " )
amountSql := fmt . Sprintf ( ` select max(a.channel) as channel, sum(a.amount) as totalAmount from (%s) as a WHERE 1=1 ` , sql )
if req . RechargeMin > 0 {
@ -345,7 +348,41 @@ func (o gameOrderImpl) GetOrderLog(ctx context.Context, req *game.OrderLogReq) (
accountSql += " group by a.channel"
g . Model ( ) . Raw ( accountSql ) . Scan ( & res . RechargeAccountTotal )
log . Printf ( "GetOrderLog: %v, %v, %v" , res . AmountTotal , res . AccountTotal , res . RechargeAccountTotal )
log . Printf ( "GetOrderLog: %v, %v, %v" , gjson . MustEncodeString ( res . AmountTotal ) , gjson . MustEncodeString ( res . AccountTotal ) , gjson . MustEncodeString ( res . RechargeAccountTotal ) )
} )
return
}
func ( o gameOrderImpl ) GetOrderLogPlatform ( ctx context . Context , req * game . OrderLogPlatformReq ) ( res * game . OrderLogPlatformRes , err error ) {
res = new ( game . OrderLogPlatformRes )
g . Try ( ctx , func ( ctx context . Context ) {
var sql = fmt . Sprintf ( "select r.channel, sum(r.amount) as amount,u.account, r.platform from game_recharge as r inner join game_unit as u on u.uid=r.unitId where r.status=2 and r.tradeNo NOT LIKE 'GM%%' " )
if req . StartTime != 0 {
sql += fmt . Sprintf ( ` and UNIX_TIMESTAMP(r.createTime)>%d ` , req . StartTime / 1000 )
}
if req . EndTime != 0 {
sql += fmt . Sprintf ( ` and UNIX_TIMESTAMP(r.createTime)<%d ` , req . EndTime / 1000 )
}
if req . RechargeTotal > 0 {
sql = internal . CompareSqlType ( sql , req . RechargeTotal , "r.amount" , req . CompareType1 )
}
if req . Channel != "" {
sql += fmt . Sprintf ( ` and r.channel="%s" ` , req . Channel )
if req . ServerId != 0 {
sql += fmt . Sprintf ( ` and r.server=%d ` , req . ServerId )
}
}
sql += fmt . Sprint ( " group by u.account,r.channel,r.platform" )
amountSql := fmt . Sprintf ( ` select a.channel, sum(a.amount) as totalAmount, a.platform from (%s) as a WHERE 1=1 ` , sql )
if req . RechargeMin > 0 {
amountSql = internal . CompareSqlType ( amountSql , req . RechargeMin , "a.amount" , req . CompareType )
}
amountSql += " group by a.channel,a.platform"
g . Model ( ) . Raw ( amountSql ) . Scan ( & res . AmountTotal )
log . Printf ( "GetOrderLog: %v, %v, %v" , gjson . MustEncodeString ( res . AmountTotal ) , gjson . MustEncodeString ( res . AccountTotal ) , gjson . MustEncodeString ( res . RechargeAccountTotal ) )
} )
return
}
@ -373,7 +410,7 @@ FROM game_recharge AS r INNER JOIN (%s) AS c ON c.uid = r.unitId WHERE r.STATUS
GROUP BY a . channel , a . createTime ` , sql )
g . Model ( ) . Raw ( accountSql ) . Scan ( & res . RechargeAccount )
log . Printf ( "GetOrderBehavior: %v, %v, %v" , res . Account , res . RechargeAccount , res . AmountList )
log . Printf ( "GetOrderBehavior: %v, %v, %v" , gjson . MustEncodeString ( res . Account ) , gjson . MustEncodeString ( res . AmountList ) , gjson . MustEncodeString ( res . RechargeAccount ) )
} )
return
}
@ -394,7 +431,7 @@ func (o gameOrderImpl) GetRechargePer(ctx context.Context, req *game.RechargePer
from game_recharge as r inner join ( % s ) as c on c . uid = r . unitId where status = 2 and tradeNo NOT LIKE ' GM % % ' group by r . channel , c . createTime ` , sql )
g . Model ( ) . Raw ( accountSql ) . Scan ( & res . RechargeAccount )
log . Printf ( "GetOrderBehavior: %v, %v" , res . Account , res . RechargeAccount )
log . Printf ( "GetOrderBehavior: %v, %v" , gjson . MustEncodeString ( res . Account ) , gjson . MustEncodeString ( res . RechargeAccount ) )
} )
return
}
@ -481,3 +518,64 @@ func (o gameOrderImpl) GetGMOrderList(ctx context.Context, req *game.GetGMOrderL
err = model . Page ( req . PageNum , req . PageSize ) . Scan ( & res . List )
return
}
func ( o gameOrderImpl ) CheckRechargeSign ( ctx context . Context , req * game . CheckRechargeSignReq ) ( res * game . CheckRechargeSignRes , err error ) {
res = new ( game . CheckRechargeSignRes )
if req . Id == 0 || req . ServerId == 0 {
return res , errors . New ( "账号为空" )
}
list := [ ] entity . GameRechargeLevel { }
err = dao . GameRechargeLevel . Ctx ( ctx ) . Where ( "unitId=?" , req . Id ) . Where ( "server=?" , req . ServerId ) . Scan ( & list )
if err != nil {
log . Printf ( "CheckRechargeSign: %v, %v" , gjson . MustEncodeString ( res ) , err )
return res , err
}
for _ , v := range list {
res . List = append ( res . List , v . Config )
}
return
}
// http://192.168.2.100:4111/frontApi/game/setOrderLevel?unitId=1&server=1001&time=250726&token
func ( o gameOrderImpl ) AddRechargeSign ( ctx context . Context , req * game . AddRechargeSignReq ) ( res * game . AddRechargeSignRes , err error ) {
if req . Id == 0 || req . ServerId == 0 || req . Config == 0 || req . Time == 0 {
return nil , errors . New ( "参数为空" )
}
token := fmt . Sprintf ( "%x" , md5 . Sum ( [ ] byte ( "#colony" + fmt . Sprint ( req . Id ) + fmt . Sprint ( req . ServerId ) + fmt . Sprint ( req . Config ) + fmt . Sprint ( req . Time ) + "$" ) ) )
if req . Time != 250726 && req . Token != token {
log . Printf ( "[%s]AddRechargeSign failed, token error, md5: %s" , gjson . MustEncodeString ( req ) , token )
return nil , errors . New ( "token err" )
}
count , err := dao . GameRechargeLevel . Ctx ( ctx ) . Where ( "unitId=?" , req . Id ) . Where ( "server=?" , req . ServerId ) . Where ( "config=?" , req . Config ) . Count ( )
if err != nil {
log . Printf ( "req: %s, AddRechargeSign: err: %v" , gjson . MustEncodeString ( req ) , err )
return nil , err
}
if count > 0 {
log . Printf ( "req: %s, AddRechargeSign: count:%v" , gjson . MustEncodeString ( req ) , count )
return nil , errors . New ( "ok" )
}
_ , err = dao . GameRechargeLevel . Ctx ( ctx ) . Insert ( do . GameRechargeLevel { UnitId : req . Id , Server : req . ServerId , Config : req . Config } )
if err != nil {
log . Printf ( "req: %s, AddRechargeSign: %v, err: %v" , gjson . MustEncodeString ( req ) , gjson . MustEncodeString ( res ) , err )
return nil , err
}
return nil , errors . New ( "ok" )
}
func ( o gameOrderImpl ) ResetRechargeSign ( ctx context . Context , req * game . ResetRechargeSignReq ) ( res * game . ResetRechargeSignRes , err error ) {
result , err := dao . GameRechargeLevel . Ctx ( ctx ) . Where ( "1=1" ) . Delete ( )
if err != nil {
log . Printf ( "ResetRechargeSign: %v" , err )
return nil , err
}
rows , err := result . RowsAffected ( )
if err != nil {
log . Printf ( "ResetRechargeSign: %v" , err )
return nil , err
}
log . Printf ( "ResetRechargeSign: %v" , rows )
return
}