This commit is contained in:
孟帅
2025-10-25 00:35:30 +08:00
parent 5ebc33f28b
commit 7313d22cdb
168 changed files with 2349 additions and 1455 deletions

View File

@@ -1,6 +1,6 @@
// Package admin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package admin
@@ -231,16 +231,26 @@ func (s *sAdminRole) Delete(ctx context.Context, in *adminin.RoleDeleteInp) (err
return gerror.New("超管角色禁止删除!")
}
has, err := dao.AdminRole.Ctx(ctx).Where("pid", models.Id).One()
exist, err := dao.AdminRole.Ctx(ctx).Where("pid", models.Id).Exist()
if err != nil {
err = gerror.Wrap(err, consts.ErrorORM)
return
}
if !has.IsEmpty() {
if exist {
return gerror.New("请先删除该角色下得所有子级!")
}
exist, err = dao.AdminMember.Ctx(ctx).Where("role_id", models.Id).Exist()
if err != nil {
err = gerror.Wrap(err, consts.ErrorORM)
return
}
if exist {
return gerror.New("请先删除该角色下得所有用户账号!")
}
if _, err = dao.AdminRole.Ctx(ctx).Where("id", in.Id).Delete(); err != nil {
err = gerror.Wrap(err, consts.ErrorORM)
}

View File

@@ -1,17 +1,24 @@
// Package common
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package common
import (
"context"
"github.com/gogf/gf/v2/net/ghttp"
"hotgo/internal/library/storager"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"hotgo/utility/file"
"hotgo/utility/format"
"time"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/grand"
)
type sCommonUpload struct{}
@@ -60,3 +67,38 @@ func (s *sCommonUpload) UploadPart(ctx context.Context, in *sysin.UploadPartInp)
res.UploadPartModel = data
return
}
// ImageTransferStorage 图片链接转存
func (s *sCommonUpload) ImageTransferStorage(ctx context.Context, in *sysin.ImageTransferStorageInp) (res *sysin.ImageTransferStorageModel, err error) {
if !gstr.HasPrefix(in.Url, "http://") && !gstr.HasPrefix(in.Url, "https://") {
return nil, gerror.New("仅支持 HTTP/HTTPS 协议的图片链接")
}
resp, err := g.Client().SetTimeout(time.Second*30).Get(ctx, in.Url)
if err != nil {
return nil, err
}
defer resp.Close()
if resp.StatusCode != 200 {
return nil, gerror.Newf("请求图片资源失败, StatusCode:%v", resp.StatusCode)
}
contentType := gstr.ToLower(resp.Header.Get("Content-Type"))
if !gstr.HasPrefix(contentType, "image/") {
return nil, gerror.New("资源不是图片类型")
}
content := resp.ReadAll()
if len(content) == 0 {
return nil, gerror.New("图片内容为空")
}
res = new(sysin.ImageTransferStorageModel)
fileHeader, err := file.NewMultipartFileHeader("its-"+grand.Letters(8)+".png", content)
if err != nil {
return nil, gerror.Newf("创建文件头失败:%v", err)
}
res.AttachmentListModel, err = s.UploadFile(ctx, storager.KindImg, &ghttp.UploadFile{FileHeader: fileHeader})
return
}

View File

@@ -1,6 +1,6 @@
// Package middleware
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package middleware
@@ -11,6 +11,7 @@ import (
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/i18n/gi18n"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gtrace"
"github.com/gogf/gf/v2/os/gctx"
@@ -56,6 +57,10 @@ func NewMiddleware() *sMiddleware {
// Ctx 初始化请求上下文
func (s *sMiddleware) Ctx(r *ghttp.Request) {
// 国际化
r.SetCtx(gi18n.WithLanguage(r.Context(), simple.GetHeaderLocale(r.Context())))
// 链路追踪
if g.Cfg().MustGet(r.Context(), "jaeger.switch").Bool() {
ctx, span := gtrace.NewSpan(r.Context(), "middleware.ctx")
span.SetAttributes(attribute.KeyValue{

View File

@@ -1,9 +1,9 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2024 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
// @AutoGenerate Version 2.17.8
package sys
import (
@@ -174,4 +174,4 @@ func (s *sSysOptionTreeDemo) TreeOption(ctx context.Context) (nodes []tree.Node,
nodes[i] = v
}
return tree.ListToTree(0, nodes)
}
}