Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
dd8cc98f
Commit
dd8cc98f
authored
Dec 08, 2022
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
脚本代码
parent
6ffd0436
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
277 additions
and
2 deletions
+277
-2
.gitignore
.gitignore
+2
-1
go.mod
go.mod
+10
-0
go.sum
go.sum
+20
-0
mysql.go
mysql/mysql.go
+32
-0
group_power_india.go
script/group_power_india.go
+202
-0
utils.go
utils/utils.go
+1
-1
utils_test.go
utils/utils_test.go
+10
-0
No files found.
.gitignore
View file @
dd8cc98f
.idea
.idea
*.xlsx
\ No newline at end of file
go.mod
View file @
dd8cc98f
module github.com/hilo-common
module github.com/hilo-common
go 1.17
go 1.17
require (
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
gorm.io/driver/mysql v1.4.3 // indirect
gorm.io/gorm v1.23.8 // indirect
)
go.sum
0 → 100644
View file @
dd8cc98f
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gorm.io/driver/mysql v1.4.3 h1:/JhWJhO2v17d8hjApTltKNADm7K7YI2ogkR7avJUL3k=
gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
mysql/mysql.go
0 → 100644
View file @
dd8cc98f
package
mysql
import
(
"fmt"
_
"github.com/go-sql-driver/mysql"
//加载mysql驱动
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"log"
"net/url"
)
var
Db
*
gorm
.
DB
func
init
()
{
var
err
error
options
:=
"?charset=utf8mb4&parseTime=True&loc=Local&time_zone="
+
url
.
QueryEscape
(
"'+8:00'"
)
dsn
:=
"read_only:hilo1632@(rm-eb3w787dzn9c8g07vuo.mysql.dubai.rds.aliyuncs.com)/hilo"
+
options
Db
,
err
=
gorm
.
Open
(
mysql
.
Open
(
dsn
),
&
gorm
.
Config
{
NamingStrategy
:
schema
.
NamingStrategy
{
SingularTable
:
true
},
})
if
err
!=
nil
{
log
.
Fatalf
(
"mysql connect error %v"
,
err
)
}
else
{
log
.
Println
(
"mysql connect success"
)
}
if
Db
.
Error
!=
nil
{
fmt
.
Printf
(
"database error %v"
,
Db
.
Error
)
}
}
script/group_power_india.go
0 → 100644
View file @
dd8cc98f
package
main
import
(
"fmt"
"github.com/hilo-common/mysql"
"github.com/spf13/cast"
"github.com/tealeg/xlsx"
"time"
)
type
GroupPower
struct
{
GroupPowerId
uint64
Owner
uint64
OwnerCode
string
Country
string
UserIds
[]
uint64
// 所有uid
UserIds9
[]
uint64
// 9月1号注册后的uid
UserIds10
[]
uint64
// 10月1号注册后的uid
UserIds11
[]
uint64
// 11月1号注册后的uid
UserChargeNum
int
// 所有进行了充值的势力成员数量
UserChargeSum
float64
// 所有势力成员累积充值
UserChargeNum9
int
// 9月1号后注册所有进行了充值的势力成员数量
UserChargeSum9
float64
// 9月1号后注册所有势力成员累积充值
UserChargeNum10
int
// 10月1号后注册所有进行了充值的势力成员数量
UserChargeSum10
float64
// 10月1号后注册所有势力成员累积充值
UserChargeNum11
int
// 11月1号后注册所有进行了充值的势力成员数量
UserChargeSum11
float64
// 11月1号后注册所有势力成员累积充值
}
type
User
struct
{
Id
uint64
Code
string
Country
string
CreatedTime
time
.
Time
}
type
GroupPowerUser
struct
{
GroupPowerId
uint64
UserId
uint64
}
func
main
()
{
groupPowerSql
:=
"SELECT p.id as group_power_id,g.`owner` from group_power p,group_info g where p.group_uid = g.im_group_id"
var
groupPowers
[]
GroupPower
if
err
:=
mysql
.
Db
.
Raw
(
groupPowerSql
)
.
Find
(
&
groupPowers
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
var
userIds
[]
uint64
for
_
,
v
:=
range
groupPowers
{
userIds
=
append
(
userIds
,
v
.
Owner
)
}
var
users
[]
User
if
err
:=
mysql
.
Db
.
Model
(
User
{})
.
Where
(
"id in ?"
,
userIds
)
.
Find
(
&
users
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
userMap
:=
make
(
map
[
uint64
]
User
)
for
i
:=
range
users
{
userMap
[
users
[
i
]
.
Id
]
=
users
[
i
]
}
var
targetGroupPower
[]
GroupPower
var
targetGroupPowerId
[]
uint64
for
i
,
p
:=
range
groupPowers
{
if
userMap
[
p
.
Owner
]
.
Country
==
"India"
{
groupPowers
[
i
]
.
Country
=
"India"
groupPowers
[
i
]
.
Owner
=
userMap
[
p
.
Owner
]
.
Id
groupPowers
[
i
]
.
OwnerCode
=
userMap
[
p
.
Owner
]
.
Code
targetGroupPower
=
append
(
targetGroupPower
,
groupPowers
[
i
])
targetGroupPowerId
=
append
(
targetGroupPowerId
,
p
.
GroupPowerId
)
}
}
groupPowerUsersSql
:=
"SELECT group_power_id,user_id FROM `group_power_user` where group_power_id in (?);"
var
groupPowerUsers
[]
GroupPowerUser
if
err
:=
mysql
.
Db
.
Raw
(
groupPowerUsersSql
,
targetGroupPowerId
)
.
Find
(
&
groupPowerUsers
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
var
groupPowerUserMap
=
make
(
map
[
uint64
][]
uint64
)
// group_power_id -> []userId
for
_
,
v
:=
range
groupPowerUsers
{
groupPowerUserMap
[
v
.
GroupPowerId
]
=
append
(
groupPowerUserMap
[
v
.
GroupPowerId
],
v
.
UserId
)
}
for
i
,
v
:=
range
targetGroupPower
{
targetGroupPower
[
i
]
.
UserIds
=
groupPowerUserMap
[
v
.
GroupPowerId
]
for
_
,
userId
:=
range
targetGroupPower
[
i
]
.
UserIds
{
if
user
,
ok
:=
userMap
[
userId
];
ok
{
if
user
.
CreatedTime
.
After
(
time
.
Date
(
2022
,
time
.
September
,
1
,
0
,
0
,
0
,
0
,
time
.
Local
))
{
targetGroupPower
[
i
]
.
UserIds9
=
append
(
targetGroupPower
[
i
]
.
UserIds9
,
userId
)
}
if
user
.
CreatedTime
.
After
(
time
.
Date
(
2022
,
time
.
October
,
1
,
0
,
0
,
0
,
0
,
time
.
Local
))
{
targetGroupPower
[
i
]
.
UserIds10
=
append
(
targetGroupPower
[
i
]
.
UserIds10
,
userId
)
}
if
user
.
CreatedTime
.
After
(
time
.
Date
(
2022
,
time
.
November
,
1
,
0
,
0
,
0
,
0
,
time
.
Local
))
{
targetGroupPower
[
i
]
.
UserIds11
=
append
(
targetGroupPower
[
i
]
.
UserIds11
,
userId
)
}
}
}
}
type
NumSum
struct
{
Count
int
Price
int
}
// 直接充值
for
i
,
groupPower
:=
range
targetGroupPower
{
userChargeNumSql
:=
"SELECT count(DISTINCT user_id) as count,sum(price) as price FROM `pay_order` where status = 2 AND platform in (1,2,3,4,5) AND user_id in ? ;"
var
userChargeNumSum
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds
)
.
First
(
&
userChargeNumSum
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum
+=
userChargeNumSum
.
Count
targetGroupPower
[
i
]
.
UserChargeSum
+=
float64
(
userChargeNumSum
.
Price
)
/
100
}
if
len
(
groupPower
.
UserIds9
)
>
0
{
var
userChargeNumSum9
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds9
)
.
First
(
&
userChargeNumSum9
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum9
+=
userChargeNumSum9
.
Count
targetGroupPower
[
i
]
.
UserChargeSum9
+=
float64
(
userChargeNumSum9
.
Price
)
/
100
}
}
if
len
(
groupPower
.
UserIds10
)
>
0
{
var
userChargeNumSum10
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds10
)
.
First
(
&
userChargeNumSum10
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum10
+=
userChargeNumSum10
.
Count
targetGroupPower
[
i
]
.
UserChargeSum10
+=
float64
(
userChargeNumSum10
.
Price
)
/
100
}
}
if
len
(
groupPower
.
UserIds11
)
>
0
{
var
userChargeNumSum11
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds11
)
.
First
(
&
userChargeNumSum11
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum11
+=
userChargeNumSum11
.
Count
targetGroupPower
[
i
]
.
UserChargeSum11
+=
float64
(
userChargeNumSum11
.
Price
)
/
100
}
}
}
// 代理充值
for
i
,
groupPower
:=
range
targetGroupPower
{
userChargeNumSql
:=
"SELECT count(DISTINCT receiver_id) as count,sum(dollar) as price FROM `dealer_transfer_detail` where receiver_id in ? ;"
var
userChargeNumSum
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds
)
.
First
(
&
userChargeNumSum
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum
+=
userChargeNumSum
.
Count
targetGroupPower
[
i
]
.
UserChargeSum
+=
float64
(
userChargeNumSum
.
Price
)
/
100
}
if
len
(
groupPower
.
UserIds9
)
>
0
{
var
userChargeNumSum9
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds9
)
.
First
(
&
userChargeNumSum9
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum9
+=
userChargeNumSum9
.
Count
targetGroupPower
[
i
]
.
UserChargeSum9
+=
float64
(
userChargeNumSum9
.
Price
)
/
100
}
}
if
len
(
groupPower
.
UserIds10
)
>
0
{
var
userChargeNumSum10
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds10
)
.
First
(
&
userChargeNumSum10
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum10
+=
userChargeNumSum10
.
Count
targetGroupPower
[
i
]
.
UserChargeSum10
+=
float64
(
userChargeNumSum10
.
Price
)
/
100
}
}
if
len
(
groupPower
.
UserIds11
)
>
0
{
var
userChargeNumSum11
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds11
)
.
First
(
&
userChargeNumSum11
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum11
+=
userChargeNumSum11
.
Count
targetGroupPower
[
i
]
.
UserChargeSum11
+=
float64
(
userChargeNumSum11
.
Price
)
/
100
}
}
}
println
(
targetGroupPower
)
excelFileName
:=
fmt
.
Sprintf
(
"./india_power%s.xlsx"
,
time
.
Now
()
.
Format
(
"20060102150405"
))
xlFile
:=
xlsx
.
NewFile
()
sheet
,
err
:=
xlFile
.
AddSheet
(
"india_charge_data"
)
if
err
!=
nil
{
panic
(
err
)
}
row
:=
sheet
.
AddRow
()
c1
,
c2
,
c3
,
c4
,
c5
,
c6
,
c7
,
c8
,
c9
,
c10
:=
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
,
c3
.
Value
,
c4
.
Value
,
c5
.
Value
,
c6
.
Value
,
c7
.
Value
,
c8
.
Value
,
c9
.
Value
,
c10
.
Value
=
"印度国籍的势力主ID"
,
"所有势力成员数量"
,
"所有势力成员累积充值"
,
"所有进行了充值的势力成员数量"
,
"9月1日之后注册的势力成员累积充值"
,
"9月1日之后注册的进行了充值的势力成员数量"
,
"10月1日之后注册的势力成员累积充值"
,
"10月1日之后注册的进行了充值的势力成员数量"
,
"11月1日之后注册的势力成员累积充值"
,
"11月1日之后注册的进行了充值的势力成员数量"
for
_
,
power
:=
range
targetGroupPower
{
row
:=
sheet
.
AddRow
()
c1
,
c2
,
c3
,
c4
,
c5
,
c6
,
c7
,
c8
,
c9
,
c10
:=
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
,
c3
.
Value
,
c4
.
Value
,
c5
.
Value
,
c6
.
Value
,
c7
.
Value
,
c8
.
Value
,
c9
.
Value
,
c10
.
Value
=
toString
(
power
.
OwnerCode
),
toString
(
len
(
power
.
UserIds
)),
toString
(
power
.
UserChargeSum
),
toString
(
power
.
UserChargeNum
),
toString
(
power
.
UserChargeSum9
),
toString
(
power
.
UserChargeNum9
),
toString
(
power
.
UserChargeSum10
),
toString
(
power
.
UserChargeNum10
),
toString
(
power
.
UserChargeSum11
),
toString
(
power
.
UserChargeNum11
)
}
_
=
xlFile
.
Save
(
excelFileName
)
}
func
toString
(
n
interface
{})
string
{
return
cast
.
ToString
(
n
)
}
utils/utils.go
View file @
dd8cc98f
package
utils
package
utils
func
TestCommon
()
{
func
TestCommon
()
{
println
(
"hello"
)
}
}
utils/utils_test.go
0 → 100644
View file @
dd8cc98f
package
utils
import
(
"testing"
"time"
)
func
TestTestCommon
(
t
*
testing
.
T
)
{
t
.
Logf
(
time
.
Date
(
2022
,
time
.
November
,
1
,
0
,
0
,
0
,
0
,
time
.
Local
)
.
String
())
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment