Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-user
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
chenweijian
hilo-user
Commits
7b53b832
Commit
7b53b832
authored
Jul 11, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:用户推荐
parent
2c323d3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
0 deletions
+81
-0
gift.go
domain/model/recommend_m/gift.go
+34
-0
gift.go
route/recommend_r/gift.go
+42
-0
router.go
route/router.go
+5
-0
No files found.
domain/model/recommend_m/gift.go
0 → 100644
View file @
7b53b832
package
recommend_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/bluele/gcache"
"time"
)
// 推荐用户送礼
type
recommendUserGift
struct
{
SendUserId
mysql
.
ID
SendUserDiamond
mysql
.
Num
}
var
recommendUserGiftKey
=
"recommendUserGiftKey"
var
recommendUserGiftCache
=
gcache
.
New
(
1
)
.
LRU
()
.
Build
()
// 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户
// 先lru cache,后db
// ttl: 5min
func
GetPastTop50SendGiftUsers
(
model
*
domain
.
Model
)
[]
recommendUserGift
{
if
data
,
err
:=
recommendUserGiftCache
.
Get
(
recommendUserGiftKey
);
err
==
nil
{
return
data
.
([]
recommendUserGift
)
}
var
res
[]
recommendUserGift
if
err
:=
model
.
DB
()
.
Table
(
"gift_operate"
)
.
Select
(
"send_user_id,SUM(send_user_diamond) send_user_diamond"
)
.
Where
(
"created_time >= ?"
,
time
.
Now
()
.
Add
(
-
time
.
Hour
*
12
))
.
Group
(
"send_user_id"
)
.
Having
(
"send_user_diamond > 100000"
)
.
Order
(
"send_user_diamond DESC"
)
.
Limit
(
50
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetPastTop50SendGiftUsers fail:%v"
,
err
)
}
recommendUserGiftCache
.
SetWithExpire
(
recommendUserGiftKey
,
res
,
time
.
Minute
*
5
)
return
res
}
route/recommend_r/gift.go
0 → 100644
View file @
7b53b832
package
recommend_r
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"hilo-user/cv/user_cv"
"hilo-user/domain/model/recommend_m"
"hilo-user/domain/model/user_m"
"hilo-user/resp"
)
// @Tags 用户推荐
// @Summary 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户
// @Param token header string true "token"
// @Success 200 {object} []user_cv.UserTiny
// @Router /v1/recommend/user/gift [get]
func
UserRecommendGift
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myContext
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
model
:=
domain
.
CreateModelContext
(
myContext
)
// 获取推荐
recommendUser
:=
recommend_m
.
GetPastTop50SendGiftUsers
(
model
)
var
response
=
make
([]
*
user_cv
.
UserTiny
,
0
)
if
len
(
recommendUser
)
<=
0
{
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
nil
}
var
userIds
[]
mysql
.
ID
for
_
,
v
:=
range
recommendUser
{
userIds
=
append
(
userIds
,
v
.
SendUserId
)
}
users
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
userIds
)
if
err
!=
nil
{
return
myContext
,
err
}
for
_
,
v
:=
range
recommendUser
{
response
=
append
(
response
,
user_cv
.
UserToTiny
(
users
[
v
.
SendUserId
]))
}
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
nil
}
route/router.go
View file @
7b53b832
...
...
@@ -12,6 +12,7 @@ import (
"hilo-user/domain/model/msg_m"
"hilo-user/resp"
"hilo-user/route/cp_r"
"hilo-user/route/recommend_r"
"hilo-user/route/user_r"
)
...
...
@@ -52,6 +53,10 @@ func InitRouter() *gin.Engine {
//cp.GET("/relation/detail", wrapper(cp_r.CpDetailPage))
cp
.
GET
(
"/im/check"
,
wrapper
(
cp_r
.
CheckCpImExpire
))
}
recommend
:=
v1
.
Group
(
"recommend"
)
{
recommend
.
GET
(
"/user/gift"
,
wrapper
(
recommend_r
.
UserRecommendGift
))
}
inner
:=
r
.
Group
(
"/inner"
)
inner
.
Use
(
ExceptionHandle
,
LoggerHandle
)
innerUser
:=
inner
.
Group
(
"/user"
)
...
...
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