package internal
import (
"context"
"database/sql"
"encoding/json"
"errors"
"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"
"github.com/gogf/gf/v2/os/gtime"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"log"
"strconv"
"strings"
"time"
"tyj_admin/api/v1/game"
"tyj_admin/internal/consts"
"tyj_admin/internal/dao"
"tyj_admin/internal/model/do"
"tyj_admin/internal/model/entity"
"tyj_admin/internal/service"
"tyj_admin/library/libUtils"
"tyj_admin/library/liberr"
)
func LogInit ( ) {
for k , sv := range ServerConfig {
go loadServeronline ( k , sv )
}
return
}
func loadServeronline ( k , sv string ) {
ctx := context . TODO ( )
model := dao . LoginOutLog . Ctx ( ctx )
srcCharset := "UTF-8"
ids := [ ] int64 { }
url := "http://" + sv + "/GetOnline"
g . Client ( ) . SetHeader ( "Content-Type" , "application/json;charset=UTF-8" )
bytes := g . Client ( ) . GetBytes ( ctx , url )
src := string ( bytes )
if g . IsEmpty ( src ) {
g . Log ( ) . Info ( ctx , " GetOnline === return nil " , sv )
return
}
tmp , _ := gcharset . ToUTF8 ( srcCharset , src )
json , err := gjson . DecodeToJson ( tmp )
if err != nil {
g . Log ( ) . Info ( ctx , " GetOnline === DecodeToJson err " , sv , err . Error ( ) )
return
}
g . Log ( ) . Info ( ctx , " GetOnline === " , sv , json )
if json . Get ( "Error" ) . Int ( ) == 200 {
accounts := json . Get ( "Accounts" ) . Array ( )
g . Log ( ) . Info ( ctx , " InitMysql === " , accounts )
for _ , v := range accounts {
account := v . ( string )
uv1 , _ := strconv . ParseInt ( account , 0 , 64 )
ids = append ( ids , uv1 )
}
g . Log ( ) . Info ( ctx , " InitMysql ids=== " , ids )
}
if len ( ids ) > 0 {
model = model . WhereNotIn ( "uid" , ids )
}
id , err := strconv . Atoi ( k )
model . Where ( "server=?" , id ) . Where ( "e_date=?" , 0 ) . Update ( "e_date=c_date" )
g . Log ( ) . Info ( ctx , "a== " , ids )
}
func GetRoleList ( ctx context . Context , req * game . RoleSearchReq ) ( res * game . RoleSearchRes , err error ) {
query := bson . M { "_t" : "Unit" }
if req . Id != "" {
query [ "_id" ] , _ = strconv . ParseInt ( req . Id , 10 , 64 )
}
if req . ServerId == 0 {
return
}
if req . Account != "" {
query [ "_id" ] , err = GetAccountUid2 ( ctx , req . Account , fmt . Sprint ( req . ServerId ) )
if err != nil {
return
}
}
if req . Uid != 0 {
query [ "UniqueId" ] = req . Uid
}
fmt . Println ( "GetRoleList: query " , query )
res = new ( game . RoleSearchRes )
mongo , ok := MongoDatabaseList [ fmt . Sprint ( req . ServerId ) ]
if ! ok {
return
}
res . Total , err = mongo . Collection ( "Unit" ) . Find ( ctx , query ) . Count ( )
err = mongo . Collection ( "Unit" ) . Find ( ctx , query ) . Skip ( ( req . PageNum - 1 ) * req . PageSize ) . Limit ( req . PageSize ) . All ( & res . RoleList )
for _ , v := range res . RoleList {
v [ "StringId" ] = fmt . Sprint ( v [ "_id" ] )
if _ , ok := v [ "C" ] ; ok {
c1 := v [ "C" ] . ( primitive . A )
for _ , c2 := range c1 {
c22 := c2 . ( map [ string ] interface { } )
c22 [ "StringId" ] = fmt . Sprint ( c22 [ "_id" ] )
if _ , ok := c22 [ "Children" ] ; ok {
children , _ := c22 [ "Children" ] . ( primitive . A )
for _ , c := range children {
cc1 := c . ( map [ string ] interface { } )
cc1 [ "StringId" ] = fmt . Sprint ( cc1 [ "_id" ] )
if _ , ok := cc1 [ "C" ] ; ok {
cc := cc1 [ "C" ] . ( primitive . A )
for _ , cK := range cc {
cK1 := cK . ( map [ string ] interface { } )
cK1 [ "StringId" ] = fmt . Sprint ( cK1 [ "_id" ] )
if _ , ok := cK1 [ "SlotDic" ] ; ok {
cKs := cK1 [ "SlotDic" ] . ( primitive . A )
cK1 [ "SlotDic" ] = cKs
for k , cKsv := range cKs {
cKsv1 := cKsv . ( primitive . A )
cKs [ k ] = append ( cKsv1 , fmt . Sprint ( cKsv1 [ 1 ] ) )
}
}
if _ , ok := cK1 [ "Children" ] ; ok {
cKs := cK1 [ "Children" ] . ( primitive . A )
cK1 [ "Children" ] = cKs
for _ , cKsv := range cKs {
cKsv1 := cKsv . ( map [ string ] interface { } )
cKsv1 [ "StringId" ] = fmt . Sprint ( cKsv1 [ "_id" ] )
}
}
if _ , ok := cK1 [ "Mates" ] ; ok {
cKs := cK1 [ "Mates" ] . ( primitive . A )
cK1 [ "Mates" ] = cKs
for k , cKsv := range cKs {
cKs [ k ] = fmt . Sprint ( cKsv )
}
}
if _ , ok := cK1 [ "MyChildren" ] ; ok {
cKs := cK1 [ "MyChildren" ] . ( primitive . A )
cK1 [ "MyChildren" ] = cKs
for k , cKsv := range cKs {
cKs [ k ] = fmt . Sprint ( cKsv )
}
}
if _ , ok := cK1 [ "Parents" ] ; ok {
cKs := cK1 [ "Parents" ] . ( primitive . A )
cK1 [ "Parents" ] = cKs
for k , cKsv := range cKs {
cKs [ k ] = fmt . Sprint ( cKsv )
}
}
}
}
}
}
}
}
}
if err != nil {
return
}
return res , err
}
func DelRole ( ctx context . Context , uid int64 , server string ) ( roleDetail map [ string ] interface { } , err error ) {
err = MongoDatabaseList [ server ] . Collection ( "Unit" ) . RemoveId ( ctx , uid )
return roleDetail , err
}
func DelAccount ( ctx context . Context , uid int64 , server string ) ( roleDetail map [ string ] interface { } , err error ) {
err = MongoDatabaseList [ server ] . Collection ( "Account" ) . RemoveId ( ctx , uid )
return roleDetail , err
}
func DelFriendUnit ( ctx context . Context , uid int64 , server string ) ( roleDetail map [ string ] interface { } , err error ) {
err = MongoDatabaseList [ server ] . Collection ( "FriendUnit" ) . RemoveId ( ctx , uid )
return roleDetail , err
}
func DelBaseInfo ( ctx context . Context , uid int64 , server string ) ( roleDetail map [ string ] interface { } , err error ) {
err = MongoDatabaseList [ server ] . Collection ( "BaseInfo" ) . RemoveId ( ctx , uid )
return roleDetail , err
}
func DelBazaar ( ctx context . Context , uid int64 , server string ) ( roleDetail map [ string ] interface { } , err error ) {
err = MongoDatabaseList [ server ] . Collection ( "Bazaar" ) . RemoveId ( ctx , uid )
return roleDetail , err
}
func GetUnitByUid ( ctx context . Context , uid int64 , serverId int ) ( unit * entity . GameUnit , err error ) {
srcId , err1 := GetIdToUid ( ctx , uid )
if err1 != nil {
g . Log ( ) . Error ( ctx , "GetUnit 获取账号ID err : " , err1 )
return nil , err1
}
if g . IsEmpty ( srcId ) {
g . Log ( ) . Error ( ctx , "GetUnit 账号ID不存在 : " , fmt . Sprint ( srcId ) + "-" + fmt . Sprint ( uid ) )
return nil , gerror . New ( "IDIsNull" )
}
units := [ ] entity . GameUnit { }
err = dao . GameUnit . Ctx ( ctx ) . Where ( "uid=?" , srcId ) . Scan ( & units )
if err != nil {
g . Log ( ) . Error ( ctx , "GetUnit scan 1 : " , srcId , gjson . MustEncodeString ( units ) )
return nil , err
}
if len ( units ) == 0 {
g . Log ( ) . Errorf ( ctx , "[%d]GetUnit unit is null, %s" , srcId , gjson . MustEncodeString ( units ) )
return nil , errors . New ( "UnitIsNull" )
}
serverList := ""
for _ , v := range units {
if v . Server == serverId {
return & v , err
}
serverList += fmt . Sprint ( v . Server ) + ";"
}
if len ( units ) > 1 {
return nil , errors . New ( "查询失败,包含多个用户,区服在:" + serverList )
}
return & units [ 0 ] , err
}
func GetUnitByStringUid ( ctx context . Context , uid string , serverId int ) ( unit * entity . GameUnit , err error ) {
srcId , err1 := GetStringIdToUid ( ctx , uid )
if err1 != nil {
g . Log ( ) . Error ( ctx , "GetUnit 获取账号ID err : " , err1 )
return nil , err1
}
if g . IsEmpty ( srcId ) {
g . Log ( ) . Error ( ctx , "GetUnit 账号ID不存在 : " , fmt . Sprint ( srcId ) + "-" + fmt . Sprint ( uid ) )
return nil , gerror . New ( "IDIsNull" )
}
units := [ ] entity . GameUnit { }
err = dao . GameUnit . Ctx ( ctx ) . Where ( "uid=?" , srcId ) . Scan ( & units )
if err != nil {
g . Log ( ) . Error ( ctx , "GetUnit scan 1 : " , srcId , gjson . MustEncodeString ( units ) )
return nil , err
}
if len ( units ) == 0 {
g . Log ( ) . Errorf ( ctx , "[%d]GetUnit unit is null, %s" , srcId , gjson . MustEncodeString ( units ) )
return nil , errors . New ( "UnitIsNull" )
}
serverList := ""
for _ , v := range units {
if v . Server == serverId {
return & v , err
}
serverList += fmt . Sprint ( v . Server ) + ";"
}
if len ( units ) > 1 {
return nil , errors . New ( "查询失败,包含多个用户,区服在:" + serverList )
}
return & units [ 0 ] , err
}
func GetUnitById ( ctx context . Context , srcId int64 , serverId int ) ( unit * entity . GameUnit , err error ) {
if g . IsEmpty ( srcId ) {
g . Log ( ) . Error ( ctx , "GetAccount 账号ID不存在 : " , fmt . Sprint ( srcId ) )
return nil , gerror . New ( "IDIsNull" )
}
units := [ ] entity . GameUnit { }
err = dao . GameUnit . Ctx ( ctx ) . Where ( "uid=?" , srcId ) . Scan ( & units )
if err != nil {
g . Log ( ) . Error ( ctx , "GetAccount scan 1 : " , srcId , gjson . MustEncodeString ( units ) )
return nil , err
}
if len ( units ) == 0 {
g . Log ( ) . Errorf ( ctx , "[%d]GetAccount unit is null, %s" , srcId , gjson . MustEncodeString ( units ) )
return nil , errors . New ( "UnitIsNull" )
}
serverList := ""
for _ , v := range units {
if v . Server == serverId {
return & v , err
}
}
if len ( units ) > 1 {
return nil , errors . New ( "查询失败,包含多个用户,区服在:" + serverList )
}
return & units [ 0 ] , err
}
func GetAccount ( ctx context . Context , req * game . AccountReq ) ( res * game . AccountRes , err error ) {
query := bson . M { }
server := fmt . Sprint ( req . ServerId )
if req . Id != "" {
id , _ := strconv . ParseInt ( req . Id , 10 , 64 )
unit , err1 := GetUnitById ( ctx , id , req . ServerId )
if err1 != nil {
err = err1
g . Log ( ) . Error ( ctx , "GetUnit:" , err1 )
return
}
query [ "_id" ] = unit . Uid
if server != fmt . Sprint ( unit . Server ) {
var serverInfo entity . GameLoginUrl
for _ , v := range ServerList {
if v . Id == unit . Server {
serverInfo = v
break
}
}
return nil , errors . New ( "区服选择错误!当前id在<" + fmt . Sprint ( serverInfo . Id ) + "><" + serverInfo . Name + ">区" )
}
}
if req . Uid != 0 {
unit , err1 := GetUnitByUid ( ctx , int64 ( req . Uid ) , req . ServerId )
if err1 != nil {
err = err1
g . Log ( ) . Error ( ctx , "GetUnit:" , err1 )
return
}
query [ "_id" ] = unit . Uid
if server != fmt . Sprint ( unit . Server ) {
var serverInfo entity . GameLoginUrl
for _ , v := range ServerList {
if v . Id == unit . Server {
serverInfo = v
break
}
}
return nil , errors . New ( "区服选择错误!当前区服在<" + fmt . Sprint ( serverInfo . Id ) + "><" + serverInfo . Name + ">区" )
}
}
if req . Account != "" {
query [ "AccountName" ] = req . Account
}
if req . Ident != "" {
query [ "Identity" ] = req . Ident
}
if req . Name != "" {
query [ "RealName" ] = req . Name
}
if req . Name != "" {
query [ "RealName" ] = req . Name
}
if req . GmState != "" {
gm , _ := strconv . Atoi ( req . GmState )
query [ "AccountType" ] = gm
}
mongo , ok := MongoDatabaseList [ server ]
if ! ok {
return nil , errors . New ( "不存在数据库!" )
}
res = new ( game . AccountRes )
res . Total , err = mongo . Collection ( "Account" ) . Find ( ctx , query ) . Count ( )
err = mongo . Collection ( "Account" ) . Find ( ctx , query ) . Skip ( ( req . PageNum - 1 ) * req . PageSize ) . Limit ( req . PageSize ) . All ( & res . Accounts )
for _ , v := range res . Accounts {
v [ "StringId" ] = fmt . Sprint ( v [ "_id" ] )
v [ "uid" ] , _ = GetIdToUid ( ctx , v [ "_id" ] . ( int64 ) )
}
if err != nil {
return
}
return res , err
}
func GetAccountUidBy ( ctx context . Context , req * game . AccountReq , server string ) ( uid int64 , err error ) {
query := bson . M { }
if req . Id != "" {
query [ "_id" ] , _ = strconv . ParseInt ( req . Id , 10 , 64 )
}
if req . Uid != 0 {
query [ "UniqueId" ] , _ = GetIdToUid ( ctx , int64 ( req . Uid ) )
}
if req . Account != "" {
query [ "AccountName" ] = req . Account
}
if req . Ident != "" {
query [ "Identity" ] = req . Ident
}
if req . Name != "" {
query [ "RealName" ] = req . Name
}
all1 := make ( [ ] map [ string ] interface { } , 1 )
err = MongoDatabaseList [ server ] . Collection ( "Account" ) . Find ( ctx , query ) . All ( & all1 )
if len ( all1 ) == 0 {
return 0 , gerror . New ( "获取失败" )
}
uid = all1 [ 0 ] [ "_id" ] . ( int64 )
return uid , err
}
func GetAccountByUid ( ctx context . Context , uid int64 , server string ) ( account map [ string ] interface { } , err error ) {
filtter := bson . M { }
if uid != 0 {
filtter [ "_id" ] = uid
}
log . Println ( "GetAccountByUid: " , filtter )
all1 := make ( [ ] map [ string ] interface { } , 1 )
mongo , ok := MongoDatabaseList [ server ]
if ! ok {
log . Println ( "GetAccountUid: 获取失败 " , all1 , err )
return account , gerror . New ( "获取失败" )
}
err = mongo . Collection ( "Account" ) . Find ( ctx , filtter ) . All ( & all1 )
if err != nil || len ( all1 ) == 0 {
log . Println ( "GetAccountUid: 获取失败 " , all1 , err )
return account , gerror . New ( "获取失败" )
}
account = all1 [ 0 ]
log . Println ( "GetAccountByUid: accountData " , account )
return account , err
}
func GetAccountUid ( ctx context . Context , account string , server string ) ( uid int , err error ) {
filtter := bson . M { }
if len ( account ) > 0 {
filtter [ "AccountName" ] = account
}
log . Println ( "GetAccountUid: " , filtter )
all1 := make ( [ ] map [ string ] interface { } , 1 )
err = MongoDatabaseList [ server ] . Collection ( "Account" ) . Find ( ctx , filtter ) . All ( & all1 )
if len ( all1 ) == 0 {
return 0 , gerror . New ( "获取失败" )
}
log . Println ( "GetAccountUid: all" , all1 , all1 [ 0 ] )
uid = all1 [ 0 ] [ "UniqueId" ] . ( int )
log . Println ( "GetAccountUid: accountData " , uid )
return uid , err
}
func AccountToUids ( ctx context . Context , account string ) ( uid [ ] int64 , err error ) {
log . Println ( "GetAccountUid: " , account )
var all1 [ ] * entity . Account
err = dao . GameUnit . Ctx ( ctx ) . Where ( "account=?" , account ) . Scan ( & all1 )
if len ( all1 ) == 0 {
return [ ] int64 { } , gerror . New ( "获取失败" )
}
log . Println ( "GetAccountUid: all" , all1 )
uid = [ ] int64 { }
for _ , e := range all1 {
uid = append ( uid , e . Uid )
}
log . Println ( "GetAccountUid: accountData " , uid )
return uid , err
}
func UidToServer ( ctx context . Context , unitId string ) ( server int , err error ) {
log . Println ( "GetAccountUid: " , unitId )
var all1 [ ] * entity . GameUnit
err = dao . GameUnit . Ctx ( ctx ) . Where ( "uid=?" , unitId ) . Scan ( & all1 )
if len ( all1 ) == 0 {
return 0 , gerror . New ( "获取失败" )
}
log . Println ( "GetAccountUid: all" , gjson . MustEncodeString ( all1 ) )
return all1 [ 0 ] . Server , err
}
func GetAccountUid2 ( ctx context . Context , account string , server string ) ( uid int64 , err error ) {
filtter := bson . M { }
if len ( account ) > 0 {
filtter [ "AccountName" ] = account
}
log . Println ( "GetAccountUid: " , filtter )
all1 := make ( [ ] map [ string ] interface { } , 1 )
err = MongoDatabaseList [ server ] . Collection ( "Account" ) . Find ( ctx , filtter ) . All ( & all1 )
if len ( all1 ) == 0 {
return 0 , gerror . New ( "获取失败" )
}
log . Println ( "GetAccountUid: all" , all1 , all1 [ 0 ] )
uid = all1 [ 0 ] [ "_id" ] . ( int64 )
log . Println ( "GetAccountUid: accountData " , uid )
return uid , err
}
func GetAccountIdentity ( ctx context . Context , account string , server string ) ( Identity string , err error ) {
filtter := bson . M { }
if len ( account ) > 0 {
filtter [ "AccountName" ] = account
}
log . Println ( "GetAccountUid: " , filtter )
all1 := make ( [ ] map [ string ] interface { } , 1 )
err = MongoDatabaseList [ server ] . Collection ( "Account" ) . Find ( ctx , filtter ) . All ( & all1 )
log . Println ( "GetAccountUid: all" , all1 , all1 [ 0 ] )
Identity = all1 [ 0 ] [ "Identity" ] . ( string )
log . Println ( "GetAccountUid: accountData " , Identity )
return Identity , err
}
type GameUnitGameTime struct {
Id int64 ` json:"id" description:"" `
Account string ` json:"account" description:"账号" `
Channel string ` json:"channel" description:"渠道" `
Uid int64 ` json:"uid" description:"账号Id" `
Server int ` json:"server" description:"区服" `
Scale int ` json:"scale" description:"规模" `
Name string ` json:"name" description:"桃谷名称" `
LogTime int64 ` json:"logTime" description:"" `
CreateTime * gtime . Time ` json:"createTime" description:"账号创建时间" `
VillagerNum int ` json:"villagerNum" description:"村民数量" `
Prosperity int ` json:"prosperity" description:"繁荣值" `
GoldIngot int ` json:"goldIngot" description:"桃花石" `
BaseFood int ` json:"baseFood" description:"基础食物" `
Day int ` json:"day" description:"游戏天数" `
GameTime int ` json:"game_time" description:"游戏时间" `
Recharge int64 ` json:"recharge" description:"充值" `
}
func SearchAccount ( ctx context . Context , req * game . SearchAccountReq ) ( res * game . SearchAccountRes , err error ) {
res = new ( game . SearchAccountRes )
model := dao . GameUnit . Ctx ( ctx )
switch req . Type {
case 1 :
{
model = checkDaoIntCompareType ( model , req . CompareType , "day" , req . Data )
break
}
case 2 :
{
model = checkDaoIntCompareType ( model , req . CompareType , "scale" , req . Data )
break
}
case 3 :
{
sql := fmt . Sprintf ( ` select uid, max(game_time) as game_time, max(day) as day from login_logout_info group by uid ` )
sql = fmt . Sprintf ( ` select u.day,u.scale,u.villager_num,u.account,u.uid, b.game_time as game_time, b.day as mDay from (%s) as b inner join game_unit as u on u.uid=b.uid where 1=1 ` , sql )
if req . ServerId > 0 {
sql += fmt . Sprintf ( " and u.server=%d" , req . ServerId )
}
if req . StartTime != 0 {
sql += fmt . Sprintf ( " and UNIX_TIMESTAMP(u.create_time)>%d" , req . StartTime / 1000 )
}
if req . EndTime != 0 {
sql += fmt . Sprintf ( " and UNIX_TIMESTAMP(u.create_time)<%d" , req . EndTime / 1000 )
}
sql = fmt . Sprintf ( ` select a.game_time,a.day,a.scale,a.villager_num,a.account,a.uid from (%s) as a where a.day=1 %s ` , sql , CompareSqlType ( "" , req . Data , "a.game_time" , req . CompareType ) )
dayAvgDetail := [ ] * Avg { }
scaleAvgDetail := [ ] * Avg { }
daysql := fmt . Sprintf ( ` select avg(c.day) as data from (%s) as c ` , sql )
g . Model ( ) . Raw ( daysql ) . Scan ( & dayAvgDetail )
scalesql := fmt . Sprintf ( ` select avg(c.scale) as data from (%s) as c ` , sql )
g . Model ( ) . Raw ( scalesql ) . Scan ( & scaleAvgDetail )
countsql := fmt . Sprintf ( ` select count(1) as data from (%s) as d ` , sql )
count := [ ] * Count { }
g . Model ( ) . Raw ( countsql ) . Scan ( & count )
if len ( count ) > 0 {
res . Total = count [ 0 ] . Data
}
res . AvgScale = scaleAvgDetail [ 0 ] . Data
res . AvgDay = dayAvgDetail [ 0 ] . Data
accountSql := fmt . Sprintf ( ` select d.uid,d.account,d.day, d.scale,d.villager_num, d.game_time from (%s) as d LIMIT %d,%d ` , sql , ( req . PageNum - 1 ) * req . PageSize , req . PageSize )
accounts := [ ] * GameUnitGameTime { }
g . Model ( ) . Raw ( accountSql ) . Scan ( & accounts )
for _ , v := range accounts {
res . Accounts = append ( res . Accounts , map [ string ] interface { } { "stringId" : fmt . Sprint ( v . Uid ) , "game_time" : v . GameTime , "account" : v . Account , "scale" : v . Scale , "day" : v . Day , "villagerNum" : v . VillagerNum } )
}
fmt . Println ( "SearchAccount: " , res . Total , fmt . Sprint ( dayAvgDetail [ 0 ] . Data ) , fmt . Sprint ( scaleAvgDetail [ 0 ] . Data ) )
return
}
default :
return res , gerror . New ( "无查询条件" )
}
if req . ServerId > 0 {
model = model . Where ( "server=?" , req . ServerId )
}
if req . StartTime != 0 {
model = model . Where ( ` UNIX_TIMESTAMP(create_time)>? ` , req . StartTime / 1000 )
}
if req . EndTime != 0 {
model = model . Where ( ` UNIX_TIMESTAMP(create_time)<? ` , req . EndTime / 1000 )
}
dayAvgDetail := [ ] * Avg { }
scaleAvgDetail := [ ] * Avg { }
err = model . FieldAvg ( "day" , "data" ) . Scan ( & dayAvgDetail )
err = model . FieldAvg ( "scale" , "data" ) . Scan ( & scaleAvgDetail )
res . Total , err = model . Count ( )
if err != nil {
return res , err
}
res . AvgScale = scaleAvgDetail [ 0 ] . Data
res . AvgDay = dayAvgDetail [ 0 ] . Data
accounts := [ ] * entity . GameUnit { }
err = model . Page ( req . PageNum , req . PageSize ) . Scan ( & accounts )
for _ , v := range accounts {
res . Accounts = append ( res . Accounts , map [ string ] interface { } { "stringId" : fmt . Sprint ( v . Uid ) , "account" : v . Account , "scale" : v . Scale , "day" : v . Day , "villagerNum" : v . VillagerNum } )
}
fmt . Println ( "SearchAccount: " , res . Total , fmt . Sprint ( dayAvgDetail [ 0 ] . Data ) , fmt . Sprint ( scaleAvgDetail [ 0 ] . Data ) )
return
}
type Avg struct {
Data float64 ` json:"data" bson:"data" `
}
type Count struct {
Data int ` json:"data" bson:"data" `
}
func GetLoginOut ( ctx context . Context , req * game . GetLoginOutReq ) ( res * game . GetLoginOutRes , err error ) {
res = new ( game . GetLoginOutRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . LoginLogoutInfo . Ctx ( ctx )
if req . Account != "" {
uid , _ := GetAccountUid2 ( ctx , req . Account , fmt . Sprint ( req . ServerId ) )
if uid == 0 {
//g.Log().Debugf(ctx, "LoginOut -> "+fmt.Sprint(uid))
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
} else if req . Uid != "" {
uid , _ := strconv . ParseInt ( req . Uid , 10 , 64 )
if uid == 0 {
//g.Log().Debugf(ctx, "LoginOut -> "+fmt.Sprint(uid))
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
}
if req . State != 0 {
model = model . Where ( "state=? " , req . State )
}
res . Total , err = model . Count ( )
err = model . Page ( req . PageNum , req . PageSize ) . OrderDesc ( "c_date" ) . Scan ( & res . Logs )
if err != nil {
return
}
return
} )
return
}
func GetLoginOutLog ( ctx context . Context , req * game . GetLoginOutLogReq ) ( res * game . GetLoginOutLogRes , err error ) {
res = new ( game . GetLoginOutLogRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . LoginOutLog . Ctx ( ctx )
if req . Account != "" {
uid , _ := GetAccountUid2 ( ctx , req . Account , fmt . Sprint ( req . ServerId ) )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
} else if req . Id != "" {
uid , _ := strconv . ParseInt ( req . Id , 10 , 64 )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
} else if req . Uid != "" {
srcId , err1 := GetStringIdToUid ( ctx , req . Uid )
if err1 != nil {
g . Log ( ) . Error ( ctx , "GetUnit 获取账号ID err : " , err1 , req . Uid )
return
}
if g . IsEmpty ( srcId ) {
g . Log ( ) . Error ( ctx , "GetUnit 账号ID不存在 : " , srcId )
return
}
uid , _ := strconv . ParseInt ( srcId , 10 , 64 )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
}
res . Total , err = model . Count ( )
err = model . Page ( req . PageNum , req . PageSize ) . OrderDesc ( "c_date" ) . Scan ( & res . Logs )
if err != nil {
return
}
return
} )
return
}
func GetItemLog ( ctx context . Context , req * game . GetItemLogReq ) ( res * game . GetItemLogRes , err error ) {
res = new ( game . GetItemLogRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . ItemIncomeExpenseRecords . Ctx ( ctx )
if req . Account != "" {
uid , _ := GetAccountUid2 ( ctx , req . Account , fmt . Sprint ( req . ServerId ) )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
model = model . Where ( "server=? " , req . ServerId )
} else if req . Uid != "" {
uid , _ := strconv . ParseInt ( req . Uid , 10 , 64 )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
model = model . Where ( "server=? " , req . ServerId )
} else if req . Id != "" {
uid , _ := strconv . ParseInt ( req . Id , 10 , 64 )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
model = model . Where ( "server=? " , req . ServerId )
}
if req . ItemId != 0 {
model = model . Where ( "item_id=? " , req . ItemId )
}
res . Total , err = model . Count ( )
err = model . Page ( req . PageNum , req . PageSize ) . Order ( "c_time desc" ) . Scan ( & res . Logs )
if err != nil {
return
}
return
} )
return
}
func GetRegister ( ctx context . Context , req * game . GetRegisterReq ) ( res * game . GetRegisterRes , err error ) {
res = new ( game . GetRegisterRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . ItemIncomeExpenseRecords . Ctx ( ctx )
if req . Account != "" {
uid , _ := GetAccountUid2 ( ctx , req . Account , fmt . Sprint ( req . ServerId ) )
if uid == 0 {
//g.Log().Debugf(ctx, "LoginOut -> "+fmt.Sprint(uid))
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
} else if req . Uid != "" {
uid , _ := strconv . ParseInt ( req . Uid , 10 , 64 )
if uid == 0 {
//g.Log().Debugf(ctx, "LoginOut -> "+fmt.Sprint(uid))
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
}
res . Total , err = model . Count ( )
err = model . Page ( req . PageNum , req . PageSize ) . Scan ( & res . Logs )
if err != nil {
return
}
return
} )
return
}
var online = map [ int ] int64 { }
func GameRegister ( ctx context . Context , req * game . RegisterReq ) ( res * game . RegisterRes , err error ) {
if req . Account == "" {
err = gerror . New ( "请填写账号!" )
return
}
if req . Uid == 0 {
err = gerror . New ( "请填写账号!" )
return
}
g . Try ( ctx , func ( ctx context . Context ) {
registerData := [ ] entity . GameRegister { }
register := dao . GameRegister . Ctx ( ctx )
register . Where ( "account=?" , req . Account ) . Where ( "channel=?" , req . Channel ) . Scan ( & registerData )
//g.Log().Debugf(ctx, "GameRegister -> "+gjson.MustEncodeString(registerData))
if len ( registerData ) > 0 {
if ! strings . Contains ( registerData [ 0 ] . Server , fmt . Sprintf ( "<%d>" , req . Server ) ) {
_ , err = register . Where ( "account=?" , req . Account ) . Where ( "channel=?" , req . Channel ) . Update ( g . Map {
dao . GameRegister . Columns ( ) . Server : registerData [ 0 ] . Server + fmt . Sprintf ( "<%d>" , req . Server ) ,
} )
}
} else {
_ , err = register . Insert ( & do . GameRegister {
Account : req . Account ,
Channel : req . Channel ,
CreateType : req . CreateType ,
Platform : req . Platform ,
Server : fmt . Sprintf ( "<%d>" , req . Server ) ,
} )
}
_ , err = dao . GameUnit . Ctx ( ctx ) . Insert ( & do . GameUnit {
Account : req . Account ,
Channel : req . Channel ,
Uid : req . Uid ,
Server : req . Server ,
OAID : req . OAID ,
Idfv : req . Idfv ,
AndroidId : req . AndroidId ,
} )
if req . Channel == consts . Channel_TAPTAP {
req1 := new ( game . DeepADReq )
req1 . OAID = req . OAID
req1 . State = consts . ADDVERTISEMENT_REGISTER
_ , err = DeepAdvertise ( ctx , req1 )
}
return
} )
return
}
func setAccount ( ctx context . Context , req * game . LoginOutReq ) {
g . Try ( ctx , func ( ctx context . Context ) {
account , err := GetAccountByUid ( ctx , req . Uid , fmt . Sprint ( req . Server ) )
if err != nil || account [ "AccountName" ] == "" {
log . Printf ( "GameUnit nil uid: %d, server: %d" , req . Uid , req . Server )
} else {
save := game . RegisterReq { }
save . Channel = fmt . Sprintf ( "%06d" , account [ "Channel" ] ) + fmt . Sprintf ( "%06d" , account [ "SubChannel" ] )
accountName := fmt . Sprint ( account [ "AccountName" ] )
if ! strings . HasPrefix ( accountName , save . Channel ) {
accountName = save . Channel + accountName
}
save . Account = accountName
save . Uid = req . Uid
save . Server = req . Server
save . Platform = 3
save . CreateType = 4
_ , err = GameRegister ( ctx , & save )
if err != nil {
log . Printf ( "GameRegister nil uid: %d, server: %d" , req . Uid , req . Server )
}
}
} )
}
func LoginOut ( ctx context . Context , req * game . LoginOutReq ) ( res * game . LoginOutRes , err error ) {
g . Try ( ctx , func ( ctx context . Context ) {
count := 0
modelLog := dao . LoginOutLog . Ctx ( ctx )
var loginLog [ ] entity . LoginOutLog
err = modelLog . Where ( dao . LoginOutLog . Columns ( ) . Uid , req . Uid ) . Where ( dao . LoginOutLog . Columns ( ) . EDate , 0 ) . Scan ( & loginLog )
//g.Log().Debugf(ctx, "LoginOut -> "+gjson.MustEncodeString(loginLog))
if len ( loginLog ) > 0 {
if req . State == consts . LogOut_State {
count = 1
}
modelLog . WherePri ( loginLog [ 0 ] . Id ) . Update ( g . Map {
dao . LoginOutLog . Columns ( ) . EDate : gtime . Timestamp ( ) ,
} )
}
if req . State == consts . LogIn_State {
_ , err = modelLog . Insert ( & do . LoginOutLog {
Uid : req . Uid ,
CDate : gtime . Timestamp ( ) ,
Server : req . Server ,
} )
count = 1
go sendAdvertisement ( ctx , req . Uid )
}
if count == 1 {
var result sql . Result
result , err = dao . GameUnit . Ctx ( ctx ) . Where ( "uid=?" , req . Uid ) . Where ( "server=?" , req . Server ) . Update ( g . Map {
dao . GameUnit . Columns ( ) . Name : req . Name ,
dao . GameUnit . Columns ( ) . Scale : req . Scale ,
dao . GameUnit . Columns ( ) . LogTime : time . Now ( ) . Unix ( ) ,
dao . GameUnit . Columns ( ) . VillagerNum : req . VillagerNum ,
dao . GameUnit . Columns ( ) . Day : req . Day ,
dao . GameUnit . Columns ( ) . GoldIngot : req . GoldIngot ,
dao . GameUnit . Columns ( ) . BaseFood : req . BaseFood ,
dao . GameUnit . Columns ( ) . Prosperity : req . Prosperity ,
} )
affect , err := result . RowsAffected ( )
if err != nil || affect == 0 {
go setAccount ( ctx , req )
}
model := dao . LoginLogoutInfo . Ctx ( ctx )
_ , err = model . Insert ( & do . LoginLogoutInfo {
Uid : req . Uid ,
State : req . State ,
Day : req . Day ,
GameTime : req . GameTime ,
Scale : req . Scale ,
VillagerNum : req . VillagerNum ,
Copper : req . Copper ,
GoldIngot : req . GoldIngot ,
BaseFood : req . BaseFood ,
Prosperity : req . Prosperity ,
Server : req . Server ,
VouchersNum : req . VouchersNum ,
RechargeTotal : req . RechargeTotal ,
StoreSum : req . StoreSum ,
StoneAmount : req . StoneAmount ,
} )
if req . StoneAmount > 50000 || req . VouchersNum > 400 || ( req . RechargeTotal == 0 && req . VouchersNum > 10 ) {
_ , err = dao . LoginLogoutInfoGm . Ctx ( ctx ) . Insert ( & do . LoginLogoutInfoGm {
Uid : req . Uid ,
State : req . State ,
Day : req . Day ,
GameTime : req . GameTime ,
Scale : req . Scale ,
VillagerNum : req . VillagerNum ,
Copper : req . Copper ,
GoldIngot : req . GoldIngot ,
BaseFood : req . BaseFood ,
Prosperity : req . Prosperity ,
Server : req . Server ,
VouchersNum : req . VouchersNum ,
RechargeTotal : req . RechargeTotal ,
StoreSum : req . StoreSum ,
StoneAmount : req . StoneAmount ,
} )
}
}
if gtime . Timestamp ( ) - online [ req . Server ] > 2 {
online [ req . Server ] = gtime . Timestamp ( )
var onlineData [ ] entity . OnlineData
onlineModel := g . Model ( "login_out_log" , "a" ) .
Fields ( "count(1) as num,b.channel" )
if req . Server != 0 {
onlineModel . Where ( "a.server=?" , req . Server )
}
err1 := onlineModel . Where ( "a.e_date" , 0 ) .
InnerJoin ( "game_unit" , "b" , "b.uid=a.uid" ) .
Group ( "b.channel" ) .
Scan ( & onlineData )
//g.Log().Debugf(ctx, "onlineData -> "+gjson.MustEncodeString(onlineData))
if err1 == nil {
var insertData [ ] do . GameOnline
for _ , v := range onlineData {
g . Log ( ) . Debugf ( ctx , "onlineData -> " + gjson . MustEncodeString ( v ) + " channel:" + v . Channel )
insertData = append ( insertData , do . GameOnline { Channel : v . Channel , Server : req . Server , Num : v . Num } )
}
dao . GameOnline . Ctx ( ctx ) . Insert ( insertData )
}
}
return
} )
return
}
func sendAdvertisement ( ctx context . Context , uid int64 ) {
units := [ ] entity . GameUnit { }
err := dao . GameUnit . Ctx ( ctx ) . Where ( "uid=?" , uid ) . Where ( "OAID<>''" ) . Scan ( & units )
if err != nil {
log . Printf ( "sendAdvertisement===Scan: err: %s" , err . Error ( ) )
}
if len ( units ) == 0 || units [ 0 ] . OAID == "" || units [ 0 ] . Channel != consts . Channel_TAPTAP {
return
}
req1 := new ( game . DeepADReq )
req1 . OAID = units [ 0 ] . OAID
req1 . State = consts . ADDVERTISEMENT_TWO
_ , err = DeepAdvertise ( ctx , req1 )
if err != nil {
log . Printf ( "sendAdvertisement===DeepAdvertise: err: %s" , err . Error ( ) )
return
}
log . Printf ( "sendAdvertisement: uid: %d, req1: %s" , uid , gjson . MustEncodeString ( req1 ) )
}
func GameUnitChangeName ( ctx context . Context , req * game . UnitChangeNameReq ) ( res * game . UnitChangeNameRes , err error ) {
if req . Uid == 0 {
err = gerror . New ( "请填写账号!" )
return
}
g . Try ( ctx , func ( ctx context . Context ) {
_ , err = dao . GameUnit . Ctx ( ctx ) . WherePri ( req . Uid ) . Where ( "server=?" , req . Server ) . Update ( g . Map {
dao . GameUnit . Columns ( ) . Name : req . Name ,
} )
return
} )
return
}
func ItemIncomeExpenseRecords ( ctx context . Context , req * game . ItemRecordReq ) ( res * game . ItemRecordRes , err error ) {
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . ItemIncomeExpenseRecords . Ctx ( ctx )
_ , err = model . Insert ( & do . ItemIncomeExpenseRecords {
Uid : req . Uid ,
ItemId : req . ItemId ,
Num : req . Num ,
Way : req . Way ,
State : req . State ,
Server : req . Server ,
} )
return
} )
return
}
func ShopRecords ( ctx context . Context , req * game . ShopRecordReq ) ( res * game . ShopRecordRes , err error ) {
res = new ( game . ShopRecordRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . GameShopLog . Ctx ( ctx )
_ , err = model . Insert ( & do . GameShopLog {
Uid : req . Uid ,
ItemId : req . ItemId ,
Price : req . Price ,
Num : req . Num ,
ServerId : req . ServerId ,
ConfigType : req . ConfigType ,
} )
return
} )
return
}
func GetShopItemLog ( ctx context . Context , req * game . GetShopItemLogReq ) ( res * game . GetShopItemLogRes , err error ) {
res = new ( game . GetShopItemLogRes )
g . Try ( ctx , func ( ctx context . Context ) {
shopLogSql := fmt . Sprintf ( ` select u.account,s.itemId,s.num,s.price,s.config_type from game_shop_log s inner join game_unit u on s.uid=u.uid and s.serverId=u.server where 1=1 ` )
rechargeSql := fmt . Sprintf ( ` select DISTINCT u.account from game_recharge r inner join game_unit u on r.unitId=u.uid inner join game_register rr on rr.account=u.account where r.status=2 ` )
if req . LowTime != "" {
rechargeSql += fmt . Sprintf ( ` and rr.create_time>"%s" ` , req . LowTime )
shopLogSql += fmt . Sprintf ( ` and s.c_date>"%s" ` , req . LowTime )
}
if req . Uptime != "" {
rechargeSql = fmt . Sprintf ( ` %s and rr.create_time<"%s" ` , rechargeSql , req . Uptime )
shopLogSql = fmt . Sprintf ( ` %s and s.c_date<"%s" ` , shopLogSql , req . Uptime )
}
if req . ServerId != 0 {
rechargeSql = fmt . Sprintf ( ` %s and u.server=%d ` , rechargeSql , req . ServerId )
shopLogSql = fmt . Sprintf ( ` %s and u.server=%d ` , shopLogSql , req . ServerId )
}
if req . Channel != "" {
rechargeSql = fmt . Sprintf ( ` %s and u.channel="%s" ` , rechargeSql , req . Channel )
shopLogSql = fmt . Sprintf ( ` %s and u.channel="%s" ` , shopLogSql , req . Channel )
}
if req . GM == 0 {
rechargeSql = fmt . Sprintf ( ` %s and r.tradeNo NOT LIKE "GM%%" ` , rechargeSql )
}
shopLogSql = fmt . Sprintf ( ` select a.account, a.itemId, a.config_type from (%s) as a group by a.itemId,a.config_type,a.account ` , shopLogSql )
shopLogSql = fmt . Sprintf ( ` select count(1) as num, b.itemId, b.config_type from (%s) as b group by b.itemId,b.config_type ` , shopLogSql )
res . Total , err = g . Model ( ) . Raw ( shopLogSql ) . Count ( )
err = g . Model ( ) . Raw ( shopLogSql ) . Page ( req . PageNum , req . PageSize ) . Scan ( & res . Logs )
res . RechargeTotal , err = g . Model ( ) . Raw ( rechargeSql ) . Count ( )
if err != nil {
return
}
return
} )
return
}
func GetShopItemList ( ctx context . Context , req * game . GetShopItemListReq ) ( res * game . GetShopItemListRes , err error ) {
res = new ( game . GetShopItemListRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . GameShopLog . Ctx ( ctx )
if req . LowTime != "" {
model = model . Where ( "c_date>?" , req . LowTime )
}
if req . Uptime != "" {
model = model . Where ( "c_date<?" , req . Uptime )
}
if req . ServerId != 0 {
model = model . Where ( "serverId=?" , req . ServerId )
}
if req . Uid != 0 {
id , _ := GetIdToUid ( ctx , int64 ( req . Uid ) )
model = model . Where ( "uid=?" , id )
}
err = model . Page ( req . PageNum , req . PageSize ) . OrderDesc ( "c_date" ) . Scan ( & res . Logs )
res . Total , err = model . Count ( )
for k , v := range res . Logs {
res . Logs [ k ] . StringId = fmt . Sprint ( v . Uid )
res . Logs [ k ] . UniqueId , _ = GetStringIdToUid ( ctx , res . Logs [ k ] . StringId )
account , err := GetUnitById ( ctx , v . Uid , v . ServerId )
if err != nil {
continue
}
res . Logs [ k ] . Account = fmt . Sprint ( account . Account )
}
if err != nil {
return
}
return
} )
return
}
func GameUserDel ( ctx context . Context , req * game . UserDelReq ) ( res * game . UserDelRes , err error ) {
err = g . Try ( ctx , func ( ctx context . Context ) {
res = new ( game . UserDelRes )
user := service . Context ( ) . GetLoginUser ( ctx )
fulluser , err1 := service . User ( ) . GetUserByUsername ( ctx , user . UserName )
if err != nil {
liberr . ErrIsNil ( ctx , err1 )
return
}
password := libUtils . EncryptPassword ( req . Password , fulluser . UserSalt )
g . Log ( ) . Info ( ctx , fmt . Sprint ( "密码错误! pwd:" + fmt . Sprintf ( "%v" , fulluser ) + ", req.pwd:" + password ) )
if fulluser . UserPassword != password {
liberr . ErrIsNil ( ctx , errors . New ( "密码错误! pwd:" + fulluser . UserPassword + ", req.pwd:" + password ) )
return
}
units := [ ] entity . GameUnit { }
err = dao . GameUnit . Ctx ( ctx ) . Where ( "account=?" , req . Account ) . Scan ( & units )
data , _ := json . Marshal ( units )
log . Printf ( "GameUserDel: %s" , string ( data ) )
_ , err = dao . GameRegister . Ctx ( ctx ) . Delete ( "account=?" , req . Account )
_ , err = dao . GameUnit . Ctx ( ctx ) . Delete ( "account=?" , req . Account )
uids := [ ] int64 { }
for _ , v := range units {
if v . Account == req . Account {
uids = append ( uids , v . Uid )
}
}
log . Printf ( "GameUserDel: %s" , fmt . Sprint ( uids ) )
//_, err = dao.GameRecharge.Ctx(ctx).Delete("unitId in (?)", uids)
//_, err = dao.GameRechargeLog.Ctx(ctx).Delete("unitId in (?)", uids)
//_, err = dao.LoginLogoutInfo.Ctx(ctx).Delete("uid in (?)", uids)
//_, err = dao.LoginOutLog.Ctx(ctx).Delete("uid in (?)", uids)
//_, err = dao.ItemIncomeExpenseRecords.Ctx(ctx).Delete("uid in (?)", uids)
//_, err = dao.ItemIncomeExpenseRecords.Ctx(ctx).Delete("uid in (?)", uids)
if err != nil {
log . Printf ( "GameUserDel: %s" , err . Error ( ) )
}
res . Data = 1
} )
return
}
func GetOperLog ( ctx context . Context , req * game . GetOperLogReq ) ( res * game . GetOperLogRes , err error ) {
res = new ( game . GetOperLogRes )
err = g . Try ( ctx , func ( ctx context . Context ) {
if req . Label == "" {
req . Label = "/api/v1/game/mange/setclientgm"
}
model := dao . SysOperLog . Ctx ( ctx ) . Where ( "oper_url=?" , req . Label )
res . Total , err = model . Count ( )
err = model . Page ( req . PageNum , req . PageSize ) . Order ( "oper_time desc" ) . Scan ( & res . List )
} )
return
}
func GetLoginOutGm ( ctx context . Context , req * game . GetLoginOutGmReq ) ( res * game . GetLoginOutGmRes , err error ) {
res = new ( game . GetLoginOutGmRes )
g . Try ( ctx , func ( ctx context . Context ) {
model := dao . LoginLogoutInfoGm . Ctx ( ctx )
if req . Account != "" {
uid , _ := GetAccountUid2 ( ctx , req . Account , fmt . Sprint ( req . ServerId ) )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
} else if req . Uid != "" {
uid , _ := strconv . ParseInt ( req . Uid , 10 , 64 )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
} else if req . UnitId != 0 {
uid , _ := GetIdToUid ( ctx , req . UnitId )
if uid == 0 {
err = gerror . New ( "获取账号失败!" )
return
}
model = model . Where ( "uid=? " , uid )
}
if req . RechargeTotal > 0 {
model = checkDaoIntCompareType ( model , req . CompareType , "rechargeTotal" , req . RechargeTotal )
}
if req . State > 0 && req . State < 3 {
model = model . Where ( "state=? " , req . State )
}
if req . CDate != 0 {
model = model . Where ( "c_date>? " , time . UnixMilli ( req . CDate ) . Format ( consts . TIME_FORMAT ) )
}
if req . VouchersNum > 0 {
model = model . Where ( "vouchersNum>? " , req . VouchersNum )
}
if req . StoneAmount > 0 {
model = model . Where ( "stoneAmount>? " , req . StoneAmount )
}
res . Total , err = model . Count ( )
err = model . Page ( req . PageNum , req . PageSize ) . OrderDesc ( "c_date" ) . Scan ( & res . Logs )
for k , v := range res . Logs {
res . Logs [ k ] . Uid , _ = GetIdToUid ( ctx , v . Uid )
}
if err != nil {
return
}
return
} )
return
}