mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-12 04:53:47 +08:00
版本预发布
This commit is contained in:
3
server/internal/library/hgorm/hook/hook.go
Normal file
3
server/internal/library/hgorm/hook/hook.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package hook
|
||||
|
||||
// hook.
|
58
server/internal/library/hgorm/hook/member.go
Normal file
58
server/internal/library/hgorm/hook/member.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// MemberInfo 后台用户信息
|
||||
var MemberInfo = gdb.HookHandler{
|
||||
Select: func(ctx context.Context, in *gdb.HookSelectInput) (result gdb.Result, err error) {
|
||||
result, err = in.Next(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for i, record := range result {
|
||||
// 部门
|
||||
if !record["dept_id"].IsEmpty() {
|
||||
deptName, err := g.Model("admin_dept").Ctx(ctx).
|
||||
Fields("name").
|
||||
Where("id", record["dept_id"]).
|
||||
Value()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
record["deptName"] = deptName
|
||||
}
|
||||
|
||||
// 角色
|
||||
if !record["role_id"].IsEmpty() {
|
||||
roleName, err := g.Model("admin_role").Ctx(ctx).
|
||||
Fields("name").
|
||||
Where("id", record["role_id"]).
|
||||
Value()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
record["roleName"] = roleName
|
||||
}
|
||||
|
||||
if !record["password_hash"].IsEmpty() {
|
||||
record["password_hash"] = gvar.New("")
|
||||
}
|
||||
|
||||
if !record["salt"].IsEmpty() {
|
||||
record["salt"] = gvar.New("")
|
||||
}
|
||||
|
||||
if !record["auth_key"].IsEmpty() {
|
||||
record["auth_key"] = gvar.New("")
|
||||
}
|
||||
|
||||
result[i] = record
|
||||
}
|
||||
return
|
||||
},
|
||||
}
|
59
server/internal/library/hgorm/hook/provinces.go
Normal file
59
server/internal/library/hgorm/hook/provinces.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/library/location"
|
||||
)
|
||||
|
||||
// CityLabel 城市地区标签
|
||||
var CityLabel = gdb.HookHandler{
|
||||
Select: func(ctx context.Context, in *gdb.HookSelectInput) (result gdb.Result, err error) {
|
||||
result, err = in.Next(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
parse := func(id int64, index int) {
|
||||
cityLabel, err := location.ParseSimpleRegion(ctx, id)
|
||||
if err != nil {
|
||||
g.Log().Warningf(ctx, "hook.CityLabel parse err:%+v", err)
|
||||
}
|
||||
result[index]["cityLabel"] = gvar.New(cityLabel)
|
||||
return
|
||||
}
|
||||
|
||||
for i, record := range result {
|
||||
// 优先级: 区 > 市 > 省
|
||||
|
||||
cityId, ok := record["city_id"]
|
||||
if ok && !cityId.IsEmpty() {
|
||||
parse(cityId.Int64(), i)
|
||||
continue
|
||||
}
|
||||
|
||||
provinceId, ok := record["province_id"]
|
||||
if ok && !provinceId.IsEmpty() {
|
||||
parse(cityId.Int64(), i)
|
||||
continue
|
||||
}
|
||||
|
||||
// 以下是默认关联表 省市区字段
|
||||
|
||||
sysLogCityId, ok := record["sysLogCityId"]
|
||||
if ok && !sysLogCityId.IsEmpty() {
|
||||
parse(sysLogCityId.Int64(), i)
|
||||
continue
|
||||
}
|
||||
|
||||
sysLogProvinceId, ok := record["sysLogProvinceId"]
|
||||
if ok && !sysLogProvinceId.IsEmpty() {
|
||||
parse(cityId.Int64(), i)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user