This commit is contained in:
孟帅
2023-02-23 17:53:04 +08:00
parent 7cf1b8ce8e
commit 61d0988d2c
402 changed files with 18340 additions and 35547 deletions

View File

@@ -1,6 +1,6 @@
// Package hook
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
@@ -16,12 +16,11 @@ import (
"hotgo/utility/simple"
)
// AccessLog 访问日志
func (s *sHook) AccessLog(r *ghttp.Request) {
// accessLog 访问日志
func (s *sHook) accessLog(r *ghttp.Request) {
if r.IsFileRequest() {
return
}
var ctx = r.Context()
modelCtx := contexts.Get(ctx)
if modelCtx == nil {
@@ -33,7 +32,7 @@ func (s *sHook) AccessLog(r *ghttp.Request) {
simple.SafeGo(ctx, func(ctx context.Context) {
if err := service.SysLog().AutoLog(ctx); err != nil {
g.Log().Warningf(ctx, "hook AccessLog err:%+v", err)
g.Log().Warningf(ctx, "hook accessLog err:%+v", err)
}
})
}

View File

@@ -1,12 +1,13 @@
// Package hook
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2022 HotGo CLI
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package hook
import (
"github.com/gogf/gf/v2/net/ghttp"
"hotgo/internal/service"
)
@@ -20,3 +21,8 @@ func init() {
func New() *sHook {
return &sHook{}
}
func (s *sHook) AfterOutput(r *ghttp.Request) {
s.accessLog(r)
s.lastAdminActive(r)
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/os/gtimer"
"hotgo/internal/consts"
"hotgo/internal/library/contexts"
"hotgo/utility/simple"
"sync"
@@ -58,30 +59,30 @@ func allow(memberId int64) bool {
return false
}
// LastActive 更新用户最后活跃
func (s *sHook) LastActive(r *ghttp.Request) {
// lastAdminActive 更新后台用户最后活跃
func (s *sHook) lastAdminActive(r *ghttp.Request) {
if r.IsFileRequest() {
return
}
var (
ctx = r.Context()
memberId = contexts.GetUserId(ctx)
ctx = r.Context()
member = contexts.GetUser(ctx)
)
if memberId == 0 {
if member == nil || member.App != consts.AppAdmin {
return
}
if allow(memberId) {
if allow(member.Id) {
simple.SafeGo(ctx, func(ctx context.Context) {
_, err := g.Model("admin_member").Ctx(ctx).
Where("id", memberId).
Where("id", member.Id).
WhereLT("last_active_at", gtime.Now()).
Data(g.Map{"last_active_at": gtime.Now()}).
Update()
if err != nil {
g.Log().Warningf(ctx, "hook LastActive err:%+v, memberId:%v", err, memberId)
g.Log().Warningf(ctx, "hook lastActive err:%+v, memberId:%v", err, member.Id)
}
})
}