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
75970f92
Commit
75970f92
authored
Mar 03, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:迁移代码
parent
2ca0565e
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
861 additions
and
3 deletions
+861
-3
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
util.go
resource/redisCli/util.go
+35
-0
finance.go
rpc/finance.go
+23
-3
fix_user_svip.go
script/fix_user_svip.go
+91
-0
agora.go
sdk/agora/agora.go
+652
-0
time.go
utils/time.go
+5
-0
url.go
utils/url.go
+1
-0
utils.go
utils/utils.go
+51
-0
No files found.
go.mod
View file @
75970f92
...
@@ -3,6 +3,7 @@ module git.hilo.cn/hilo-common
...
@@ -3,6 +3,7 @@ module git.hilo.cn/hilo-common
go 1.17
go 1.17
require (
require (
github.com/AgoraIO/Tools/DynamicKey/AgoraDynamicKey/go/src v0.0.0-20200910100525-12b7f1b63a6a // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
...
...
go.sum
View file @
75970f92
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/AgoraIO/Tools/DynamicKey/AgoraDynamicKey/go/src v0.0.0-20200910100525-12b7f1b63a6a h1:+/ILLIcuKbrW4kyQ0V574aV9skXRivrcmlg0IBk7apY=
github.com/AgoraIO/Tools/DynamicKey/AgoraDynamicKey/go/src v0.0.0-20200910100525-12b7f1b63a6a/go.mod h1:4bXIK0ntDk9CqAXobmomWd7dedbfNv/aaIpmpqqzt+A=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274 h1:u48e7I7h/BY5uDP8xiIFNaUkdTVk7hjj/Sucg8FrxNU=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274 h1:u48e7I7h/BY5uDP8xiIFNaUkdTVk7hjj/Sucg8FrxNU=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274/go.mod h1:9CMdKNL3ynIGPpfTcdwTvIm8SGuAZYYC4jFVSSvE1YQ=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1274/go.mod h1:9CMdKNL3ynIGPpfTcdwTvIm8SGuAZYYC4jFVSSvE1YQ=
...
...
resource/redisCli/util.go
0 → 100644
View file @
75970f92
package
redisCli
import
(
"context"
"git.hilo.cn/hilo-common/mylogrus"
"time"
)
//这个用户避免多个服务器并发问题。
func
SetNX
(
key
string
,
value
interface
{},
expiration
time
.
Duration
,
callBack
func
())
{
flag
,
err
:=
RedisClient
.
SetNX
(
context
.
Background
(),
key
,
value
,
expiration
)
.
Result
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"key:%v lock start setNx err: %v"
,
key
,
err
)
}
if
!
flag
{
mylogrus
.
MyLog
.
Infof
(
"key:%v lock setNx has lock"
,
key
)
return
}
mylogrus
.
MyLog
.
Infof
(
"key:%v lock setNx begin"
,
key
)
callBack
()
//执行结束之后,移除key
//RedisClient.Del(context.Background(), key)
mylogrus
.
MyLog
.
Infof
(
"key:%v lock setNx end"
,
key
)
}
func
Lock
(
key
string
,
expiration
time
.
Duration
)
bool
{
flag
,
err
:=
RedisClient
.
SetNX
(
context
.
Background
(),
key
,
1
,
expiration
)
.
Result
()
if
err
!=
nil
{
return
false
}
if
!
flag
{
return
false
}
return
true
}
rpc/finance.go
View file @
75970f92
...
@@ -55,6 +55,7 @@ type CVSvipPrivilege struct {
...
@@ -55,6 +55,7 @@ type CVSvipPrivilege struct {
Type
int
`json:"type"`
// 1.专属勋章, 2.专属标识, 3.设备和IP踢出房间, 4.隐藏在线, 5.禁止跟随, 6.炫彩昵称, 7.隐藏礼物墙, 8.隐藏访客记录, 9.排行榜隐身, 10.房间防踢, 11.房间防抱下麦
Type
int
`json:"type"`
// 1.专属勋章, 2.专属标识, 3.设备和IP踢出房间, 4.隐藏在线, 5.禁止跟随, 6.炫彩昵称, 7.隐藏礼物墙, 8.隐藏访客记录, 9.排行榜隐身, 10.房间防踢, 11.房间防抱下麦
CanSwitch
bool
`json:"canSwitch"`
// 能否开关
CanSwitch
bool
`json:"canSwitch"`
// 能否开关
UserSwitch
bool
`json:"userSwitch"`
// 用户开关
UserSwitch
bool
`json:"userSwitch"`
// 用户开关
MysteryCode
string
`json:"mysteryCode,omitempty"`
// 神秘人代码,特权17的专属代码
}
}
// 获取svip等级
// 获取svip等级
...
@@ -120,6 +121,25 @@ func MGetUserSvip(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]CvSvip,
...
@@ -120,6 +121,25 @@ func MGetUserSvip(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]CvSvip,
return
res
,
nil
return
res
,
nil
}
}
// 拷贝客户端用到的privileges赋值
// 避免推送大包体
// 目前暂时只需要 svip7.神秘人特权
func
CopySimpleSvip
(
svip
CvSvip
)
CvSvip
{
var
simpleSvip
CvSvip
simpleSvip
.
SvipLevel
=
svip
.
SvipLevel
for
_
,
p
:=
range
svip
.
Privileges
{
if
p
.
Type
==
17
{
// 神秘人代码,特权17的专属代码
simpleSvip
.
Privileges
=
append
(
simpleSvip
.
Privileges
,
CVSvipPrivilege
{
Type
:
p
.
Type
,
CanSwitch
:
p
.
CanSwitch
,
UserSwitch
:
p
.
UserSwitch
,
MysteryCode
:
p
.
MysteryCode
,
})
}
}
return
simpleSvip
}
func
getFinanceHost
()
string
{
func
getFinanceHost
()
string
{
l
:=
len
(
financeServerHost
)
l
:=
len
(
financeServerHost
)
r
:=
rand
.
Intn
(
l
)
// 随机一个
r
:=
rand
.
Intn
(
l
)
// 随机一个
...
...
script/fix_user_svip.go
0 → 100644
View file @
75970f92
package
main
import
(
"fmt"
"git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/script/mysql"
)
type
UserSvip
struct
{
UserId
uint64
Code
string
Points
int64
Level
int
AcPoints
int64
Diamond
int64
}
var
bt1
=
"2023-01-04 16:42:58"
var
et1
=
"2023-03-04 00:00:00"
func
cal
(
level
int
)
int64
{
switch
level
{
case
1
:
return
50000
case
2
:
return
300000
case
3
:
return
1000000
case
4
:
return
2000000
case
5
:
return
5000000
case
6
:
return
10000000
case
7
:
return
30000000
}
return
0
}
func
main
()
{
var
userSvip
[]
UserSvip
if
err
:=
mysql
.
ProdReadOnlyDB
.
Model
(
UserSvip
{})
.
Where
(
"level > 0"
)
.
Find
(
&
userSvip
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
for
i
,
v
:=
range
userSvip
{
_
,
userSvip
[
i
]
.
Diamond
,
_
=
GetChargeMoneyDiamond2
(
v
.
UserId
)
userSvip
[
i
]
.
AcPoints
=
v
.
Points
+
cal
(
v
.
Level
)
var
user
model
.
User
if
err
:=
mysql
.
ProdReadOnlyDB
.
Model
(
model
.
User
{})
.
Where
(
"id = ? "
,
v
.
UserId
)
.
First
(
&
user
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
userSvip
[
i
]
.
Code
=
user
.
Code
}
fmt
.
Printf
(
"UserId,Points,Level,AcPoints,Diamond
\n
"
)
for
_
,
v
:=
range
userSvip
{
fmt
.
Printf
(
"%v,%v,%v,%v,%v
\n
"
,
v
.
Code
,
v
.
Points
,
v
.
Level
,
v
.
AcPoints
,
v
.
Diamond
)
}
}
func
GetChargeMoneyDiamond2
(
uid
uint64
)
(
int64
,
int64
,
error
)
{
type
R
struct
{
Money
int64
Diamond
int64
}
var
money
R
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"diamond_account_detail AS d"
)
.
Joins
(
"INNER JOIN pay_order AS p ON d.origin_id = p.id"
)
.
Where
(
"d.user_id in (?) AND operate_type in (?) AND add_reduce = 1"
,
uid
,
[]
int
{
int
(
4
),
int
(
42
),
int
(
55
),
int
(
68
)})
.
Where
(
"d.created_time >= ? AND d.created_time < ?"
,
bt1
,
et1
)
.
Order
(
"d.user_id"
)
.
Select
(
"SUM(p.price) as money,SUM(d.num) as diamond"
)
.
Scan
(
&
money
)
.
Error
;
err
!=
nil
{
return
0
,
0
,
err
}
type
R2
struct
{
Price
int64
Diamond
int64
}
var
money2
R2
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"diamond_account_detail AS d"
)
.
Joins
(
"INNER JOIN dealer_transfer_detail AS t ON d.origin_id = t.id"
)
.
Where
(
"d.user_id in (?) AND operate_type = ? AND add_reduce = 1"
,
uid
,
26
)
.
Select
(
"SUM(t.dollar) as price,SUM(d.num) as diamond"
)
.
Where
(
"d.created_time >= ? AND d.created_time < ?"
,
bt1
,
et1
)
.
Order
(
"d.user_id"
)
.
Scan
(
&
money2
)
.
Error
;
err
!=
nil
{
return
0
,
0
,
err
}
return
money
.
Money
+
money2
.
Price
,
money
.
Diamond
+
money2
.
Diamond
,
nil
}
sdk/agora/agora.go
0 → 100644
View file @
75970f92
This diff is collapsed.
Click to expand it.
utils/time.go
View file @
75970f92
...
@@ -6,6 +6,7 @@ const DEFAULT_LANG = "en"
...
@@ -6,6 +6,7 @@ const DEFAULT_LANG = "en"
const
DATETIME_FORMAT
=
"2006-01-02 15:04:05"
const
DATETIME_FORMAT
=
"2006-01-02 15:04:05"
const
COMPACT_DATE_FORMAT
=
"20060102"
const
COMPACT_DATE_FORMAT
=
"20060102"
const
DATE_FORMAT
=
"2006-01-02"
const
DATE_FORMAT
=
"2006-01-02"
const
COMPACT_MONTH_FORMAT
=
"200601"
func
GetZeroTime
(
t
time
.
Time
)
time
.
Time
{
func
GetZeroTime
(
t
time
.
Time
)
time
.
Time
{
return
time
.
Date
(
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
0
,
0
,
0
,
0
,
t
.
Location
())
return
time
.
Date
(
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
0
,
0
,
0
,
0
,
t
.
Location
())
...
@@ -22,3 +23,7 @@ func GetLastDayOfWeek(t time.Time, n time.Weekday) time.Time {
...
@@ -22,3 +23,7 @@ func GetLastDayOfWeek(t time.Time, n time.Weekday) time.Time {
}
}
return
t
.
AddDate
(
0
,
0
,
-
(
int
(
weekDay
)))
return
t
.
AddDate
(
0
,
0
,
-
(
int
(
weekDay
)))
}
}
func
GetMonday
(
t
time
.
Time
)
time
.
Time
{
return
GetLastDayOfWeek
(
t
,
time
.
Monday
)
}
utils/url.go
View file @
75970f92
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
)
)
const
DefaultAvatarMan
=
"hilo/manager/ea48b62d54a24a709de3c38702c89995.png"
const
DefaultAvatarMan
=
"hilo/manager/ea48b62d54a24a709de3c38702c89995.png"
const
DEFAULT_NICK
=
"Hilo No.%s"
// 补全url,区分处理oss和aws两种情况
// 补全url,区分处理oss和aws两种情况
func
MakeFullUrl
(
url
string
)
string
{
func
MakeFullUrl
(
url
string
)
string
{
...
...
utils/utils.go
View file @
75970f92
...
@@ -2,6 +2,8 @@ package utils
...
@@ -2,6 +2,8 @@ package utils
import
(
import
(
"encoding/json"
"encoding/json"
"git.hilo.cn/hilo-common/resource/mysql"
"time"
)
)
// 去除slice中的重复元素
// 去除slice中的重复元素
...
@@ -32,3 +34,52 @@ func SliceToMapUInt64(s []uint64) map[uint64]struct{} {
...
@@ -32,3 +34,52 @@ func SliceToMapUInt64(s []uint64) map[uint64]struct{} {
}
}
return
m
return
m
}
}
func
IfLogoutStr
(
condition
bool
,
trueVal
,
falseVal
string
)
string
{
if
condition
{
return
trueVal
}
return
falseVal
}
func
IfLogoutNick
(
condition
bool
,
code
string
,
nick
string
)
string
{
if
condition
{
return
"Hilo No."
+
code
}
return
nick
}
func
IfLogout
(
logoutTime
int64
)
bool
{
return
logoutTime
>
0
&&
time
.
Now
()
.
Unix
()
>
logoutTime
}
func
BirthdayToUint64
(
birthday
*
mysql
.
Timestamp
)
*
uint64
{
if
*
birthday
==
0
{
return
nil
}
return
(
*
uint64
)(
birthday
)
}
//空字符串转成nil
func
StrNil
(
msg
string
)
*
string
{
if
msg
==
""
{
return
nil
}
return
&
msg
}
func
TypeToUint8
(
t
*
mysql
.
Type
)
*
uint8
{
if
*
t
==
0
{
return
nil
}
else
{
return
(
*
uint8
)(
t
)
}
}
func
StrToString
(
str
*
mysql
.
Str
)
*
string
{
return
(
*
string
)(
str
)
}
func
NumToUint32
(
num
*
mysql
.
Num
)
*
uint32
{
return
(
*
uint32
)(
num
)
}
\ No newline at end of file
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