From f30dbf34fab813ef58342339a174ceb11aafa8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=B8=85?= <133814250@qq.com> Date: Sun, 14 May 2023 23:55:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8F=91=E5=B8=83v2.7.3=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=86=85=E5=AE=B9=E8=AF=B7=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=EF=BC=9Ahttps://github.com/bufanyun/hotgo/blob/v2.0/d?= =?UTF-8?q?ocs/guide-zh-CN/start-update-log.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide-zh-CN/start-update-log.md | 5 + server/addons/hgexample/logic/sys/table.go | 2 +- server/api/admin/common/site.go | 50 +- server/api/admin/common/sms.go | 10 +- server/api/admin/member/member.go | 46 +- server/internal/consts/config.go | 43 +- server/internal/consts/status.go | 3 +- server/internal/consts/version.go | 2 +- .../internal/controller/admin/admin/member.go | 61 +-- .../controller/admin/common/console.go | 3 +- .../internal/controller/admin/common/site.go | 82 ++- .../internal/controller/admin/common/sms.go | 18 +- .../controller/admin/common/upload.go | 5 +- server/internal/dao/admin_member.go | 67 --- server/internal/dao/internal/admin_member.go | 2 + .../library/hgorm/handler/filter_auth.go | 5 + .../library/hgorm/handler/force_cache.go | 5 + server/internal/library/hgorm/hook/hook.go | 5 + server/internal/library/hgorm/hook/member.go | 5 + .../internal/library/hgorm/hook/provinces.go | 5 + server/internal/library/location/geocode.go | 5 + server/internal/library/location/region.go | 5 + server/internal/library/network/tcp/client.go | 5 + .../library/network/tcp/client_cron.go | 5 + .../library/network/tcp/client_handle.go | 5 + .../internal/library/network/tcp/context.go | 5 + server/internal/library/network/tcp/model.go | 5 + .../internal/library/network/tcp/response.go | 5 + server/internal/library/network/tcp/router.go | 5 + server/internal/library/network/tcp/rpc.go | 5 + server/internal/library/network/tcp/server.go | 5 + .../library/network/tcp/server_cron.go | 5 + .../library/network/tcp/server_handle.go | 5 + server/internal/library/network/tcp/sign.go | 5 + server/internal/logic/admin/dept.go | 2 +- server/internal/logic/admin/member.go | 397 ++++++--------- server/internal/logic/admin/notice.go | 2 +- server/internal/logic/admin/order.go | 2 +- server/internal/logic/admin/post.go | 2 +- server/internal/logic/admin/site.go | 266 ++++++++++ server/internal/logic/middleware/init.go | 5 +- server/internal/logic/pay/pay.go | 7 +- server/internal/logic/sys/attachment.go | 2 +- server/internal/logic/sys/blacklist.go | 2 +- server/internal/logic/sys/config.go | 52 +- server/internal/logic/sys/cron.go | 2 +- server/internal/logic/sys/cron_group.go | 2 +- server/internal/logic/sys/curd_demo.go | 2 +- server/internal/logic/sys/ems_log.go | 2 +- server/internal/logic/sys/gen_codes.go | 2 +- server/internal/logic/sys/login_log.go | 11 +- server/internal/logic/sys/provinces.go | 3 +- server/internal/logic/sys/sms_log.go | 9 +- server/internal/logic/tcpclient/auth.go | 1 + server/internal/logic/tcpclient/cron.go | 5 +- server/internal/model/config.go | 12 + server/internal/model/do/admin_member.go | 1 + server/internal/model/entity/admin_member.go | 1 + server/internal/model/input/adminin/member.go | 129 ++--- server/internal/model/input/adminin/site.go | 78 +++ server/internal/model/input/payin/pay.go | 7 +- .../internal/model/input/sysin/login_log.go | 4 +- server/internal/model/input/sysin/sms_log.go | 3 +- server/internal/router/admin.go | 4 +- server/internal/service/admin.go | 257 +++++----- server/internal/service/sys.go | 443 ++++++++--------- server/manifest/config/config.example.yaml | 5 +- .../generate/default/curd/logic.go.template | 2 +- server/storage/data/hotgo.sql | 469 +++++++++--------- web/.env | 4 +- web/.env.development | 3 - web/.env.production | 3 - web/build/vite/plugin/index.ts | 9 +- web/build/vite/plugin/mock.ts | 19 - web/mock/_createProductionServer.ts | 18 - web/mock/_util.ts | 73 --- web/mock/dashboard/console.ts | 44 -- web/mock/system/menu.ts | 89 ---- web/mock/system/role.ts | 46 -- web/mock/table/list.ts | 40 -- web/mock/user/menus.ts | 53 -- web/mock/user/user.ts | 60 --- web/package.json | 3 +- web/src/api/system/user.ts | 52 +- web/src/api/table/list.ts | 10 - web/src/enums/apiEnum.ts | 5 +- web/src/hooks/setting/index.ts | 3 - web/src/layout/components/Logo/index.vue | 8 +- web/src/router/router-guards.ts | 4 + web/src/store/modules/user.ts | 62 ++- web/src/store/mutation-types.ts | 3 +- web/src/utils/env.ts | 2 - web/src/views/curdDemo/edit.vue | 2 +- web/src/views/login/components/form-other.vue | 64 +++ web/src/views/login/components/style.less | 68 +++ web/src/views/login/index.vue | 322 +++++------- web/src/views/login/login/demo-account.vue | 47 ++ web/src/views/login/login/form.vue | 311 ++++++++++++ web/src/views/login/login/index.vue | 22 + web/src/views/login/register/agreement.vue | 53 ++ web/src/views/login/register/index.vue | 278 +++++++++++ .../serve-monitor/components/DataItem.vue | 7 +- .../components/chart/FullYearSalesChart.vue | 20 +- .../components/chart/LoadChart.vue | 9 +- web/src/views/org/user/list.vue | 105 +++- web/src/views/system/config/BasicSetting.vue | 18 - web/src/views/system/config/LoginSetting.vue | 173 +++++++ web/src/views/system/config/system.vue | 13 +- web/types/config.d.ts | 3 - web/types/global.d.ts | 2 - web/vite.config.ts | 5 +- 111 files changed, 2853 insertions(+), 1969 deletions(-) create mode 100644 server/internal/logic/admin/site.go create mode 100644 server/internal/model/input/adminin/site.go delete mode 100644 web/build/vite/plugin/mock.ts delete mode 100644 web/mock/_createProductionServer.ts delete mode 100644 web/mock/_util.ts delete mode 100644 web/mock/dashboard/console.ts delete mode 100644 web/mock/system/menu.ts delete mode 100644 web/mock/system/role.ts delete mode 100644 web/mock/table/list.ts delete mode 100644 web/mock/user/menus.ts delete mode 100644 web/mock/user/user.ts delete mode 100644 web/src/api/table/list.ts create mode 100644 web/src/views/login/components/form-other.vue create mode 100644 web/src/views/login/components/style.less create mode 100644 web/src/views/login/login/demo-account.vue create mode 100644 web/src/views/login/login/form.vue create mode 100644 web/src/views/login/login/index.vue create mode 100644 web/src/views/login/register/agreement.vue create mode 100644 web/src/views/login/register/index.vue create mode 100644 web/src/views/system/config/LoginSetting.vue diff --git a/docs/guide-zh-CN/start-update-log.md b/docs/guide-zh-CN/start-update-log.md index 0270a5a..d78ae1b 100644 --- a/docs/guide-zh-CN/start-update-log.md +++ b/docs/guide-zh-CN/start-update-log.md @@ -11,6 +11,11 @@ > 如果升级(覆盖)代码后打开会出现 sql 报错, 请检查更新的数据库格式或自行调整 +### v2.7.3 +updated 2023.05.14 +- 增加:增加注册、手机号登录、二维码邀请注册功能 +- 优化:优化管理员业务模块验证唯一属性接口,将登录相关功能拆分到管理员基础模块中 +- 移除:移除web端mock插件 ### v2.6.10 updated 2023.05.12 diff --git a/server/addons/hgexample/logic/sys/table.go b/server/addons/hgexample/logic/sys/table.go index 190bf1a..faedc65 100644 --- a/server/addons/hgexample/logic/sys/table.go +++ b/server/addons/hgexample/logic/sys/table.go @@ -189,7 +189,7 @@ func (s *sSysTable) Status(ctx context.Context, in sysin.TableStatusInp) (err er return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/api/admin/common/site.go b/server/api/admin/common/site.go index b8052a1..0580f2b 100644 --- a/server/api/admin/common/site.go +++ b/server/api/admin/common/site.go @@ -7,6 +7,7 @@ package common import ( "github.com/gogf/gf/v2/frame/g" + "hotgo/internal/model" "hotgo/internal/model/input/adminin" ) @@ -16,6 +17,15 @@ type LoginLogoutReq struct { } type LoginLogoutRes struct{} +// RegisterReq 提交账号注册 +type RegisterReq struct { + g.Meta `path:"/site/register" method:"post" tags:"后台基础" summary:"账号注册"` + adminin.RegisterInp +} +type RegisterRes struct { + *adminin.LoginModel +} + // LoginCaptchaReq 获取登录验证码 type LoginCaptchaReq struct { g.Meta `path:"/site/captcha" method:"get" tags:"后台基础" summary:"获取登录验证码"` @@ -25,17 +35,22 @@ type LoginCaptchaRes struct { Base64 string `json:"base64" dc:"验证码"` } -// LoginReq 提交登录 -type LoginReq struct { - g.Meta `path:"/site/login" method:"post" tags:"后台基础" summary:"账号登录"` - Username string `json:"username" v:"required#用户名不能为空" dc:"用户名"` - Password string `json:"password" v:"required#密码不能为空" dc:"密码"` - Cid string `json:"cid" dc:"验证码ID"` - Code string `json:"code" dc:"验证码"` - IsLock bool `json:"isLock" dc:"是否为锁屏状态"` +// AccountLoginReq 提交账号登录 +type AccountLoginReq struct { + g.Meta `path:"/site/accountLogin" method:"post" tags:"后台基础" summary:"账号登录"` + adminin.AccountLoginInp } -type LoginRes struct { - *adminin.MemberLoginModel +type AccountLoginRes struct { + *adminin.LoginModel +} + +// MobileLoginReq 提交手机号登录 +type MobileLoginReq struct { + g.Meta `path:"/site/mobileLogin" method:"post" tags:"后台基础" summary:"手机号登录"` + adminin.MobileLoginInp +} +type MobileLoginRes struct { + *adminin.LoginModel } // SiteConfigReq 获取配置 @@ -43,9 +58,18 @@ type SiteConfigReq struct { g.Meta `path:"/site/config" method:"get" tags:"后台基础" summary:"获取配置"` } type SiteConfigRes struct { - Version string `json:"version" dc:"系统版本"` - WsAddr string `json:"wsAddr" dc:"客户端websocket地址"` - Domain string `json:"domain" dc:"对外域名"` + Version string `json:"version" dc:"系统版本"` + WsAddr string `json:"wsAddr" dc:"客户端websocket地址"` + Domain string `json:"domain" dc:"对外域名"` + //InviteUrl string `json:"inviteUrl" dc:"邀请注册地址"` +} + +// SiteLoginConfigReq 获取登录配置 +type SiteLoginConfigReq struct { + g.Meta `path:"/site/loginConfig" method:"get" tags:"后台基础" summary:"获取登录配置"` +} +type SiteLoginConfigRes struct { + *model.LoginConfig } // SitePingReq ping diff --git a/server/api/admin/common/sms.go b/server/api/admin/common/sms.go index ad79af8..f383755 100644 --- a/server/api/admin/common/sms.go +++ b/server/api/admin/common/sms.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package common import "github.com/gogf/gf/v2/frame/g" @@ -24,3 +23,12 @@ type SendBindSmsReq struct { } type SendBindSmsRes struct { } + +// SendSmsReq 发送短信 +type SendSmsReq struct { + g.Meta `path:"/sms/send" tags:"短信" method:"post" summary:"发送短信"` + Event string `json:"event" v:"required#事件模板不能为空" dc:"事件模板"` + Mobile string `json:"mobile" v:"required#接收手机号不能为空" dc:"接收手机号"` +} +type SendSmsRes struct { +} diff --git a/server/api/admin/member/member.go b/server/api/admin/member/member.go index dbcb1ce..5de114e 100644 --- a/server/api/admin/member/member.go +++ b/server/api/admin/member/member.go @@ -53,33 +53,6 @@ type ResetPwdReq struct { } type ResetPwdRes struct{} -// EmailUniqueReq 邮箱是否唯一 -type EmailUniqueReq struct { - g.Meta `path:"/member/emailUnique" method:"get" tags:"用户" summary:"邮箱是否唯一"` - adminin.MemberEmailUniqueInp -} -type EmailUniqueRes struct { - *adminin.MemberEmailUniqueModel -} - -// MobileUniqueReq 手机号是否唯一 -type MobileUniqueReq struct { - g.Meta `path:"/member/mobileUnique" method:"get" tags:"用户" summary:"手机号是否唯一"` - adminin.MemberMobileUniqueInp -} -type MobileUniqueRes struct { - *adminin.MemberMobileUniqueModel -} - -// NameUniqueReq 名称是否唯一 -type NameUniqueReq struct { - g.Meta `path:"/member/nameUnique" method:"get" tags:"用户" summary:"用户名称是否唯一"` - adminin.MemberNameUniqueInp -} -type NameUniqueRes struct { - *adminin.MemberNameUniqueModel -} - // ListReq 查询列表 type ListReq struct { g.Meta `path:"/member/list" method:"get" tags:"用户" summary:"获取用户列表"` @@ -114,15 +87,6 @@ type DeleteReq struct { } type DeleteRes struct{} -// LoginInfoReq 获取登录用户信息 -type LoginInfoReq struct { - g.Meta `path:"/member/info" method:"get" tags:"用户" summary:"获取登录用户信息" dc:"获取管理后台的登录用户信息"` -} - -type LoginInfoRes struct { - *adminin.LoginMemberInfoModel -} - // StatusReq 更新用户状态 type StatusReq struct { g.Meta `path:"/member/status" method:"post" tags:"用户" summary:"更新用户状态"` @@ -132,10 +96,18 @@ type StatusRes struct{} // SelectReq 获取可选的后台用户选项 type SelectReq struct { - g.Meta `path:"/member/option" method:"get" summary:"用户" tags:"获取可选的后台用户选项"` + g.Meta `path:"/member/option" method:"get" tags:"用户" summary:"获取可选的后台用户选项"` } type SelectRes []*adminin.MemberSelectModel +// InfoReq 获取登录用户信息 +type InfoReq struct { + g.Meta `path:"/member/info" method:"get" tags:"用户" summary:"获取登录用户信息"` +} +type InfoRes struct { + *adminin.LoginMemberInfoModel +} + // AddBalanceReq 增加余额 type AddBalanceReq struct { g.Meta `path:"/member/addBalance" method:"post" tags:"用户" summary:"增加余额"` diff --git a/server/internal/consts/config.go b/server/internal/consts/config.go index 6d13dba..4039745 100644 --- a/server/internal/consts/config.go +++ b/server/internal/consts/config.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package consts import "github.com/gogf/gf/v2/util/gconv" @@ -13,22 +12,25 @@ var RequestEncryptKey = []byte("f080a463654b2279") // 配置数据类型 const ( - ConfigTypeString = "string" - ConfigTypeInt = "int" - ConfigTypeInt8 = "int8" - ConfigTypeInt16 = "int16" - ConfigTypeInt32 = "int32" - ConfigTypeInt64 = "int64" - ConfigTypeUint = "uint" - ConfigTypeUint8 = "uint8" - ConfigTypeUint16 = "uint16" - ConfigTypeUint32 = "uint32" - ConfigTypeUint64 = "uint64" - ConfigTypeFloat32 = "float32" - ConfigTypeFloat64 = "float64" - ConfigTypeBool = "bool" - ConfigTypeDate = "date" - ConfigTypeDateTime = "datetime" + ConfigTypeString = "string" + ConfigTypeInt = "int" + ConfigTypeInt8 = "int8" + ConfigTypeInt16 = "int16" + ConfigTypeInt32 = "int32" + ConfigTypeInt64 = "int64" + ConfigTypeUint = "uint" + ConfigTypeUint8 = "uint8" + ConfigTypeUint16 = "uint16" + ConfigTypeUint32 = "uint32" + ConfigTypeUint64 = "uint64" + ConfigTypeFloat32 = "float32" + ConfigTypeFloat64 = "float64" + ConfigTypeBool = "bool" + ConfigTypeDate = "date" + ConfigTypeDateTime = "datetime" + ConfigTypeSliceString = "[]string" + ConfigTypeSliceInt = "[]int" + ConfigTypeSliceInt64 = "[]int64" ) var ConfigTypes = []string{ConfigTypeString, @@ -37,6 +39,7 @@ var ConfigTypes = []string{ConfigTypeString, ConfigTypeFloat32, ConfigTypeFloat64, ConfigTypeBool, ConfigTypeDate, ConfigTypeDateTime, + ConfigTypeSliceString, ConfigTypeSliceInt, ConfigTypeSliceInt64, } // ConvType 类型转换 @@ -74,6 +77,12 @@ func ConvType(val interface{}, t string) interface{} { val = gconv.Time(val, "Y-m-d") case ConfigTypeDateTime: val = gconv.Time(val, "Y-m-d H:i:s") + case ConfigTypeSliceInt: + val = gconv.SliceInt(val) + case ConfigTypeSliceInt64: + val = gconv.SliceInt64(val) + case ConfigTypeSliceString: + val = gconv.SliceStr(val) default: val = gconv.String(val) } diff --git a/server/internal/consts/status.go b/server/internal/consts/status.go index ee7ddf7..274fe9d 100644 --- a/server/internal/consts/status.go +++ b/server/internal/consts/status.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package consts // 状态码 @@ -14,4 +13,4 @@ const ( StatusDelete int = 3 // 已删除 ) -var StatusMap = []int{StatusALL, StatusEnabled, StatusDisable, StatusDelete} +var StatusSlice = []int{StatusALL, StatusEnabled, StatusDisable, StatusDelete} diff --git a/server/internal/consts/version.go b/server/internal/consts/version.go index ff737c9..50ec7a9 100644 --- a/server/internal/consts/version.go +++ b/server/internal/consts/version.go @@ -7,5 +7,5 @@ package consts // VersionApp HotGo版本 const ( - VersionApp = "2.6.10" + VersionApp = "2.7.3" ) diff --git a/server/internal/controller/admin/admin/member.go b/server/internal/controller/admin/admin/member.go index df7b477..da3ed1b 100644 --- a/server/internal/controller/admin/admin/member.go +++ b/server/internal/controller/admin/admin/member.go @@ -96,54 +96,15 @@ func (c *cMember) ResetPwd(ctx context.Context, req *member.ResetPwdReq) (res *m return } -// EmailUnique 邮箱是否唯一 -func (c *cMember) EmailUnique(ctx context.Context, req *member.EmailUniqueReq) (res *member.EmailUniqueRes, err error) { - var in = adminin.MemberEmailUniqueInp{ - Id: req.Id, - Email: req.Email, - } - - data, err := service.AdminMember().EmailUnique(ctx, in) +// MemberInfo 登录用户信息 +func (c *cMember) MemberInfo(ctx context.Context, _ *member.InfoReq) (res *member.InfoRes, err error) { + data, err := service.AdminMember().LoginMemberInfo(ctx) if err != nil { return } - res = new(member.EmailUniqueRes) - res.IsUnique = data.IsUnique - return -} - -// MobileUnique 手机号是否唯一 -func (c *cMember) MobileUnique(ctx context.Context, req *member.MobileUniqueReq) (res *member.MobileUniqueRes, err error) { - var in = adminin.MemberMobileUniqueInp{ - Id: req.Id, - Mobile: req.Mobile, - } - - data, err := service.AdminMember().MobileUnique(ctx, in) - if err != nil { - return - } - - res = new(member.MobileUniqueRes) - res.IsUnique = data.IsUnique - return -} - -// NameUnique 名称是否唯一 -func (c *cMember) NameUnique(ctx context.Context, req *member.NameUniqueReq) (res *member.NameUniqueRes, err error) { - var in = adminin.MemberNameUniqueInp{ - Id: req.Id, - Username: req.Username, - } - - data, err := service.AdminMember().NameUnique(ctx, in) - if err != nil { - return - } - - res = new(member.NameUniqueRes) - res.IsUnique = data.IsUnique + res = new(member.InfoRes) + res.LoginMemberInfoModel = data return } @@ -206,18 +167,6 @@ func (c *cMember) List(ctx context.Context, req *member.ListReq) (res *member.Li return } -// LoginInfo 登录用户信息 -func (c *cMember) LoginInfo(ctx context.Context, req *member.LoginInfoReq) (res *member.LoginInfoRes, err error) { - data, err := service.AdminMember().LoginMemberInfo(ctx) - if err != nil { - return - } - - res = new(member.LoginInfoRes) - res.LoginMemberInfoModel = data - return -} - // Status 更新状态 func (c *cMember) Status(ctx context.Context, req *member.StatusReq) (res *member.StatusRes, err error) { var in adminin.MemberStatusInp diff --git a/server/internal/controller/admin/common/console.go b/server/internal/controller/admin/common/console.go index 8558aee..30c44c8 100644 --- a/server/internal/controller/admin/common/console.go +++ b/server/internal/controller/admin/common/console.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package common import ( @@ -16,7 +15,7 @@ var Console = cConsole{} type cConsole struct{} // Stat 综合数据统计 -func (c *cConsole) Stat(ctx context.Context, req *common.ConsoleStatReq) (res *common.ConsoleStatRes, err error) { +func (c *cConsole) Stat(_ context.Context, _ *common.ConsoleStatReq) (res *common.ConsoleStatRes, err error) { res = new(common.ConsoleStatRes) res.Visits.DayVisits = 12010 diff --git a/server/internal/controller/admin/common/site.go b/server/internal/controller/admin/common/site.go index 22ec469..fc93cda 100644 --- a/server/internal/controller/admin/common/site.go +++ b/server/internal/controller/admin/common/site.go @@ -16,7 +16,6 @@ import ( "hotgo/internal/library/captcha" "hotgo/internal/library/token" "hotgo/internal/model/input/adminin" - "hotgo/internal/model/input/sysin" "hotgo/internal/service" "hotgo/utility/validate" ) @@ -26,17 +25,18 @@ var Site = cSite{} type cSite struct{} // Ping ping -func (c *cSite) Ping(ctx context.Context, req *common.SitePingReq) (res *common.SitePingRes, err error) { +func (c *cSite) Ping(_ context.Context, _ *common.SitePingReq) (res *common.SitePingRes, err error) { return } // Config 获取配置 -func (c *cSite) Config(ctx context.Context, req *common.SiteConfigReq) (res *common.SiteConfigRes, err error) { +func (c *cSite) Config(ctx context.Context, _ *common.SiteConfigReq) (res *common.SiteConfigRes, err error) { request := ghttp.RequestFromCtx(ctx) res = &common.SiteConfigRes{ Version: consts.VersionApp, WsAddr: c.getWsAddr(ctx, request), Domain: c.getDomain(ctx, request), + //InviteUrl: "http://192.168.1.27:8001/#/login?scope=register&inviteCode=", } return } @@ -71,35 +71,77 @@ func (c *cSite) getDomain(ctx context.Context, request *ghttp.Request) string { return basic.Domain } +// LoginConfig 登录配置 +func (c *cSite) LoginConfig(ctx context.Context, _ *common.SiteLoginConfigReq) (res *common.SiteLoginConfigRes, err error) { + res = new(common.SiteLoginConfigRes) + login, err := service.SysConfig().GetLogin(ctx) + if err != nil { + return + } + + res.LoginConfig = login + return +} + // Captcha 登录验证码 -func (c *cSite) Captcha(ctx context.Context, req *common.LoginCaptchaReq) (res *common.LoginCaptchaRes, err error) { +func (c *cSite) Captcha(ctx context.Context, _ *common.LoginCaptchaReq) (res *common.LoginCaptchaRes, err error) { cid, base64 := captcha.Generate(ctx) res = &common.LoginCaptchaRes{Cid: cid, Base64: base64} return } -// Login 提交登录 -func (c *cSite) Login(ctx context.Context, req *common.LoginReq) (res *common.LoginRes, err error) { - var in adminin.MemberLoginInp +// Register 账号注册 +func (c *cSite) Register(ctx context.Context, req *common.RegisterReq) (res *common.RegisterRes, err error) { + var in adminin.RegisterInp if err = gconv.Scan(req, &in); err != nil { return } - defer func() { - var response = new(adminin.MemberLoginModel) - if res != nil && res.MemberLoginModel != nil { - response = res.MemberLoginModel - } - service.SysLoginLog().Push(ctx, sysin.LoginLogPushInp{Input: in, Response: response, Err: err}) - }() - - // 校验 验证码 - if !req.IsLock && !captcha.Verify(req.Cid, req.Code) { - err = gerror.New("验证码错误") + if err = validate.PreFilter(ctx, &in); err != nil { return } - model, err := service.AdminMember().Login(ctx, in) + err = service.AdminSite().Register(ctx, in) + return +} + +// AccountLogin 账号登录 +func (c *cSite) AccountLogin(ctx context.Context, req *common.AccountLoginReq) (res *common.AccountLoginRes, err error) { + var in adminin.AccountLoginInp + if err = gconv.Scan(req, &in); err != nil { + return + } + + login, err := service.SysConfig().GetLogin(ctx) + if err != nil { + return + } + + if login.CaptchaSwitch == 1 { + // 校验 验证码 + if !req.IsLock && !captcha.Verify(req.Cid, req.Code) { + err = gerror.New("验证码错误") + return + } + } + + model, err := service.AdminSite().AccountLogin(ctx, in) + if err != nil { + return + } + + err = gconv.Scan(model, &res) + return +} + +// MobileLogin 手机号登录 +func (c *cSite) MobileLogin(ctx context.Context, req *common.MobileLoginReq) (res *common.MobileLoginRes, err error) { + var in adminin.MobileLoginInp + if err = gconv.Scan(req, &in); err != nil { + return + } + + model, err := service.AdminSite().MobileLogin(ctx, in) if err != nil { return } @@ -109,7 +151,7 @@ func (c *cSite) Login(ctx context.Context, req *common.LoginReq) (res *common.Lo } // Logout 注销登录 -func (c *cSite) Logout(ctx context.Context, req *common.LoginLogoutReq) (res *common.LoginLogoutRes, err error) { +func (c *cSite) Logout(ctx context.Context, _ *common.LoginLogoutReq) (res *common.LoginLogoutRes, err error) { err = token.Logout(ghttp.RequestFromCtx(ctx)) return } diff --git a/server/internal/controller/admin/common/sms.go b/server/internal/controller/admin/common/sms.go index a5d557e..573d93e 100644 --- a/server/internal/controller/admin/common/sms.go +++ b/server/internal/controller/admin/common/sms.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package common import ( @@ -40,7 +39,7 @@ func (c *cSms) SendTest(ctx context.Context, req *common.SendTestSmsReq) (res *c } // SendBindSms 发送换绑短信 -func (c *cSms) SendBindSms(ctx context.Context, req *common.SendBindSmsReq) (res *common.SendBindSmsRes, err error) { +func (c *cSms) SendBindSms(ctx context.Context, _ *common.SendBindSmsReq) (res *common.SendBindSmsRes, err error) { var ( memberId = contexts.GetUserId(ctx) models *entity.AdminMember @@ -75,3 +74,18 @@ func (c *cSms) SendBindSms(ctx context.Context, req *common.SendBindSmsReq) (res }) return } + +// SendSms 发送短信 +func (c *cSms) SendSms(ctx context.Context, req *common.SendSmsReq) (res *common.SendSmsRes, err error) { + var in sysin.SendCodeInp + if err = gconv.Scan(req, &in); err != nil { + return + } + + if err = validate.PreFilter(ctx, &in); err != nil { + return + } + + err = service.SysSmsLog().SendCode(ctx, in) + return +} diff --git a/server/internal/controller/admin/common/upload.go b/server/internal/controller/admin/common/upload.go index 992295c..9d13d5d 100644 --- a/server/internal/controller/admin/common/upload.go +++ b/server/internal/controller/admin/common/upload.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package common import ( @@ -19,7 +18,7 @@ var Upload = new(cUpload) type cUpload struct{} // UploadImage 上传图片 -func (c *cUpload) UploadImage(ctx context.Context, req *common.UploadImageReq) (res common.UploadImageRes, err error) { +func (c *cUpload) UploadImage(ctx context.Context, _ *common.UploadImageReq) (res common.UploadImageRes, err error) { file := g.RequestFromCtx(ctx).GetUploadFile("file") if file == nil { err = gerror.New("没有找到上传的文件") @@ -30,7 +29,7 @@ func (c *cUpload) UploadImage(ctx context.Context, req *common.UploadImageReq) ( } // UploadFile 上传附件 -func (c *cUpload) UploadFile(ctx context.Context, req *common.UploadFileReq) (res common.UploadFileRes, err error) { +func (c *cUpload) UploadFile(ctx context.Context, _ *common.UploadFileReq) (res common.UploadFileRes, err error) { file := g.RequestFromCtx(ctx).GetUploadFile("file") if file == nil { err = gerror.New("没有找到上传的文件") diff --git a/server/internal/dao/admin_member.go b/server/internal/dao/admin_member.go index d2ba4c3..d6d13ef 100644 --- a/server/internal/dao/admin_member.go +++ b/server/internal/dao/admin_member.go @@ -5,11 +5,7 @@ package dao import ( - "context" - "github.com/gogf/gf/v2/errors/gerror" - "hotgo/internal/consts" "hotgo/internal/dao/internal" - "hotgo/internal/model/entity" ) // internalAdminMemberDao is internal type for wrapping internal DAO implements. @@ -29,66 +25,3 @@ var ( ) // Fill with you ideas below. - -// IsUniqueName 判断用户名是否唯一 -func (dao *adminMemberDao) IsUniqueName(ctx context.Context, id int64, name string) (bool, error) { - var data *entity.AdminDept - m := dao.Ctx(ctx).Where("username", name) - - if id > 0 { - m = m.WhereNot("id", id) - } - - if err := m.Scan(&data); err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return false, err - } - - if data == nil { - return true, nil - } - - return false, nil -} - -// IsUniqueEmail 判断邮箱是否唯一 -func (dao *adminMemberDao) IsUniqueEmail(ctx context.Context, id int64, email string) (bool, error) { - var data *entity.AdminMember - m := dao.Ctx(ctx).Where("email", email) - - if id > 0 { - m = m.WhereNot("id", id) - } - - if err := m.Scan(&data); err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return false, err - } - - if data == nil { - return true, nil - } - - return false, nil -} - -// IsUniqueMobile 判断手机号是否唯一 -func (dao *adminMemberDao) IsUniqueMobile(ctx context.Context, id int64, mobile string) (bool, error) { - var data *entity.AdminMember - m := dao.Ctx(ctx).Where("mobile", mobile) - - if id > 0 { - m = m.WhereNot("id", id) - } - - if err := m.Scan(&data); err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return false, err - } - - if data == nil { - return true, nil - } - - return false, nil -} diff --git a/server/internal/dao/internal/admin_member.go b/server/internal/dao/internal/admin_member.go index 3ed51dd..48a77fa 100644 --- a/server/internal/dao/internal/admin_member.go +++ b/server/internal/dao/internal/admin_member.go @@ -41,6 +41,7 @@ type AdminMemberColumns struct { Pid string // 上级管理员ID Level string // 关系树等级 Tree string // 关系树 + InviteCode string // 邀请码 Cash string // 提现配置 LastActiveAt string // 最后活跃时间 Remark string // 备注 @@ -72,6 +73,7 @@ var adminMemberColumns = AdminMemberColumns{ Pid: "pid", Level: "level", Tree: "tree", + InviteCode: "invite_code", Cash: "cash", LastActiveAt: "last_active_at", Remark: "remark", diff --git a/server/internal/library/hgorm/handler/filter_auth.go b/server/internal/library/hgorm/handler/filter_auth.go index 843520f..558b149 100644 --- a/server/internal/library/hgorm/handler/filter_auth.go +++ b/server/internal/library/hgorm/handler/filter_auth.go @@ -1,3 +1,8 @@ +// Package handler +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package handler import ( diff --git a/server/internal/library/hgorm/handler/force_cache.go b/server/internal/library/hgorm/handler/force_cache.go index edfb85f..a59f2a5 100644 --- a/server/internal/library/hgorm/handler/force_cache.go +++ b/server/internal/library/hgorm/handler/force_cache.go @@ -1,3 +1,8 @@ +// Package handler +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package handler import ( diff --git a/server/internal/library/hgorm/hook/hook.go b/server/internal/library/hgorm/hook/hook.go index 2b894e6..abd78d5 100644 --- a/server/internal/library/hgorm/hook/hook.go +++ b/server/internal/library/hgorm/hook/hook.go @@ -1,3 +1,8 @@ +// Package hook +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package hook // hook. diff --git a/server/internal/library/hgorm/hook/member.go b/server/internal/library/hgorm/hook/member.go index ce1f3da..0513015 100644 --- a/server/internal/library/hgorm/hook/member.go +++ b/server/internal/library/hgorm/hook/member.go @@ -1,3 +1,8 @@ +// Package hook +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package hook import ( diff --git a/server/internal/library/hgorm/hook/provinces.go b/server/internal/library/hgorm/hook/provinces.go index 0cf0c1f..7027986 100644 --- a/server/internal/library/hgorm/hook/provinces.go +++ b/server/internal/library/hgorm/hook/provinces.go @@ -1,3 +1,8 @@ +// Package hook +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package hook import ( diff --git a/server/internal/library/location/geocode.go b/server/internal/library/location/geocode.go index ccb5575..94e1153 100644 --- a/server/internal/library/location/geocode.go +++ b/server/internal/library/location/geocode.go @@ -1,3 +1,8 @@ +// Package location +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package location import ( diff --git a/server/internal/library/location/region.go b/server/internal/library/location/region.go index cf6cdba..96246bc 100644 --- a/server/internal/library/location/region.go +++ b/server/internal/library/location/region.go @@ -1,3 +1,8 @@ +// Package location +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package location import ( diff --git a/server/internal/library/network/tcp/client.go b/server/internal/library/network/tcp/client.go index 0217b0b..c55dd37 100644 --- a/server/internal/library/network/tcp/client.go +++ b/server/internal/library/network/tcp/client.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/client_cron.go b/server/internal/library/network/tcp/client_cron.go index c232605..75a6368 100644 --- a/server/internal/library/network/tcp/client_cron.go +++ b/server/internal/library/network/tcp/client_cron.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/client_handle.go b/server/internal/library/network/tcp/client_handle.go index 227c20c..a003dfa 100644 --- a/server/internal/library/network/tcp/client_handle.go +++ b/server/internal/library/network/tcp/client_handle.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/context.go b/server/internal/library/network/tcp/context.go index 176c636..87fa0fc 100644 --- a/server/internal/library/network/tcp/context.go +++ b/server/internal/library/network/tcp/context.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/model.go b/server/internal/library/network/tcp/model.go index ce5411b..2b16435 100644 --- a/server/internal/library/network/tcp/model.go +++ b/server/internal/library/network/tcp/model.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/response.go b/server/internal/library/network/tcp/response.go index c3c53aa..f1584d2 100644 --- a/server/internal/library/network/tcp/response.go +++ b/server/internal/library/network/tcp/response.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp type Response interface { diff --git a/server/internal/library/network/tcp/router.go b/server/internal/library/network/tcp/router.go index 6751c52..c449d82 100644 --- a/server/internal/library/network/tcp/router.go +++ b/server/internal/library/network/tcp/router.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/rpc.go b/server/internal/library/network/tcp/rpc.go index 7459d3f..6aee4e1 100644 --- a/server/internal/library/network/tcp/rpc.go +++ b/server/internal/library/network/tcp/rpc.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/server.go b/server/internal/library/network/tcp/server.go index 3bbbb6c..47fa078 100644 --- a/server/internal/library/network/tcp/server.go +++ b/server/internal/library/network/tcp/server.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/server_cron.go b/server/internal/library/network/tcp/server_cron.go index c8b31bd..bdf3b2d 100644 --- a/server/internal/library/network/tcp/server_cron.go +++ b/server/internal/library/network/tcp/server_cron.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/server_handle.go b/server/internal/library/network/tcp/server_handle.go index 52d7e99..dfbf99a 100644 --- a/server/internal/library/network/tcp/server_handle.go +++ b/server/internal/library/network/tcp/server_handle.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/library/network/tcp/sign.go b/server/internal/library/network/tcp/sign.go index 818f591..db4bae6 100644 --- a/server/internal/library/network/tcp/sign.go +++ b/server/internal/library/network/tcp/sign.go @@ -1,3 +1,8 @@ +// Package tcp +// @Link https://github.com/bufanyun/hotgo +// @Copyright Copyright (c) 2023 HotGo CLI +// @Author Ms <133814250@qq.com> +// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE package tcp import ( diff --git a/server/internal/logic/admin/dept.go b/server/internal/logic/admin/dept.go index a4345e7..1fa89e7 100644 --- a/server/internal/logic/admin/dept.go +++ b/server/internal/logic/admin/dept.go @@ -112,7 +112,7 @@ func (s *sAdminDept) Status(ctx context.Context, in adminin.DeptStatusInp) (err return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/admin/member.go b/server/internal/logic/admin/member.go index 087648a..9ae2a08 100644 --- a/server/internal/logic/admin/member.go +++ b/server/internal/logic/admin/member.go @@ -19,16 +19,13 @@ import ( "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/library/contexts" + "hotgo/internal/library/hgorm" "hotgo/internal/library/hgorm/handler" "hotgo/internal/library/hgorm/hook" - "hotgo/internal/library/token" - "hotgo/internal/model" - "hotgo/internal/model/do" "hotgo/internal/model/entity" "hotgo/internal/model/input/adminin" "hotgo/internal/model/input/sysin" "hotgo/internal/service" - "hotgo/utility/simple" "hotgo/utility/tree" "hotgo/utility/validate" ) @@ -157,7 +154,7 @@ func (s *sAdminMember) UpdateCash(ctx context.Context, in adminin.MemberUpdateCa _, err = dao.AdminMember.Ctx(ctx). Where("id", memberId). Data(g.Map{ - "cash": adminin.MemberCash{ + dao.AdminMember.Columns().Cash: adminin.MemberCash{ Name: in.Name, Account: in.Account, PayeeCode: in.PayeeCode, @@ -316,13 +313,13 @@ func (s *sAdminMember) UpdateProfile(ctx context.Context, in adminin.MemberUpdat // UpdatePwd 修改登录密码 func (s *sAdminMember) UpdatePwd(ctx context.Context, in adminin.MemberUpdatePwdInp) (err error) { - var memberInfo entity.AdminMember - if err = dao.AdminMember.Ctx(ctx).Where("id", in.Id).Scan(&memberInfo); err != nil { + var mb entity.AdminMember + if err = dao.AdminMember.Ctx(ctx).Where("id", in.Id).Scan(&mb); err != nil { err = gerror.Wrap(err, consts.ErrorORM) return err } - if gmd5.MustEncryptString(in.OldPassword+memberInfo.Salt) != memberInfo.PasswordHash { + if gmd5.MustEncryptString(in.OldPassword+mb.Salt) != mb.PasswordHash { err = gerror.New("原密码不正确") return err } @@ -330,10 +327,10 @@ func (s *sAdminMember) UpdatePwd(ctx context.Context, in adminin.MemberUpdatePwd _, err = dao.AdminMember.Ctx(ctx). Where("id", in.Id). Data(g.Map{ - "password_hash": gmd5.MustEncryptString(in.NewPassword + memberInfo.Salt), - "updated_at": gtime.Now(), + dao.AdminMember.Columns().PasswordHash: gmd5.MustEncryptString(in.NewPassword + mb.Salt), }). Update() + if err != nil { err = gerror.Wrap(err, consts.ErrorORM) return err @@ -362,61 +359,40 @@ func (s *sAdminMember) ResetPwd(ctx context.Context, in adminin.MemberResetPwdIn _, err = s.FilterAuthModel(ctx, memberId). Where("id", in.Id). Data(g.Map{ - "password_hash": gmd5.MustEncryptString(in.Password + mb.Salt), - "updated_at": gtime.Now(), + dao.AdminMember.Columns().PasswordHash: gmd5.MustEncryptString(in.Password + mb.Salt), }). Update() return } -// EmailUnique 菜单名称是否唯一 -func (s *sAdminMember) EmailUnique(ctx context.Context, in adminin.MemberEmailUniqueInp) (res *adminin.MemberEmailUniqueModel, err error) { - isUnique, err := dao.AdminMember.IsUniqueEmail(ctx, in.Id, in.Email) - if err != nil { - err = gerror.Wrap(err, consts.ErrorORM) +// VerifyUnique 验证管理员唯一属性 +func (s *sAdminMember) VerifyUnique(ctx context.Context, in adminin.VerifyUniqueInp) (err error) { + if in.Where == nil { return } - res = new(adminin.MemberEmailUniqueModel) - res.IsUnique = isUnique - return -} - -// MobileUnique 手机号是否唯一 -func (s *sAdminMember) MobileUnique(ctx context.Context, in adminin.MemberMobileUniqueInp) (res *adminin.MemberMobileUniqueModel, err error) { - isUnique, err := dao.AdminMember.IsUniqueMobile(ctx, in.Id, in.Mobile) - if err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return + msgMap := g.MapStrStr{ + "username": "用户名已存在,请换一个", + "email": "邮箱已存在,请换一个", + "mobile": "手机号已存在,请换一个", + "invite_code": "邀请码已存在,请换一个", } - res = new(adminin.MemberMobileUniqueModel) - res.IsUnique = isUnique - return -} - -// NameUnique 菜单名称是否唯一 -func (s *sAdminMember) NameUnique(ctx context.Context, in adminin.MemberNameUniqueInp) (res *adminin.MemberNameUniqueModel, err error) { - isUnique, err := dao.AdminMember.IsUniqueName(ctx, in.Id, in.Username) - if err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return - } - - res = new(adminin.MemberNameUniqueModel) - res.IsUnique = isUnique - return -} - -// VerifySuperId 验证是否为超管 -func (s *sAdminMember) VerifySuperId(ctx context.Context, verifyId int64) bool { - superIds := g.Cfg().MustGet(ctx, "hotgo.admin.superIds") - for _, id := range superIds.Int64s() { - if id == verifyId { - return true + for k, v := range in.Where { + if v == "" { + continue + } + message, ok := msgMap[k] + if !ok { + err = gerror.Newf("字段 [ %v ] 未配置唯一属性验证", k) + return + } + if err = hgorm.IsUnique(ctx, dao.AdminMember, g.Map{k: v}, message, in.Id); err != nil { + return } } - return false + + return } // Delete 删除 @@ -449,36 +425,17 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err return } - uniqueName, err := dao.AdminMember.IsUniqueName(ctx, in.Id, in.Username) + err = s.VerifyUnique(ctx, adminin.VerifyUniqueInp{ + Id: in.Id, + Where: g.Map{ + dao.AdminMember.Columns().Username: in.Username, + dao.AdminMember.Columns().Mobile: in.Mobile, + dao.AdminMember.Columns().Email: in.Email, + }, + }) if err != nil { return } - if !uniqueName { - err = gerror.New("用户名已存在") - return - } - - if in.Mobile != "" { - uniqueMobile, err := dao.AdminMember.IsUniqueMobile(ctx, in.Id, in.Mobile) - if err != nil { - return err - } - if !uniqueMobile { - err = gerror.New("手机号已存在") - return err - } - } - - if in.Email != "" { - uniqueEmail, err := dao.AdminMember.IsUniqueEmail(ctx, in.Id, in.Email) - if err != nil { - return err - } - if !uniqueEmail { - err = gerror.New("邮箱已存在") - return err - } - } // 修改 if in.Id > 0 { @@ -488,8 +445,13 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err } mod := s.FilterAuthModel(ctx, opMemberId) + if in.Password != "" { - salt, err := s.FilterAuthModel(ctx, contexts.GetUserId(ctx)).Fields(dao.AdminMember.Columns().Salt).Where("id", in.Id).Value() + // 修改密码 + salt, err := s.FilterAuthModel(ctx, contexts.GetUserId(ctx)). + Fields(dao.AdminMember.Columns().Salt). + Where("id", in.Id). + Value() if err != nil { return err } @@ -498,35 +460,39 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err mod = mod.FieldsEx(dao.AdminMember.Columns().PasswordHash) } - if _, err = mod.Where("id", in.Id).Data(in).Update(); err != nil { - return - } + return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { + if _, err = mod.Where("id", in.Id).Data(in).Update(); err != nil { + return + } - // 更新岗位 - err = dao.AdminMemberPost.UpdatePostIds(ctx, in.Id, in.PostIds) - return + // 更新岗位 + return dao.AdminMemberPost.UpdatePostIds(ctx, in.Id, in.PostIds) + }) } // 新增用户时的额外属性 var data adminin.MemberAddInp data.MemberEditInp = in data.Salt = grand.S(6) + data.InviteCode = grand.S(12) data.PasswordHash = gmd5.MustEncryptString(data.Password + data.Salt) // 关系树 data.Pid = opMemberId - data.Level, data.Tree, err = s.genTree(ctx, opMemberId) + data.Level, data.Tree, err = s.GenTree(ctx, opMemberId) if err != nil { return } - id, err := dao.AdminMember.Ctx(ctx).Data(data).InsertAndGetId() - if err != nil { - return - } + return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { + id, err := dao.AdminMember.Ctx(ctx).Data(data).InsertAndGetId() + if err != nil { + return + } - err = dao.AdminMemberPost.UpdatePostIds(ctx, id, in.PostIds) - return + // 更新岗位 + return dao.AdminMemberPost.UpdatePostIds(ctx, id, in.PostIds) + }) } // View 获取信息 @@ -589,6 +555,7 @@ func (s *sAdminMember) List(ctx context.Context, in adminin.MemberListInp) (list Fields("post_id"). Where("member_id", list[i].Id). Array() + if err != nil { return nil, 0, err } @@ -601,20 +568,68 @@ func (s *sAdminMember) List(ctx context.Context, in adminin.MemberListInp) (list return } -// genTree 生成关系树 -func (s *sAdminMember) genTree(ctx context.Context, pid int64) (level int, newTree string, err error) { - var pInfo *entity.AdminMember - if err = dao.AdminMember.Ctx(ctx).Where("id", pid).Scan(&pInfo); err != nil { +// Status 更新状态 +func (s *sAdminMember) Status(ctx context.Context, in adminin.MemberStatusInp) (err error) { + if in.Id <= 0 { + err = gerror.New("ID不能为空") return } - if pInfo == nil { + if s.VerifySuperId(ctx, in.Id) { + err = gerror.New("超管账号不能更改状态") + return + } + + if in.Status <= 0 { + err = gerror.New("状态不能为空") + return + } + + if !validate.InSliceInt(consts.StatusSlice, in.Status) { + err = gerror.New("状态不正确") + return + } + + // 修改 + in.UpdatedAt = gtime.Now() + _, err = s.FilterAuthModel(ctx, contexts.GetUserId(ctx)).Where("id", in.Id).Data("status", in.Status).Update() + return +} + +// GenTree 生成关系树 +func (s *sAdminMember) GenTree(ctx context.Context, pid int64) (level int, newTree string, err error) { + var pmb *entity.AdminMember + if err = dao.AdminMember.Ctx(ctx).Where("id", pid).Scan(&pmb); err != nil { + return + } + + if pmb == nil { err = gerror.New("上级信息不存在") return } - level = pInfo.Level + 1 - newTree = tree.GenLabel(pInfo.Tree, pInfo.Id) + level = pmb.Level + 1 + newTree = tree.GenLabel(pmb.Tree, pmb.Id) + return +} + +// RoleMemberList 获取角色下的用户列表 +func (s *sAdminMember) RoleMemberList(ctx context.Context, in adminin.RoleMemberListInp) (list []*adminin.MemberListModel, totalCount int, err error) { + mod := dao.AdminMember.Ctx(ctx) + if in.Role > 0 { + mod = mod.Where("role", in.Role) + } + + totalCount, err = mod.Count() + if err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + return + } + + if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + return + } return } @@ -626,11 +641,7 @@ func (s *sAdminMember) LoginMemberInfo(ctx context.Context) (res *adminin.LoginM return } - err = dao.AdminMember.Ctx(ctx). - Hook(hook.MemberInfo). - Where("id", memberId). - Scan(&res) - if err != nil { + if err = dao.AdminMember.Ctx(ctx).Hook(hook.MemberInfo).Where("id", memberId).Scan(&res); err != nil { err = gerror.Wrap(err, consts.ErrorORM) return } @@ -660,142 +671,36 @@ func (s *sAdminMember) LoginMemberInfo(ctx context.Context) (res *adminin.LoginM return } -// Login 提交登录 -func (s *sAdminMember) Login(ctx context.Context, in adminin.MemberLoginInp) (res *adminin.MemberLoginModel, err error) { - var ( - ro *entity.AdminRole - mb *entity.AdminMember - ) +// MemberLoginStat 用户登录统计 +func (s *sAdminMember) MemberLoginStat(ctx context.Context, in adminin.MemberLoginStatInp) (res *adminin.MemberLoginStatModel, err error) { + var models *entity.SysLoginLog + err = dao.SysLoginLog.Ctx(ctx). + Fields("login_at,login_ip"). + Where("member_id", in.MemberId). + Where("status", consts.StatusEnabled). + Scan(&models) - if err = dao.AdminMember.Ctx(ctx).Where("username", in.Username).Scan(&mb); err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return - } - - if mb == nil { - err = gerror.New("账号不存在") - return - } - - if mb.Salt == "" { - err = gerror.New("用户信息错误") - return - } - - if err = simple.CheckPassword(in.Password, mb.Salt, mb.PasswordHash); err != nil { - return - } - - if mb.Status != consts.StatusEnabled { - err = gerror.New("账号已被禁用") - return - } - - if err = dao.AdminRole.Ctx(ctx).Fields("id,key,status").Where("id", mb.RoleId).Scan(&ro); err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return - } - - if ro == nil { - err = gerror.New("角色不存在") - return - } - - if ro.Status != consts.StatusEnabled { - err = gerror.New("角色已被禁用") - return - } - - user := &model.Identity{ - Id: mb.Id, - Pid: mb.Pid, - DeptId: mb.DeptId, - RoleId: ro.Id, - RoleKey: ro.Key, - Username: mb.Username, - RealName: mb.RealName, - Avatar: mb.Avatar, - Email: mb.Email, - Mobile: mb.Mobile, - App: consts.AppAdmin, - LoginAt: gtime.Now(), - } - - loginToken, expires, err := token.Login(ctx, user) if err != nil { - return nil, err - } - - update := do.AdminMember{ - LastActiveAt: user.LoginAt, - } - - // 更新登录信息 - if _, err = dao.AdminMember.Ctx(ctx).Data(update).Where(do.AdminMember{Id: mb.Id}).Update(); err != nil { return } - res = &adminin.MemberLoginModel{ - Id: user.Id, - Token: loginToken, - Expires: expires, - } - - return -} - -// RoleMemberList 获取角色下的用户列表 -func (s *sAdminMember) RoleMemberList(ctx context.Context, in adminin.RoleMemberListInp) (list []*adminin.MemberListModel, totalCount int, err error) { - mod := dao.AdminMember.Ctx(ctx) - if in.Role > 0 { - mod = mod.Where("role", in.Role) - } - - totalCount, err = mod.Count() - if err != nil { - err = gerror.Wrap(err, consts.ErrorORM) + res = new(adminin.MemberLoginStatModel) + if models == nil { return } - if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil { - err = gerror.Wrap(err, consts.ErrorORM) - return - } - - return -} - -// Status 更新状态 -func (s *sAdminMember) Status(ctx context.Context, in adminin.MemberStatusInp) (err error) { - if in.Id <= 0 { - err = gerror.New("ID不能为空") - return - } - - if s.VerifySuperId(ctx, in.Id) { - err = gerror.New("超管账号不能更改状态") - return - } - - if in.Status <= 0 { - err = gerror.New("状态不能为空") - return - } - - if !validate.InSliceInt(consts.StatusMap, in.Status) { - err = gerror.New("状态不正确") - return - } - - // 修改 - in.UpdatedAt = gtime.Now() - _, err = s.FilterAuthModel(ctx, contexts.GetUserId(ctx)).Where("id", in.Id).Data("status", in.Status).Update() + res.LastLoginAt = models.LoginAt + res.LastLoginIp = models.LoginIp + res.LoginCount, err = dao.SysLoginLog.Ctx(ctx). + Where("member_id", in.MemberId). + Where("status", consts.StatusEnabled). + Count() return } // GetIdByCode 通过邀请码获取用户ID func (s *sAdminMember) GetIdByCode(ctx context.Context, in adminin.GetIdByCodeInp) (res *adminin.GetIdByCodeModel, err error) { - err = dao.AdminMember.Ctx(ctx).Fields("invite_code").Where("invite_code", in.Code).Scan(&res) + err = dao.AdminMember.Ctx(ctx).Fields(adminin.GetIdByCodeModel{}).Where("invite_code", in.Code).Scan(&res) return } @@ -808,6 +713,17 @@ func (s *sAdminMember) Select(ctx context.Context, in adminin.MemberSelectInp) ( return } +// VerifySuperId 验证是否为超管 +func (s *sAdminMember) VerifySuperId(ctx context.Context, verifyId int64) bool { + superIds := g.Cfg().MustGet(ctx, "hotgo.admin.superIds") + for _, id := range superIds.Int64s() { + if id == verifyId { + return true + } + } + return false +} + func (s *sAdminMember) FilterAuthModel(ctx context.Context, memberId int64) *gdb.Model { m := dao.AdminMember.Ctx(ctx) if !s.VerifySuperId(ctx, memberId) { @@ -815,26 +731,3 @@ func (s *sAdminMember) FilterAuthModel(ctx context.Context, memberId int64) *gdb } return m.Handler(handler.FilterAuthWithField("id")) } - -// MemberLoginStat 用户登录统计 -func (s *sAdminMember) MemberLoginStat(ctx context.Context, in adminin.MemberLoginStatInp) (res *adminin.MemberLoginStatModel, err error) { - var models *entity.SysLoginLog - err = dao.SysLoginLog.Ctx(ctx). - Fields("login_at,login_ip"). - Where("member_id", in.MemberId). - Where("status", consts.StatusEnabled). - Scan(&models) - if err != nil { - return - } - - res = new(adminin.MemberLoginStatModel) - if models == nil { - return - } - - res.LastLoginAt = models.LoginAt - res.LastLoginIp = models.LoginIp - res.LoginCount, err = dao.SysLoginLog.Ctx(ctx).Where("member_id", in.MemberId).Where("status", consts.StatusEnabled).Count() - return -} diff --git a/server/internal/logic/admin/notice.go b/server/internal/logic/admin/notice.go index 56d01aa..2b03f93 100644 --- a/server/internal/logic/admin/notice.go +++ b/server/internal/logic/admin/notice.go @@ -124,7 +124,7 @@ func (s *sAdminNotice) Status(ctx context.Context, in adminin.NoticeStatusInp) ( return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/admin/order.go b/server/internal/logic/admin/order.go index f623b6d..cb322e8 100644 --- a/server/internal/logic/admin/order.go +++ b/server/internal/logic/admin/order.go @@ -378,7 +378,7 @@ func (s *sAdminOrder) Status(ctx context.Context, in adminin.OrderStatusInp) (er return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/admin/post.go b/server/internal/logic/admin/post.go index 7680ce1..205003c 100644 --- a/server/internal/logic/admin/post.go +++ b/server/internal/logic/admin/post.go @@ -203,7 +203,7 @@ func (s *sAdminPost) Status(ctx context.Context, in adminin.PostStatusInp) (err return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/admin/site.go b/server/internal/logic/admin/site.go new file mode 100644 index 0000000..1e77e44 --- /dev/null +++ b/server/internal/logic/admin/site.go @@ -0,0 +1,266 @@ +package admin + +import ( + "context" + "github.com/gogf/gf/v2/crypto/gmd5" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/util/grand" + "hotgo/internal/consts" + "hotgo/internal/dao" + "hotgo/internal/library/token" + "hotgo/internal/model" + "hotgo/internal/model/do" + "hotgo/internal/model/entity" + "hotgo/internal/model/input/adminin" + "hotgo/internal/model/input/sysin" + "hotgo/internal/service" + "hotgo/utility/simple" +) + +type sAdminSite struct{} + +func NewAdminSite() *sAdminSite { + return &sAdminSite{} +} + +func init() { + service.RegisterAdminSite(NewAdminSite()) +} + +// Register 账号注册 +func (s *sAdminSite) Register(ctx context.Context, in adminin.RegisterInp) (err error) { + var data adminin.MemberAddInp + + // 默认上级 + data.Pid = 1 + + // 存在邀请人 + if in.InviteCode != "" { + pmb, err := service.AdminMember().GetIdByCode(ctx, adminin.GetIdByCodeInp{Code: in.InviteCode}) + if err != nil { + return err + } + + if pmb == nil { + err = gerror.New("邀请人信息不存在") + return err + } + + data.Pid = pmb.Id + } + + config, err := service.SysConfig().GetLogin(ctx) + if err != nil { + return + } + + if config.RegisterSwitch != 1 { + err = gerror.New("管理员未开放注册") + return + } + + if config.RoleId < 1 { + err = gerror.New("管理员未配置默认角色") + return + } + + if config.DeptId < 1 { + err = gerror.New("管理员未配置默认部门") + return + } + + if len(config.PostIds) == 0 { + err = gerror.New("管理员未配置默认岗位") + return + } + + // 验证唯一性 + err = service.AdminMember().VerifyUnique(ctx, adminin.VerifyUniqueInp{ + Where: g.Map{ + dao.AdminMember.Columns().Username: in.Username, + dao.AdminMember.Columns().Mobile: in.Mobile, + }, + }) + if err != nil { + return + } + + // 验证短信验证码 + err = service.SysSmsLog().VerifyCode(ctx, sysin.VerifyCodeInp{ + Event: consts.SmsTemplateRegister, + Mobile: in.Mobile, + Code: in.Code, + }) + if err != nil { + return + } + + data.MemberEditInp = adminin.MemberEditInp{ + Id: 0, + RoleId: config.RoleId, + PostIds: config.PostIds, + DeptId: config.DeptId, + Username: in.Username, + Password: in.Password, + RealName: "", + Avatar: config.Avatar, + Sex: 3, // 保密 + Mobile: in.Mobile, + Status: consts.StatusEnabled, + } + data.Salt = grand.S(6) + data.InviteCode = grand.S(12) + data.PasswordHash = gmd5.MustEncryptString(data.Password + data.Salt) + data.Level, data.Tree, err = service.AdminMember().GenTree(ctx, data.Pid) + if err != nil { + return + } + + // 提交注册信息 + return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { + id, err := dao.AdminMember.Ctx(ctx).Data(data).InsertAndGetId() + if err != nil { + return + } + + return dao.AdminMemberPost.UpdatePostIds(ctx, id, config.PostIds) + }) +} + +// AccountLogin 账号登录 +func (s *sAdminSite) AccountLogin(ctx context.Context, in adminin.AccountLoginInp) (res *adminin.LoginModel, err error) { + defer func() { + service.SysLoginLog().Push(ctx, sysin.LoginLogPushInp{Response: res, Err: err}) + }() + + var mb *entity.AdminMember + if err = dao.AdminMember.Ctx(ctx).Where("username", in.Username).Scan(&mb); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + return + } + + if mb == nil { + err = gerror.New("账号不存在") + return + } + + res = new(adminin.LoginModel) + res.Id = mb.Id + res.Username = mb.Username + if mb.Salt == "" { + err = gerror.New("用户信息错误") + return + } + + if err = simple.CheckPassword(in.Password, mb.Salt, mb.PasswordHash); err != nil { + return + } + + if mb.Status != consts.StatusEnabled { + err = gerror.New("账号已被禁用") + return + } + + res, err = s.handleLogin(ctx, mb) + return +} + +// MobileLogin 手机号登录 +func (s *sAdminSite) MobileLogin(ctx context.Context, in adminin.MobileLoginInp) (res *adminin.LoginModel, err error) { + defer func() { + service.SysLoginLog().Push(ctx, sysin.LoginLogPushInp{Response: res, Err: err}) + }() + + var mb *entity.AdminMember + if err = dao.AdminMember.Ctx(ctx).Where("mobile ", in.Mobile).Scan(&mb); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + return + } + + if mb == nil { + err = gerror.New("账号不存在") + return + } + + res = new(adminin.LoginModel) + res.Id = mb.Id + res.Username = mb.Username + + err = service.SysSmsLog().VerifyCode(ctx, sysin.VerifyCodeInp{ + Event: consts.SmsTemplateLogin, + Mobile: in.Mobile, + Code: in.Code, + }) + + if err != nil { + return + } + + if mb.Status != consts.StatusEnabled { + err = gerror.New("账号已被禁用") + return + } + + res, err = s.handleLogin(ctx, mb) + return +} + +// handleLogin . +func (s *sAdminSite) handleLogin(ctx context.Context, mb *entity.AdminMember) (res *adminin.LoginModel, err error) { + var ro *entity.AdminRole + if err = dao.AdminRole.Ctx(ctx).Fields("id,key,status").Where("id", mb.RoleId).Scan(&ro); err != nil { + err = gerror.Wrap(err, consts.ErrorORM) + return + } + + if ro == nil { + err = gerror.New("角色不存在") + return + } + + if ro.Status != consts.StatusEnabled { + err = gerror.New("角色已被禁用") + return + } + + user := &model.Identity{ + Id: mb.Id, + Pid: mb.Pid, + DeptId: mb.DeptId, + RoleId: ro.Id, + RoleKey: ro.Key, + Username: mb.Username, + RealName: mb.RealName, + Avatar: mb.Avatar, + Email: mb.Email, + Mobile: mb.Mobile, + App: consts.AppAdmin, + LoginAt: gtime.Now(), + } + + loginToken, expires, err := token.Login(ctx, user) + if err != nil { + return nil, err + } + + update := do.AdminMember{ + LastActiveAt: user.LoginAt, + } + + // 更新登录信息 + if _, err = dao.AdminMember.Ctx(ctx).Data(update).Where(do.AdminMember{Id: mb.Id}).Update(); err != nil { + return + } + + res = &adminin.LoginModel{ + Username: user.Username, + Id: user.Id, + Token: loginToken, + Expires: expires, + } + + return +} diff --git a/server/internal/logic/middleware/init.go b/server/internal/logic/middleware/init.go index 331e0d8..2e38db4 100644 --- a/server/internal/logic/middleware/init.go +++ b/server/internal/logic/middleware/init.go @@ -39,8 +39,9 @@ func NewMiddleware() *sMiddleware { return &sMiddleware{ LoginUrl: "/common", DemoWhiteList: g.Map{ - "/admin/site/login": struct{}{}, // 后台登录 - "/admin/genCodes/preview": struct{}{}, // 预览代码 + "/admin/site/accountLogin": struct{}{}, // 账号登录 + "/admin/site/mobileLogin": struct{}{}, // 手机号登录 + "/admin/genCodes/preview": struct{}{}, // 预览代码 }, PayNotifyRoutes: g.Map{ "/api/pay/notify/alipay": struct{}{}, // 支付宝 diff --git a/server/internal/logic/pay/pay.go b/server/internal/logic/pay/pay.go index 02a2f98..35b8462 100644 --- a/server/internal/logic/pay/pay.go +++ b/server/internal/logic/pay/pay.go @@ -61,11 +61,6 @@ func (s *sPay) List(ctx context.Context, in payin.PayListInp) (list []*payin.Pay mod = mod.WhereBetween(dao.PayLog.Columns().CreatedAt, in.CreatedAt[0], in.CreatedAt[1]) } - // 查询分类名称 - if in.TestCategoryName != "" { - mod = mod.WhereLike(dao.TestCategory.Columns().Name, in.TestCategoryName) - } - totalCount, err = mod.Clone().Count() if err != nil { return @@ -143,7 +138,7 @@ func (s *sPay) Status(ctx context.Context, in payin.PayStatusInp) (err error) { return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/attachment.go b/server/internal/logic/sys/attachment.go index e73d884..cbbdb6f 100644 --- a/server/internal/logic/sys/attachment.go +++ b/server/internal/logic/sys/attachment.go @@ -73,7 +73,7 @@ func (s *sSysAttachment) Status(ctx context.Context, in sysin.AttachmentStatusIn return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/blacklist.go b/server/internal/logic/sys/blacklist.go index fa10603..dd9e88a 100644 --- a/server/internal/logic/sys/blacklist.go +++ b/server/internal/logic/sys/blacklist.go @@ -68,7 +68,7 @@ func (s *sSysBlacklist) Status(ctx context.Context, in sysin.BlacklistStatusInp) return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/config.go b/server/internal/logic/sys/config.go index 7c67eb8..7dc3771 100644 --- a/server/internal/logic/sys/config.go +++ b/server/internal/logic/sys/config.go @@ -83,27 +83,13 @@ func (s *sSysConfig) InitConfig(ctx context.Context) { } -// GetLoadTCP 获取本地tcp配置 -func (s *sSysConfig) GetLoadTCP(ctx context.Context) (conf *model.TCPConfig, err error) { - err = g.Cfg().MustGet(ctx, "tcp").Scan(&conf) - return -} - -// GetLoadCache 获取本地缓存配置 -func (s *sSysConfig) GetLoadCache(ctx context.Context) (conf *model.CacheConfig, err error) { - err = g.Cfg().MustGet(ctx, "cache").Scan(&conf) - return -} - -// GetLoadGenerate 获取本地生成配置 -func (s *sSysConfig) GetLoadGenerate(ctx context.Context) (conf *model.GenerateConfig, err error) { - err = g.Cfg().MustGet(ctx, "hggen").Scan(&conf) - return -} - -// GetLoadToken 获取本地token配置 -func (s *sSysConfig) GetLoadToken(ctx context.Context) (conf *model.TokenConfig, err error) { - err = g.Cfg().MustGet(ctx, "token").Scan(&conf) +// GetLogin 获取登录配置 +func (s *sSysConfig) GetLogin(ctx context.Context) (conf *model.LoginConfig, err error) { + models, err := s.GetConfigByGroup(ctx, sysin.GetConfigInp{Group: "login"}) + if err != nil { + return + } + err = gconv.Scan(models.List, &conf) return } @@ -182,6 +168,30 @@ func (s *sSysConfig) GetBasic(ctx context.Context) (conf *model.BasicConfig, err return } +// GetLoadTCP 获取本地tcp配置 +func (s *sSysConfig) GetLoadTCP(ctx context.Context) (conf *model.TCPConfig, err error) { + err = g.Cfg().MustGet(ctx, "tcp").Scan(&conf) + return +} + +// GetLoadCache 获取本地缓存配置 +func (s *sSysConfig) GetLoadCache(ctx context.Context) (conf *model.CacheConfig, err error) { + err = g.Cfg().MustGet(ctx, "cache").Scan(&conf) + return +} + +// GetLoadGenerate 获取本地生成配置 +func (s *sSysConfig) GetLoadGenerate(ctx context.Context) (conf *model.GenerateConfig, err error) { + err = g.Cfg().MustGet(ctx, "hggen").Scan(&conf) + return +} + +// GetLoadToken 获取本地token配置 +func (s *sSysConfig) GetLoadToken(ctx context.Context) (conf *model.TokenConfig, err error) { + err = g.Cfg().MustGet(ctx, "token").Scan(&conf) + return +} + // GetLoadSSL 获取本地日志配置 func (s *sSysConfig) GetLoadSSL(ctx context.Context) (conf *model.SSLConfig, err error) { err = g.Cfg().MustGet(ctx, "hotgo.ssl").Scan(&conf) diff --git a/server/internal/logic/sys/cron.go b/server/internal/logic/sys/cron.go index 503d59a..89bfb68 100644 --- a/server/internal/logic/sys/cron.go +++ b/server/internal/logic/sys/cron.go @@ -107,7 +107,7 @@ func (s *sSysCron) Status(ctx context.Context, in sysin.CronStatusInp) (err erro return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/cron_group.go b/server/internal/logic/sys/cron_group.go index 6d201d3..fc6889d 100644 --- a/server/internal/logic/sys/cron_group.go +++ b/server/internal/logic/sys/cron_group.go @@ -63,7 +63,7 @@ func (s *sSysCronGroup) Status(ctx context.Context, in sysin.CronGroupStatusInp) return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/curd_demo.go b/server/internal/logic/sys/curd_demo.go index e20d922..d4c7d14 100644 --- a/server/internal/logic/sys/curd_demo.go +++ b/server/internal/logic/sys/curd_demo.go @@ -180,7 +180,7 @@ func (s *sSysCurdDemo) Status(ctx context.Context, in sysin.CurdDemoStatusInp) ( return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/ems_log.go b/server/internal/logic/sys/ems_log.go index c3a25dd..06fd5da 100644 --- a/server/internal/logic/sys/ems_log.go +++ b/server/internal/logic/sys/ems_log.go @@ -76,7 +76,7 @@ func (s *sSysEmsLog) Status(ctx context.Context, in sysin.EmsLogStatusInp) (err return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/gen_codes.go b/server/internal/logic/sys/gen_codes.go index a18c57f..dd62293 100644 --- a/server/internal/logic/sys/gen_codes.go +++ b/server/internal/logic/sys/gen_codes.go @@ -110,7 +110,7 @@ func (s *sSysGenCodes) Status(ctx context.Context, in sysin.GenCodesStatusInp) ( return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/login_log.go b/server/internal/logic/sys/login_log.go index 9e1c5b7..c4072ad 100644 --- a/server/internal/logic/sys/login_log.go +++ b/server/internal/logic/sys/login_log.go @@ -24,6 +24,7 @@ import ( "hotgo/internal/library/location" "hotgo/internal/library/queue" "hotgo/internal/model/entity" + "hotgo/internal/model/input/adminin" "hotgo/internal/model/input/form" "hotgo/internal/model/input/sysin" "hotgo/internal/service" @@ -147,10 +148,14 @@ func (s *sSysLoginLog) View(ctx context.Context, in sysin.LoginLogViewInp) (res // Push 推送登录日志 func (s *sSysLoginLog) Push(ctx context.Context, in sysin.LoginLogPushInp) { + g.DumpWithType(in) + if in.Response == nil { + in.Response = new(adminin.LoginModel) + } var models entity.SysLoginLog models.ReqId = gctx.CtxId(ctx) models.MemberId = in.Response.Id - models.Username = in.Input.Username + models.Username = in.Response.Username models.LoginAt = gtime.Now() models.LoginIp = location.GetClientIp(ghttp.RequestFromCtx(ctx)) models.Status = consts.StatusEnabled @@ -161,12 +166,12 @@ func (s *sSysLoginLog) Push(ctx context.Context, in sysin.LoginLogPushInp) { } models.Response = gjson.New(consts.NilJsonToString) - if in.Response != nil && in.Response.Id > 0 { + if in.Response != nil { models.Response = gjson.New(in.Response) } if err := queue.Push(consts.QueueLoginLogTopic, models); err != nil { - g.Log().Warningf(ctx, "sSysLoginLog.Push err:%+v, models:%+v", err, models) + g.Log().Warningf(ctx, "push err:%+v, models:%+v", err, models) } return } diff --git a/server/internal/logic/sys/provinces.go b/server/internal/logic/sys/provinces.go index 5e07198..ab5fa5a 100644 --- a/server/internal/logic/sys/provinces.go +++ b/server/internal/logic/sys/provinces.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package sys import ( @@ -127,7 +126,7 @@ func (s *sSysProvinces) Status(ctx context.Context, in sysin.ProvincesStatusInp) return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/internal/logic/sys/sms_log.go b/server/internal/logic/sys/sms_log.go index 87d0620..2031609 100644 --- a/server/internal/logic/sys/sms_log.go +++ b/server/internal/logic/sys/sms_log.go @@ -15,7 +15,6 @@ import ( "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/library/location" - "hotgo/internal/library/sms" "hotgo/internal/model" "hotgo/internal/model/entity" "hotgo/internal/model/input/form" @@ -71,7 +70,7 @@ func (s *sSysSmsLog) Status(ctx context.Context, in sysin.SmsLogStatusInp) (err return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } @@ -180,9 +179,9 @@ func (s *sSysSmsLog) SendCode(ctx context.Context, in sysin.SendCodeInp) (err er in.Code = grand.Digits(4) } - if err = sms.New(config.SmsDrive).SendCode(ctx, in, config); err != nil { - return - } + //if err = sms.New(config.SmsDrive).SendCode(ctx, in, config); err != nil { + // return + //} var data = new(entity.SysSmsLog) data.Event = in.Event diff --git a/server/internal/logic/tcpclient/auth.go b/server/internal/logic/tcpclient/auth.go index f7e8674..768dea4 100644 --- a/server/internal/logic/tcpclient/auth.go +++ b/server/internal/logic/tcpclient/auth.go @@ -50,6 +50,7 @@ func (s *sAuthClient) Start(ctx context.Context) { LoginEvent: s.onLoginEvent, CloseEvent: s.onCloseEvent, }) + if err != nil { g.Log().Errorf(ctx, "AuthClient NewClient fail:%+v", err) return diff --git a/server/internal/logic/tcpclient/cron.go b/server/internal/logic/tcpclient/cron.go index 287d5fb..55dcb73 100644 --- a/server/internal/logic/tcpclient/cron.go +++ b/server/internal/logic/tcpclient/cron.go @@ -37,7 +37,7 @@ func (s *sCronClient) Start(ctx context.Context) { } simple.SafeGo(ctx, func(ctx context.Context) { - client, err := tcp.NewClient(&tcp.ClientConfig{ + s.client, err = tcp.NewClient(&tcp.ClientConfig{ Addr: config.Client.Cron.Address, Auth: &tcp.AuthMeta{ Group: config.Client.Cron.Group, @@ -48,13 +48,12 @@ func (s *sCronClient) Start(ctx context.Context) { LoginEvent: s.onLoginEvent, CloseEvent: s.onCloseEvent, }) + if err != nil { g.Log().Errorf(ctx, "CronClient NewClient fail:%+v", err) return } - s.client = client - err = s.client.RegisterRouter(map[string]tcp.RouterHandler{ "CronDelete": s.OnCronDelete, // 删除任务 "CronEdit": s.OnCronEdit, // 编辑任务 diff --git a/server/internal/model/config.go b/server/internal/model/config.go index 935bd1c..d90f252 100644 --- a/server/internal/model/config.go +++ b/server/internal/model/config.go @@ -157,6 +157,18 @@ type WechatConfig struct { *WechatOpenPlatformConfig } +// LoginConfig 登录配置 +type LoginConfig struct { + RegisterSwitch int `json:"loginRegisterSwitch"` + CaptchaSwitch int `json:"loginCaptchaSwitch"` + Avatar string `json:"loginAvatar"` + Protocol string `json:"loginProtocol"` + Policy string `json:"loginPolicy"` + RoleId int64 `json:"loginRoleId"` + DeptId int64 `json:"loginDeptId"` + PostIds []int64 `json:"loginPostIds"` +} + ///////////// 以下是本地配置 // SSLConfig https配置 diff --git a/server/internal/model/do/admin_member.go b/server/internal/model/do/admin_member.go index 5b57c6c..5b281d8 100644 --- a/server/internal/model/do/admin_member.go +++ b/server/internal/model/do/admin_member.go @@ -34,6 +34,7 @@ type AdminMember struct { Pid interface{} // 上级管理员ID Level interface{} // 关系树等级 Tree interface{} // 关系树 + InviteCode interface{} // 邀请码 Cash *gjson.Json // 提现配置 LastActiveAt *gtime.Time // 最后活跃时间 Remark interface{} // 备注 diff --git a/server/internal/model/entity/admin_member.go b/server/internal/model/entity/admin_member.go index 339c0e1..ababd28 100644 --- a/server/internal/model/entity/admin_member.go +++ b/server/internal/model/entity/admin_member.go @@ -32,6 +32,7 @@ type AdminMember struct { Pid int64 `json:"pid" description:"上级管理员ID"` Level int `json:"level" description:"关系树等级"` Tree string `json:"tree" description:"关系树"` + InviteCode string `json:"inviteCode" description:"邀请码"` Cash *gjson.Json `json:"cash" description:"提现配置"` LastActiveAt *gtime.Time `json:"lastActiveAt" description:"最后活跃时间"` Remark string `json:"remark" description:"备注"` diff --git a/server/internal/model/input/adminin/member.go b/server/internal/model/input/adminin/member.go index 5d7aff2..b058a25 100644 --- a/server/internal/model/input/adminin/member.go +++ b/server/internal/model/input/adminin/member.go @@ -82,48 +82,44 @@ type MemberResetPwdInp struct { Id int64 `json:"id" dc:"用户ID"` } -// MemberEmailUniqueInp 邮箱是否唯一 -type MemberEmailUniqueInp struct { - Email string `json:"email" v:"required#邮箱不能为空" dc:"邮箱"` - Id int64 `json:"id" dc:"用户ID"` -} - -type MemberEmailUniqueModel struct { - IsUnique bool -} - -// MemberMobileUniqueInp 手机号是否唯一 -type MemberMobileUniqueInp struct { - Mobile string `json:"mobile" v:"required#手机号不能为空" dc:"手机号"` - Id int64 `json:"id" dc:"用户ID"` -} - -type MemberMobileUniqueModel struct { - IsUnique bool -} - -// MemberNameUniqueInp 名称是否唯一 -type MemberNameUniqueInp struct { - Username string `json:"username" v:"required#用户名称不能为空" dc:"用户名称"` - Id int64 `json:"id" dc:"用户ID"` -} - -type MemberNameUniqueModel struct { - IsUnique bool +type LoginMemberInfoModel struct { + Id int64 `json:"id" dc:"用户ID"` + DeptName string `json:"deptName" dc:"所属部门"` + RoleName string `json:"roleName" dc:"所属角色"` + Permissions []string `json:"permissions" dc:"角色信息"` + DeptId int64 `json:"-" dc:"部门ID"` + RoleId int64 `json:"-" dc:"角色ID"` + Username string `json:"username" dc:"用户名"` + RealName string `json:"realName" dc:"姓名"` + Avatar string `json:"avatar" dc:"头像"` + Balance float64 `json:"balance" dc:"余额"` + Integral float64 `json:"integral" dc:"积分"` + Sex int `json:"sex" dc:"性别"` + Qq string `json:"qq" dc:"qq"` + Email string `json:"email" dc:"邮箱"` + Mobile string `json:"mobile" dc:"手机号码"` + Birthday *gtime.Time `json:"birthday" dc:"生日"` + CityId int64 `json:"cityId" dc:"城市编码"` + Address string `json:"address" dc:"联系地址"` + Cash *MemberCash `json:"cash" dc:"收款信息"` + CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"` + OpenId string `json:"openId" dc:"本次登录的openId"` // 区别与绑定的微信openid + InviteCode string `json:"inviteCode" dc:"邀请码"` + *MemberLoginStatModel } // MemberEditInp 修改/新增管理员 type MemberEditInp struct { Id int64 `json:"id" dc:""` - RoleId int `json:"roleId" v:"required#角色不能为空" dc:"角色ID"` - PostIds []int64 `json:"postIds" v:"required#岗位不能为空" dc:"岗位ID"` - DeptId int64 `json:"deptId" v:"required#部门不能为空" dc:"部门ID"` - Username string `json:"username" v:"required#账号不能为空" dc:"帐号"` + RoleId int64 `json:"roleId" v:"required#角色不能为空" dc:"角色ID"` + PostIds []int64 `json:"postIds" v:"required#岗位不能为空" dc:"岗位ID"` + DeptId int64 `json:"deptId" v:"required#部门不能为空" dc:"部门ID"` + Username string `json:"username" v:"required#账号不能为空" dc:"帐号"` PasswordHash string `json:"passwordHash" dc:"密码hash"` Password string `json:"password" dc:"密码"` RealName string `json:"realName" dc:"真实姓名"` Avatar string `json:"avatar" dc:"头像"` - Sex string `json:"sex" dc:"性别"` + Sex int `json:"sex" dc:"性别"` Qq string `json:"qq" dc:"qq"` Email string `json:"email" dc:"邮箱"` Birthday *gtime.Time `json:"birthday" dc:"生日"` @@ -133,17 +129,18 @@ type MemberEditInp struct { Address string `json:"address" dc:"默认地址"` Mobile string `json:"mobile" dc:"手机号码"` Remark string `json:"remark" dc:"备注"` - Status string `json:"status" dc:"状态"` + Status int `json:"status" dc:"状态"` CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"` UpdatedAt *gtime.Time `json:"updatedAt" dc:"修改时间"` } type MemberAddInp struct { MemberEditInp - Salt string `json:"salt" dc:"密码盐"` - Pid int64 `json:"pid" dc:"上级ID"` - Level int `json:"level" dc:"等级"` - Tree string `json:"tree" dc:"关系树"` + Salt string `json:"salt" dc:"密码盐"` + Pid int64 `json:"pid" dc:"上级ID"` + Level int `json:"level" dc:"等级"` + Tree string `json:"tree" dc:"关系树"` + InviteCode string `json:"inviteCode" dc:"邀请码"` } func (in *MemberEditInp) Filter(ctx context.Context) (err error) { @@ -160,6 +157,12 @@ func (in *MemberEditInp) Filter(ctx context.Context) (err error) { type MemberEditModel struct{} +// VerifyUniqueInp 验证管理员唯一属性 +type VerifyUniqueInp struct { + Id int64 + Where g.Map +} + // MemberDeleteInp 删除字典类型 type MemberDeleteInp struct { Id interface{} `json:"id" v:"required#用户ID不能为空" dc:"用户ID"` @@ -200,45 +203,6 @@ type MemberListModel struct { DeptId int64 `json:"deptId" dc:"部门ID"` } -// MemberLoginInp 登录 -type MemberLoginInp struct { - Username string - Password string -} -type MemberLoginModel struct { - Id int64 `json:"id" dc:"用户ID"` - Token string `json:"token" dc:"登录token"` - Expires int64 `json:"expires" dc:"登录有效期"` -} - -type LoginMemberInfoModel struct { - Id int64 `json:"id" dc:"用户ID"` - DeptName string `json:"deptName" dc:"所属部门"` - RoleName string `json:"roleName" dc:"所属角色"` - Permissions []string `json:"permissions" dc:"角色信息"` - DeptId int64 `json:"-" dc:"部门ID"` - RoleId int64 `json:"-" dc:"角色ID"` - Username string `json:"username" dc:"用户名"` - RealName string `json:"realName" dc:"姓名"` - Avatar string `json:"avatar" dc:"头像"` - Balance float64 `json:"balance" dc:"余额"` - Integral float64 `json:"integral" dc:"积分"` - Sex int `json:"sex" dc:"性别"` - Qq string `json:"qq" dc:"qq"` - Email string `json:"email" dc:"邮箱"` - Mobile string `json:"mobile" dc:"手机号码"` - Birthday *gtime.Time `json:"birthday" dc:"生日"` - CityId int64 `json:"cityId" dc:"城市编码"` - Address string `json:"address" dc:"联系地址"` - Cash *MemberCash `json:"cash" dc:"收款信息"` - CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"` - OpenId string `json:"openId" dc:"本次登录的openId"` // 区别与绑定的微信openid - *MemberLoginStatModel -} - -// MemberLoginPermissions 登录用户角色信息 -type MemberLoginPermissions []string - // MemberCash 用户提现配置 type MemberCash struct { Name string `json:"name" dc:"收款人姓名"` @@ -263,17 +227,6 @@ type MemberSelectModel struct { Avatar string `json:"avatar" dc:"头像"` } -// MemberLoginStatInp 用户登录统计 -type MemberLoginStatInp struct { - MemberId int64 -} - -type MemberLoginStatModel struct { - LoginCount int `json:"loginCount" dc:"登录次数"` - LastLoginAt *gtime.Time `json:"lastLoginAt" dc:"最后登录时间"` - LastLoginIp string `json:"lastLoginIp" dc:"最后登录IP"` -} - // MemberAddBalanceInp 增加余额 type MemberAddBalanceInp struct { Id int64 `json:"id" v:"required#用户ID不能为空" dc:"管理员ID"` diff --git a/server/internal/model/input/adminin/site.go b/server/internal/model/input/adminin/site.go new file mode 100644 index 0000000..c061442 --- /dev/null +++ b/server/internal/model/input/adminin/site.go @@ -0,0 +1,78 @@ +package adminin + +import ( + "context" + "github.com/gogf/gf/v2/encoding/gbase64" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" + "hotgo/internal/consts" + "hotgo/utility/encrypt" +) + +// RegisterInp 账号注册 +type RegisterInp struct { + Username string `json:"username" v:"required#用户名不能为空" dc:"用户名"` + Password string `json:"password" v:"required#密码不能为空" dc:"密码"` + Mobile string `json:"mobile" v:"required|phone-loose#手机号不能为空|手机号格式不正确" dc:"手机号"` + Code string `json:"code" v:"required#验证码不能为空" dc:"验证码"` + InviteCode string `json:"inviteCode" dc:"邀请码"` +} + +func (in *RegisterInp) Filter(ctx context.Context) (err error) { + // 解密密码 + str, err := gbase64.Decode([]byte(in.Password)) + if err != nil { + return err + } + + str, err = encrypt.AesECBDecrypt(str, consts.RequestEncryptKey) + if err != nil { + return err + } + + password := string(str) + + if err = g.Validator().Data(password).Rules("password").Messages("密码长度在6~18之间").Run(ctx); err != nil { + return + } + + in.Password = password + return +} + +// LoginModel 统一登录响应 +type LoginModel struct { + Id int64 `json:"id" dc:"用户ID"` + Username string `json:"username" dc:"用户名"` + Token string `json:"token" dc:"登录token"` + Expires int64 `json:"expires" dc:"登录有效期"` +} + +// AccountLoginInp 账号登录 +type AccountLoginInp struct { + Username string `json:"username" v:"required#用户名不能为空" dc:"用户名"` + Password string `json:"password" v:"required#密码不能为空" dc:"密码"` + Cid string `json:"cid" dc:"验证码ID"` + Code string `json:"code" dc:"验证码"` + IsLock bool `json:"isLock" dc:"是否为锁屏状态"` +} + +// MobileLoginInp 手机号登录 +type MobileLoginInp struct { + Mobile string `json:"mobile" v:"required|phone-loose#手机号不能为空|手机号格式不正确" dc:"手机号"` + Code string `json:"code" v:"required#验证码不能为空" dc:"验证码"` +} + +// MemberLoginPermissions 登录用户角色信息 +type MemberLoginPermissions []string + +// MemberLoginStatInp 用户登录统计 +type MemberLoginStatInp struct { + MemberId int64 +} + +type MemberLoginStatModel struct { + LoginCount int `json:"loginCount" dc:"登录次数"` + LastLoginAt *gtime.Time `json:"lastLoginAt" dc:"最后登录时间"` + LastLoginIp string `json:"lastLoginIp" dc:"最后登录IP"` +} diff --git a/server/internal/model/input/payin/pay.go b/server/internal/model/input/payin/pay.go index 8bcc34f..84bcee6 100644 --- a/server/internal/model/input/payin/pay.go +++ b/server/internal/model/input/payin/pay.go @@ -88,10 +88,9 @@ type PayViewModel struct { // PayListInp 获取支付日志列表 type PayListInp struct { form.PageReq - Id int64 `json:"id" dc:"ID"` - Status int `json:"status" dc:"状态"` - CreatedAt []*gtime.Time `json:"createdAt" dc:"创建时间"` - TestCategoryName string `json:"testCategoryName" dc:"分类名称"` + Id int64 `json:"id" dc:"ID"` + Status int `json:"status" dc:"状态"` + CreatedAt []*gtime.Time `json:"createdAt" dc:"创建时间"` } func (in *PayListInp) Filter(ctx context.Context) (err error) { diff --git a/server/internal/model/input/sysin/login_log.go b/server/internal/model/input/sysin/login_log.go index 7a4e3ab..e6dff1e 100644 --- a/server/internal/model/input/sysin/login_log.go +++ b/server/internal/model/input/sysin/login_log.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package sysin import ( @@ -84,7 +83,6 @@ type LoginLogExportModel struct { // LoginLogPushInp 解推送登录日志 type LoginLogPushInp struct { - Input adminin.MemberLoginInp - Response *adminin.MemberLoginModel + Response *adminin.LoginModel Err error } diff --git a/server/internal/model/input/sysin/sms_log.go b/server/internal/model/input/sysin/sms_log.go index 9d14236..d1e2003 100644 --- a/server/internal/model/input/sysin/sms_log.go +++ b/server/internal/model/input/sysin/sms_log.go @@ -55,8 +55,7 @@ type SmsLogListInp struct { func (in *SmsLogListInp) Filter(ctx context.Context) (err error) { if in.Event != "" { - _, ok := consts.SmsTemplateEventMap[in.Event] - if !ok { + if _, ok := consts.SmsTemplateEventMap[in.Event]; !ok { err = gerror.Newf("无效的事件类型:%v", in.Event) return } diff --git a/server/internal/router/admin.go b/server/internal/router/admin.go index 04879df..82d6523 100644 --- a/server/internal/router/admin.go +++ b/server/internal/router/admin.go @@ -25,9 +25,11 @@ func Admin(ctx context.Context, group *ghttp.RouterGroup) { prefix := g.Cfg().MustGet(ctx, "router.admin.prefix", "/admin") group.Group(prefix.String(), func(group *ghttp.RouterGroup) { + group.Bind( + common.Site, // 基础 + ) group.Middleware(service.Middleware().AdminAuth) group.Bind( - common.Site, // 基础 common.Console, // 控制台 common.Ems, // 邮件 common.Sms, // 短信 diff --git a/server/internal/service/admin.go b/server/internal/service/admin.go index 42f97a8..624ee85 100644 --- a/server/internal/service/admin.go +++ b/server/internal/service/admin.go @@ -19,17 +19,37 @@ import ( ) type ( - IAdminRole interface { - Verify(ctx context.Context, path, method string) bool - List(ctx context.Context, in adminin.RoleListInp) (res *adminin.RoleListModel, totalCount int, err error) - GetName(ctx context.Context, RoleId int64) (name string, err error) - GetMemberList(ctx context.Context, RoleId int64) (list []*adminin.RoleListModel, err error) - GetPermissions(ctx context.Context, reqInfo *role.GetPermissionsReq) (MenuIds []int64, err error) - UpdatePermissions(ctx context.Context, reqInfo *role.UpdatePermissionsReq) (err error) - Edit(ctx context.Context, in *role.EditReq) (err error) - Delete(ctx context.Context, in *role.DeleteReq) (err error) - DataScopeSelect(ctx context.Context) (res form.Selects) - DataScopeEdit(ctx context.Context, in *adminin.DataScopeEditInp) (err error) + IAdminCash interface { + View(ctx context.Context, in adminin.CashViewInp) (res *adminin.CashViewModel, err error) + List(ctx context.Context, in adminin.CashListInp) (list []*adminin.CashListModel, totalCount int, err error) + Apply(ctx context.Context, in adminin.CashApplyInp) (err error) + Payment(ctx context.Context, in adminin.CashPaymentInp) (err error) + } + IAdminMenu interface { + MaxSort(ctx context.Context, req *menu.MaxSortReq) (res *menu.MaxSortRes, err error) + NameUnique(ctx context.Context, req *menu.NameUniqueReq) (res *menu.NameUniqueRes, err error) + CodeUnique(ctx context.Context, req *menu.CodeUniqueReq) (res *menu.CodeUniqueRes, err error) + Delete(ctx context.Context, req *menu.DeleteReq) (err error) + Edit(ctx context.Context, req *menu.EditReq) (err error) + View(ctx context.Context, req *menu.ViewReq) (res *menu.ViewRes, err error) + List(ctx context.Context, req *menu.ListReq) (lists []map[string]interface{}, err error) + GetMenuList(ctx context.Context, memberId int64) (lists role.DynamicRes, err error) + LoginPermissions(ctx context.Context, memberId int64) (lists adminin.MemberLoginPermissions, err error) + } + IAdminMonitor interface { + StartMonitor(ctx context.Context) + GetMeta(ctx context.Context) *model.MonitorData + } + IAdminPost interface { + Delete(ctx context.Context, in adminin.PostDeleteInp) (err error) + Edit(ctx context.Context, in adminin.PostEditInp) (err error) + MaxSort(ctx context.Context, in adminin.PostMaxSortInp) (res *adminin.PostMaxSortModel, err error) + NameUnique(ctx context.Context, in adminin.PostNameUniqueInp) (res *adminin.PostNameUniqueModel, err error) + CodeUnique(ctx context.Context, in adminin.PostCodeUniqueInp) (res *adminin.PostCodeUniqueModel, err error) + View(ctx context.Context, in adminin.PostViewInp) (res *adminin.PostViewModel, err error) + List(ctx context.Context, in adminin.PostListInp) (list []*adminin.PostListModel, totalCount int, err error) + GetMemberByStartName(ctx context.Context, memberId int64) (name string, err error) + Status(ctx context.Context, in adminin.PostStatusInp) (err error) } IAdminNotice interface { Model(ctx context.Context, option ...*handler.Option) *gdb.Model @@ -45,11 +65,35 @@ type ( ReadAll(ctx context.Context, in adminin.NoticeReadAllInp) (err error) MessageList(ctx context.Context, in adminin.NoticeMessageListInp) (list []*adminin.NoticeMessageListModel, totalCount int, err error) } - IAdminCash interface { - View(ctx context.Context, in adminin.CashViewInp) (res *adminin.CashViewModel, err error) - List(ctx context.Context, in adminin.CashListInp) (list []*adminin.CashListModel, totalCount int, err error) - Apply(ctx context.Context, in adminin.CashApplyInp) (err error) - Payment(ctx context.Context, in adminin.CashPaymentInp) (err error) + IAdminOrder interface { + Model(ctx context.Context, option ...*handler.Option) *gdb.Model + AcceptRefund(ctx context.Context, in adminin.OrderAcceptRefundInp) (err error) + ApplyRefund(ctx context.Context, in adminin.OrderApplyRefundInp) (err error) + PayNotify(ctx context.Context, in payin.NotifyCallFuncInp) (err error) + Create(ctx context.Context, in adminin.OrderCreateInp) (res *adminin.OrderCreateModel, err error) + List(ctx context.Context, in adminin.OrderListInp) (list []*adminin.OrderListModel, totalCount int, err error) + Export(ctx context.Context, in adminin.OrderListInp) (err error) + Edit(ctx context.Context, in adminin.OrderEditInp) (err error) + Delete(ctx context.Context, in adminin.OrderDeleteInp) (err error) + View(ctx context.Context, in adminin.OrderViewInp) (res *adminin.OrderViewModel, err error) + Status(ctx context.Context, in adminin.OrderStatusInp) (err error) + } + IAdminRole interface { + Verify(ctx context.Context, path, method string) bool + List(ctx context.Context, in adminin.RoleListInp) (res *adminin.RoleListModel, totalCount int, err error) + GetName(ctx context.Context, RoleId int64) (name string, err error) + GetMemberList(ctx context.Context, RoleId int64) (list []*adminin.RoleListModel, err error) + GetPermissions(ctx context.Context, reqInfo *role.GetPermissionsReq) (MenuIds []int64, err error) + UpdatePermissions(ctx context.Context, reqInfo *role.UpdatePermissionsReq) (err error) + Edit(ctx context.Context, in *role.EditReq) (err error) + Delete(ctx context.Context, in *role.DeleteReq) (err error) + DataScopeSelect(ctx context.Context) (res form.Selects) + DataScopeEdit(ctx context.Context, in *adminin.DataScopeEditInp) (err error) + } + IAdminSite interface { + Register(ctx context.Context, in adminin.RegisterInp) (err error) + AccountLogin(ctx context.Context, in adminin.AccountLoginInp) (res *adminin.LoginModel, err error) + MobileLogin(ctx context.Context, in adminin.MobileLoginInp) (res *adminin.LoginModel, err error) } IAdminCreditsLog interface { Model(ctx context.Context, option ...*handler.Option) *gdb.Model @@ -78,102 +122,62 @@ type ( UpdateProfile(ctx context.Context, in adminin.MemberUpdateProfileInp) (err error) UpdatePwd(ctx context.Context, in adminin.MemberUpdatePwdInp) (err error) ResetPwd(ctx context.Context, in adminin.MemberResetPwdInp) (err error) - EmailUnique(ctx context.Context, in adminin.MemberEmailUniqueInp) (res *adminin.MemberEmailUniqueModel, err error) - MobileUnique(ctx context.Context, in adminin.MemberMobileUniqueInp) (res *adminin.MemberMobileUniqueModel, err error) - NameUnique(ctx context.Context, in adminin.MemberNameUniqueInp) (res *adminin.MemberNameUniqueModel, err error) - VerifySuperId(ctx context.Context, verifyId int64) bool + VerifyUnique(ctx context.Context, in adminin.VerifyUniqueInp) (err error) Delete(ctx context.Context, in adminin.MemberDeleteInp) (err error) Edit(ctx context.Context, in adminin.MemberEditInp) (err error) View(ctx context.Context, in adminin.MemberViewInp) (res *adminin.MemberViewModel, err error) List(ctx context.Context, in adminin.MemberListInp) (list []*adminin.MemberListModel, totalCount int, err error) - LoginMemberInfo(ctx context.Context) (res *adminin.LoginMemberInfoModel, err error) - Login(ctx context.Context, in adminin.MemberLoginInp) (res *adminin.MemberLoginModel, err error) - RoleMemberList(ctx context.Context, in adminin.RoleMemberListInp) (list []*adminin.MemberListModel, totalCount int, err error) Status(ctx context.Context, in adminin.MemberStatusInp) (err error) + GenTree(ctx context.Context, pid int64) (level int, newTree string, err error) + RoleMemberList(ctx context.Context, in adminin.RoleMemberListInp) (list []*adminin.MemberListModel, totalCount int, err error) + LoginMemberInfo(ctx context.Context) (res *adminin.LoginMemberInfoModel, err error) + MemberLoginStat(ctx context.Context, in adminin.MemberLoginStatInp) (res *adminin.MemberLoginStatModel, err error) GetIdByCode(ctx context.Context, in adminin.GetIdByCodeInp) (res *adminin.GetIdByCodeModel, err error) Select(ctx context.Context, in adminin.MemberSelectInp) (res []*adminin.MemberSelectModel, err error) + VerifySuperId(ctx context.Context, verifyId int64) bool FilterAuthModel(ctx context.Context, memberId int64) *gdb.Model - MemberLoginStat(ctx context.Context, in adminin.MemberLoginStatInp) (res *adminin.MemberLoginStatModel, err error) } IAdminMemberPost interface { UpdatePostIds(ctx context.Context, memberId int64, postIds []int64) (err error) GetMemberByIds(ctx context.Context, memberId int64) (postIds []int64, err error) } - IAdminMenu interface { - MaxSort(ctx context.Context, req *menu.MaxSortReq) (res *menu.MaxSortRes, err error) - NameUnique(ctx context.Context, req *menu.NameUniqueReq) (res *menu.NameUniqueRes, err error) - CodeUnique(ctx context.Context, req *menu.CodeUniqueReq) (res *menu.CodeUniqueRes, err error) - Delete(ctx context.Context, req *menu.DeleteReq) (err error) - Edit(ctx context.Context, req *menu.EditReq) (err error) - View(ctx context.Context, req *menu.ViewReq) (res *menu.ViewRes, err error) - List(ctx context.Context, req *menu.ListReq) (lists []map[string]interface{}, err error) - GetMenuList(ctx context.Context, memberId int64) (lists role.DynamicRes, err error) - LoginPermissions(ctx context.Context, memberId int64) (lists adminin.MemberLoginPermissions, err error) - } - IAdminMonitor interface { - StartMonitor(ctx context.Context) - GetMeta(ctx context.Context) *model.MonitorData - } - IAdminOrder interface { - Model(ctx context.Context, option ...*handler.Option) *gdb.Model - AcceptRefund(ctx context.Context, in adminin.OrderAcceptRefundInp) (err error) - ApplyRefund(ctx context.Context, in adminin.OrderApplyRefundInp) (err error) - PayNotify(ctx context.Context, in payin.NotifyCallFuncInp) (err error) - Create(ctx context.Context, in adminin.OrderCreateInp) (res *adminin.OrderCreateModel, err error) - List(ctx context.Context, in adminin.OrderListInp) (list []*adminin.OrderListModel, totalCount int, err error) - Export(ctx context.Context, in adminin.OrderListInp) (err error) - Edit(ctx context.Context, in adminin.OrderEditInp) (err error) - Delete(ctx context.Context, in adminin.OrderDeleteInp) (err error) - View(ctx context.Context, in adminin.OrderViewInp) (res *adminin.OrderViewModel, err error) - Status(ctx context.Context, in adminin.OrderStatusInp) (err error) - } - IAdminPost interface { - Delete(ctx context.Context, in adminin.PostDeleteInp) (err error) - Edit(ctx context.Context, in adminin.PostEditInp) (err error) - MaxSort(ctx context.Context, in adminin.PostMaxSortInp) (res *adminin.PostMaxSortModel, err error) - NameUnique(ctx context.Context, in adminin.PostNameUniqueInp) (res *adminin.PostNameUniqueModel, err error) - CodeUnique(ctx context.Context, in adminin.PostCodeUniqueInp) (res *adminin.PostCodeUniqueModel, err error) - View(ctx context.Context, in adminin.PostViewInp) (res *adminin.PostViewModel, err error) - List(ctx context.Context, in adminin.PostListInp) (list []*adminin.PostListModel, totalCount int, err error) - GetMemberByStartName(ctx context.Context, memberId int64) (name string, err error) - Status(ctx context.Context, in adminin.PostStatusInp) (err error) - } ) var ( - localAdminCash IAdminCash + localAdminMemberPost IAdminMemberPost + localAdminNotice IAdminNotice + localAdminOrder IAdminOrder + localAdminRole IAdminRole + localAdminSite IAdminSite localAdminCreditsLog IAdminCreditsLog localAdminDept IAdminDept localAdminMember IAdminMember - localAdminMemberPost IAdminMemberPost + localAdminPost IAdminPost + localAdminCash IAdminCash localAdminMenu IAdminMenu localAdminMonitor IAdminMonitor - localAdminNotice IAdminNotice - localAdminOrder IAdminOrder - localAdminPost IAdminPost - localAdminRole IAdminRole ) -func AdminMenu() IAdminMenu { - if localAdminMenu == nil { - panic("implement not found for interface IAdminMenu, forgot register?") +func AdminMember() IAdminMember { + if localAdminMember == nil { + panic("implement not found for interface IAdminMember, forgot register?") } - return localAdminMenu + return localAdminMember } -func RegisterAdminMenu(i IAdminMenu) { - localAdminMenu = i +func RegisterAdminMember(i IAdminMember) { + localAdminMember = i } -func AdminMonitor() IAdminMonitor { - if localAdminMonitor == nil { - panic("implement not found for interface IAdminMonitor, forgot register?") +func AdminMemberPost() IAdminMemberPost { + if localAdminMemberPost == nil { + panic("implement not found for interface IAdminMemberPost, forgot register?") } - return localAdminMonitor + return localAdminMemberPost } -func RegisterAdminMonitor(i IAdminMonitor) { - localAdminMonitor = i +func RegisterAdminMemberPost(i IAdminMemberPost) { + localAdminMemberPost = i } func AdminNotice() IAdminNotice { @@ -187,15 +191,37 @@ func RegisterAdminNotice(i IAdminNotice) { localAdminNotice = i } -func AdminCash() IAdminCash { - if localAdminCash == nil { - panic("implement not found for interface IAdminCash, forgot register?") +func AdminOrder() IAdminOrder { + if localAdminOrder == nil { + panic("implement not found for interface IAdminOrder, forgot register?") } - return localAdminCash + return localAdminOrder } -func RegisterAdminCash(i IAdminCash) { - localAdminCash = i +func RegisterAdminOrder(i IAdminOrder) { + localAdminOrder = i +} + +func AdminRole() IAdminRole { + if localAdminRole == nil { + panic("implement not found for interface IAdminRole, forgot register?") + } + return localAdminRole +} + +func RegisterAdminRole(i IAdminRole) { + localAdminRole = i +} + +func AdminSite() IAdminSite { + if localAdminSite == nil { + panic("implement not found for interface IAdminSite, forgot register?") + } + return localAdminSite +} + +func RegisterAdminSite(i IAdminSite) { + localAdminSite = i } func AdminCreditsLog() IAdminCreditsLog { @@ -220,37 +246,15 @@ func RegisterAdminDept(i IAdminDept) { localAdminDept = i } -func AdminMember() IAdminMember { - if localAdminMember == nil { - panic("implement not found for interface IAdminMember, forgot register?") +func AdminMonitor() IAdminMonitor { + if localAdminMonitor == nil { + panic("implement not found for interface IAdminMonitor, forgot register?") } - return localAdminMember + return localAdminMonitor } -func RegisterAdminMember(i IAdminMember) { - localAdminMember = i -} - -func AdminMemberPost() IAdminMemberPost { - if localAdminMemberPost == nil { - panic("implement not found for interface IAdminMemberPost, forgot register?") - } - return localAdminMemberPost -} - -func RegisterAdminMemberPost(i IAdminMemberPost) { - localAdminMemberPost = i -} - -func AdminOrder() IAdminOrder { - if localAdminOrder == nil { - panic("implement not found for interface IAdminOrder, forgot register?") - } - return localAdminOrder -} - -func RegisterAdminOrder(i IAdminOrder) { - localAdminOrder = i +func RegisterAdminMonitor(i IAdminMonitor) { + localAdminMonitor = i } func AdminPost() IAdminPost { @@ -264,13 +268,24 @@ func RegisterAdminPost(i IAdminPost) { localAdminPost = i } -func AdminRole() IAdminRole { - if localAdminRole == nil { - panic("implement not found for interface IAdminRole, forgot register?") +func AdminCash() IAdminCash { + if localAdminCash == nil { + panic("implement not found for interface IAdminCash, forgot register?") } - return localAdminRole + return localAdminCash } -func RegisterAdminRole(i IAdminRole) { - localAdminRole = i +func RegisterAdminCash(i IAdminCash) { + localAdminCash = i +} + +func AdminMenu() IAdminMenu { + if localAdminMenu == nil { + panic("implement not found for interface IAdminMenu, forgot register?") + } + return localAdminMenu +} + +func RegisterAdminMenu(i IAdminMenu) { + localAdminMenu = i } diff --git a/server/internal/service/sys.go b/server/internal/service/sys.go index 04c2292..d854205 100644 --- a/server/internal/service/sys.go +++ b/server/internal/service/sys.go @@ -17,20 +17,112 @@ import ( ) type ( + ISysBlacklist interface { + Delete(ctx context.Context, in sysin.BlacklistDeleteInp) (err error) + Edit(ctx context.Context, in sysin.BlacklistEditInp) (err error) + Status(ctx context.Context, in sysin.BlacklistStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.BlacklistMaxSortInp) (res *sysin.BlacklistMaxSortModel, err error) + View(ctx context.Context, in sysin.BlacklistViewInp) (res *sysin.BlacklistViewModel, err error) + List(ctx context.Context, in sysin.BlacklistListInp) (list []*sysin.BlacklistListModel, totalCount int, err error) + VariableLoad(ctx context.Context, err error) + Load(ctx context.Context) + } + ISysCronGroup interface { + Delete(ctx context.Context, in sysin.CronGroupDeleteInp) (err error) + Edit(ctx context.Context, in sysin.CronGroupEditInp) (err error) + Status(ctx context.Context, in sysin.CronGroupStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.CronGroupMaxSortInp) (res *sysin.CronGroupMaxSortModel, err error) + View(ctx context.Context, in sysin.CronGroupViewInp) (res *sysin.CronGroupViewModel, err error) + List(ctx context.Context, in sysin.CronGroupListInp) (list []*sysin.CronGroupListModel, totalCount int, err error) + Select(ctx context.Context, in sysin.CronGroupSelectInp) (res *sysin.CronGroupSelectModel, err error) + } + ISysGenCodes interface { + Delete(ctx context.Context, in sysin.GenCodesDeleteInp) (err error) + Edit(ctx context.Context, in sysin.GenCodesEditInp) (res *sysin.GenCodesEditModel, err error) + Status(ctx context.Context, in sysin.GenCodesStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.GenCodesMaxSortInp) (res *sysin.GenCodesMaxSortModel, err error) + View(ctx context.Context, in sysin.GenCodesViewInp) (res *sysin.GenCodesViewModel, err error) + List(ctx context.Context, in sysin.GenCodesListInp) (list []*sysin.GenCodesListModel, totalCount int, err error) + Selects(ctx context.Context, in sysin.GenCodesSelectsInp) (res *sysin.GenCodesSelectsModel, err error) + TableSelect(ctx context.Context, in sysin.GenCodesTableSelectInp) (res []*sysin.GenCodesTableSelectModel, err error) + ColumnSelect(ctx context.Context, in sysin.GenCodesColumnSelectInp) (res []*sysin.GenCodesColumnSelectModel, err error) + ColumnList(ctx context.Context, in sysin.GenCodesColumnListInp) (res []*sysin.GenCodesColumnListModel, err error) + Preview(ctx context.Context, in sysin.GenCodesPreviewInp) (res *sysin.GenCodesPreviewModel, err error) + Build(ctx context.Context, in sysin.GenCodesBuildInp) (err error) + } + ISysLoginLog interface { + Model(ctx context.Context) *gdb.Model + List(ctx context.Context, in sysin.LoginLogListInp) (list []*sysin.LoginLogListModel, totalCount int, err error) + Export(ctx context.Context, in sysin.LoginLogListInp) (err error) + Delete(ctx context.Context, in sysin.LoginLogDeleteInp) (err error) + View(ctx context.Context, in sysin.LoginLogViewInp) (res *sysin.LoginLogViewModel, err error) + Push(ctx context.Context, in sysin.LoginLogPushInp) + RealWrite(ctx context.Context, models entity.SysLoginLog) (err error) + } ISysAddonsConfig interface { GetConfigByGroup(ctx context.Context, in sysin.GetAddonsConfigInp) (res *sysin.GetAddonsConfigModel, err error) ConversionType(ctx context.Context, models *entity.SysAddonsConfig) (value interface{}, err error) UpdateConfigByGroup(ctx context.Context, in sysin.UpdateAddonsConfigInp) (err error) } - ISysCron interface { - StartCron(ctx context.Context) - Delete(ctx context.Context, in sysin.CronDeleteInp) (err error) - Edit(ctx context.Context, in sysin.CronEditInp) (err error) - Status(ctx context.Context, in sysin.CronStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.CronMaxSortInp) (res *sysin.CronMaxSortModel, err error) - View(ctx context.Context, in sysin.CronViewInp) (res *sysin.CronViewModel, err error) - List(ctx context.Context, in sysin.CronListInp) (list []*sysin.CronListModel, totalCount int, err error) - OnlineExec(ctx context.Context, in sysin.OnlineExecInp) (err error) + ISysAttachment interface { + Model(ctx context.Context, option ...*handler.Option) *gdb.Model + Delete(ctx context.Context, in sysin.AttachmentDeleteInp) (err error) + Edit(ctx context.Context, in sysin.AttachmentEditInp) (err error) + Status(ctx context.Context, in sysin.AttachmentStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.AttachmentMaxSortInp) (res *sysin.AttachmentMaxSortModel, err error) + View(ctx context.Context, in sysin.AttachmentViewInp) (res *sysin.AttachmentViewModel, err error) + List(ctx context.Context, in sysin.AttachmentListInp) (list []*sysin.AttachmentListModel, totalCount int, err error) + Add(ctx context.Context, meta *sysin.UploadFileMeta, fullPath, drive string) (models *entity.SysAttachment, err error) + } + ISysConfig interface { + InitConfig(ctx context.Context) + GetLogin(ctx context.Context) (conf *model.LoginConfig, err error) + GetWechat(ctx context.Context) (conf *model.WechatConfig, err error) + GetPay(ctx context.Context) (conf *model.PayConfig, err error) + GetSms(ctx context.Context) (conf *model.SmsConfig, err error) + GetGeo(ctx context.Context) (conf *model.GeoConfig, err error) + GetUpload(ctx context.Context) (conf *model.UploadConfig, err error) + GetSmtp(ctx context.Context) (conf *model.EmailConfig, err error) + GetBasic(ctx context.Context) (conf *model.BasicConfig, err error) + GetLoadTCP(ctx context.Context) (conf *model.TCPConfig, err error) + GetLoadCache(ctx context.Context) (conf *model.CacheConfig, err error) + GetLoadGenerate(ctx context.Context) (conf *model.GenerateConfig, err error) + GetLoadToken(ctx context.Context) (conf *model.TokenConfig, err error) + GetLoadSSL(ctx context.Context) (conf *model.SSLConfig, err error) + GetLoadLog(ctx context.Context) (conf *model.LogConfig, err error) + GetLoadServeLog(ctx context.Context) (conf *model.ServeLogConfig, err error) + GetConfigByGroup(ctx context.Context, in sysin.GetConfigInp) (res *sysin.GetConfigModel, err error) + ConversionType(ctx context.Context, models *entity.SysConfig) (value interface{}, err error) + UpdateConfigByGroup(ctx context.Context, in sysin.UpdateConfigInp) (err error) + } + ISysLog interface { + Export(ctx context.Context, in sysin.LogListInp) (err error) + RealWrite(ctx context.Context, log entity.SysLog) (err error) + AutoLog(ctx context.Context) error + AnalysisLog(ctx context.Context) entity.SysLog + View(ctx context.Context, in sysin.LogViewInp) (res *sysin.LogViewModel, err error) + Delete(ctx context.Context, in sysin.LogDeleteInp) (err error) + List(ctx context.Context, in sysin.LogListInp) (list []*sysin.LogListModel, totalCount int, err error) + } + ISysServeLog interface { + Model(ctx context.Context) *gdb.Model + List(ctx context.Context, in sysin.ServeLogListInp) (list []*sysin.ServeLogListModel, totalCount int, err error) + Export(ctx context.Context, in sysin.ServeLogListInp) (err error) + Delete(ctx context.Context, in sysin.ServeLogDeleteInp) (err error) + View(ctx context.Context, in sysin.ServeLogViewInp) (res *sysin.ServeLogViewModel, err error) + RealWrite(ctx context.Context, models entity.SysServeLog) (err error) + } + ISysDictData interface { + Delete(ctx context.Context, in sysin.DictDataDeleteInp) error + Edit(ctx context.Context, in sysin.DictDataEditInp) (err error) + List(ctx context.Context, in sysin.DictDataListInp) (list []*sysin.DictDataListModel, totalCount int, err error) + Select(ctx context.Context, in sysin.DataSelectInp) (list sysin.DataSelectModel, err error) + } + ISysDictType interface { + Tree(ctx context.Context) (list []*sysin.DictTypeTree, err error) + Delete(ctx context.Context, in sysin.DictTypeDeleteInp) (err error) + Edit(ctx context.Context, in sysin.DictTypeEditInp) (err error) + TreeSelect(ctx context.Context, in sysin.DictTreeSelectInp) (list []*sysin.DictTypeTree, err error) } ISysCurdDemo interface { Model(ctx context.Context, option ...*handler.Option) *gdb.Model @@ -43,27 +135,6 @@ type ( Status(ctx context.Context, in sysin.CurdDemoStatusInp) (err error) Switch(ctx context.Context, in sysin.CurdDemoSwitchInp) (err error) } - ISysDictType interface { - Tree(ctx context.Context) (list []*sysin.DictTypeTree, err error) - Delete(ctx context.Context, in sysin.DictTypeDeleteInp) (err error) - Edit(ctx context.Context, in sysin.DictTypeEditInp) (err error) - TreeSelect(ctx context.Context, in sysin.DictTreeSelectInp) (list []*sysin.DictTypeTree, err error) - } - ISysCronGroup interface { - Delete(ctx context.Context, in sysin.CronGroupDeleteInp) (err error) - Edit(ctx context.Context, in sysin.CronGroupEditInp) (err error) - Status(ctx context.Context, in sysin.CronGroupStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.CronGroupMaxSortInp) (res *sysin.CronGroupMaxSortModel, err error) - View(ctx context.Context, in sysin.CronGroupViewInp) (res *sysin.CronGroupViewModel, err error) - List(ctx context.Context, in sysin.CronGroupListInp) (list []*sysin.CronGroupListModel, totalCount int, err error) - Select(ctx context.Context, in sysin.CronGroupSelectInp) (res *sysin.CronGroupSelectModel, err error) - } - ISysDictData interface { - Delete(ctx context.Context, in sysin.DictDataDeleteInp) error - Edit(ctx context.Context, in sysin.DictDataEditInp) (err error) - List(ctx context.Context, in sysin.DictDataListInp) (list []*sysin.DictDataListModel, totalCount int, err error) - Select(ctx context.Context, in sysin.DataSelectInp) (list sysin.DataSelectModel, err error) - } ISysEmsLog interface { Delete(ctx context.Context, in sysin.EmsLogDeleteInp) (err error) Edit(ctx context.Context, in sysin.EmsLogEditInp) (err error) @@ -75,14 +146,17 @@ type ( AllowSend(ctx context.Context, models *entity.SysEmsLog, config *model.EmailConfig) (err error) VerifyCode(ctx context.Context, in sysin.VerifyEmsCodeInp) (err error) } - ISysLog interface { - Export(ctx context.Context, in sysin.LogListInp) (err error) - RealWrite(ctx context.Context, log entity.SysLog) (err error) - AutoLog(ctx context.Context) error - AnalysisLog(ctx context.Context) entity.SysLog - View(ctx context.Context, in sysin.LogViewInp) (res *sysin.LogViewModel, err error) - Delete(ctx context.Context, in sysin.LogDeleteInp) (err error) - List(ctx context.Context, in sysin.LogListInp) (list []*sysin.LogListModel, totalCount int, err error) + ISysProvinces interface { + Tree(ctx context.Context) (list []g.Map, err error) + Delete(ctx context.Context, in sysin.ProvincesDeleteInp) (err error) + Edit(ctx context.Context, in sysin.ProvincesEditInp) (err error) + Status(ctx context.Context, in sysin.ProvincesStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.ProvincesMaxSortInp) (res *sysin.ProvincesMaxSortModel, err error) + View(ctx context.Context, in sysin.ProvincesViewInp) (res *sysin.ProvincesViewModel, err error) + List(ctx context.Context, in sysin.ProvincesListInp) (list []*sysin.ProvincesListModel, totalCount int, err error) + ChildrenList(ctx context.Context, in sysin.ProvincesChildrenListInp) (list []*sysin.ProvincesChildrenListModel, totalCount int, err error) + UniqueId(ctx context.Context, in sysin.ProvincesUniqueIdInp) (res *sysin.ProvincesUniqueIdModel, err error) + Select(ctx context.Context, in sysin.ProvincesSelectInp) (res *sysin.ProvincesSelectModel, err error) } ISysSmsLog interface { Delete(ctx context.Context, in sysin.SmsLogDeleteInp) (err error) @@ -104,142 +178,47 @@ type ( Upgrade(ctx context.Context, in sysin.AddonsUpgradeInp) (err error) UnInstall(ctx context.Context, in sysin.AddonsUnInstallInp) (err error) } - ISysConfig interface { - InitConfig(ctx context.Context) - GetLoadTCP(ctx context.Context) (conf *model.TCPConfig, err error) - GetLoadCache(ctx context.Context) (conf *model.CacheConfig, err error) - GetLoadGenerate(ctx context.Context) (conf *model.GenerateConfig, err error) - GetLoadToken(ctx context.Context) (conf *model.TokenConfig, err error) - GetWechat(ctx context.Context) (conf *model.WechatConfig, err error) - GetPay(ctx context.Context) (conf *model.PayConfig, err error) - GetSms(ctx context.Context) (conf *model.SmsConfig, err error) - GetGeo(ctx context.Context) (conf *model.GeoConfig, err error) - GetUpload(ctx context.Context) (conf *model.UploadConfig, err error) - GetSmtp(ctx context.Context) (conf *model.EmailConfig, err error) - GetBasic(ctx context.Context) (conf *model.BasicConfig, err error) - GetLoadSSL(ctx context.Context) (conf *model.SSLConfig, err error) - GetLoadLog(ctx context.Context) (conf *model.LogConfig, err error) - GetLoadServeLog(ctx context.Context) (conf *model.ServeLogConfig, err error) - GetConfigByGroup(ctx context.Context, in sysin.GetConfigInp) (res *sysin.GetConfigModel, err error) - ConversionType(ctx context.Context, models *entity.SysConfig) (value interface{}, err error) - UpdateConfigByGroup(ctx context.Context, in sysin.UpdateConfigInp) (err error) - } - ISysLoginLog interface { - Model(ctx context.Context) *gdb.Model - List(ctx context.Context, in sysin.LoginLogListInp) (list []*sysin.LoginLogListModel, totalCount int, err error) - Export(ctx context.Context, in sysin.LoginLogListInp) (err error) - Delete(ctx context.Context, in sysin.LoginLogDeleteInp) (err error) - View(ctx context.Context, in sysin.LoginLogViewInp) (res *sysin.LoginLogViewModel, err error) - Push(ctx context.Context, in sysin.LoginLogPushInp) - RealWrite(ctx context.Context, models entity.SysLoginLog) (err error) - } - ISysProvinces interface { - Tree(ctx context.Context) (list []g.Map, err error) - Delete(ctx context.Context, in sysin.ProvincesDeleteInp) (err error) - Edit(ctx context.Context, in sysin.ProvincesEditInp) (err error) - Status(ctx context.Context, in sysin.ProvincesStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.ProvincesMaxSortInp) (res *sysin.ProvincesMaxSortModel, err error) - View(ctx context.Context, in sysin.ProvincesViewInp) (res *sysin.ProvincesViewModel, err error) - List(ctx context.Context, in sysin.ProvincesListInp) (list []*sysin.ProvincesListModel, totalCount int, err error) - ChildrenList(ctx context.Context, in sysin.ProvincesChildrenListInp) (list []*sysin.ProvincesChildrenListModel, totalCount int, err error) - UniqueId(ctx context.Context, in sysin.ProvincesUniqueIdInp) (res *sysin.ProvincesUniqueIdModel, err error) - Select(ctx context.Context, in sysin.ProvincesSelectInp) (res *sysin.ProvincesSelectModel, err error) - } - ISysServeLog interface { - Model(ctx context.Context) *gdb.Model - List(ctx context.Context, in sysin.ServeLogListInp) (list []*sysin.ServeLogListModel, totalCount int, err error) - Export(ctx context.Context, in sysin.ServeLogListInp) (err error) - Delete(ctx context.Context, in sysin.ServeLogDeleteInp) (err error) - View(ctx context.Context, in sysin.ServeLogViewInp) (res *sysin.ServeLogViewModel, err error) - RealWrite(ctx context.Context, models entity.SysServeLog) (err error) - } - ISysAttachment interface { - Model(ctx context.Context, option ...*handler.Option) *gdb.Model - Delete(ctx context.Context, in sysin.AttachmentDeleteInp) (err error) - Edit(ctx context.Context, in sysin.AttachmentEditInp) (err error) - Status(ctx context.Context, in sysin.AttachmentStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.AttachmentMaxSortInp) (res *sysin.AttachmentMaxSortModel, err error) - View(ctx context.Context, in sysin.AttachmentViewInp) (res *sysin.AttachmentViewModel, err error) - List(ctx context.Context, in sysin.AttachmentListInp) (list []*sysin.AttachmentListModel, totalCount int, err error) - Add(ctx context.Context, meta *sysin.UploadFileMeta, fullPath, drive string) (models *entity.SysAttachment, err error) - } - ISysBlacklist interface { - Delete(ctx context.Context, in sysin.BlacklistDeleteInp) (err error) - Edit(ctx context.Context, in sysin.BlacklistEditInp) (err error) - Status(ctx context.Context, in sysin.BlacklistStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.BlacklistMaxSortInp) (res *sysin.BlacklistMaxSortModel, err error) - View(ctx context.Context, in sysin.BlacklistViewInp) (res *sysin.BlacklistViewModel, err error) - List(ctx context.Context, in sysin.BlacklistListInp) (list []*sysin.BlacklistListModel, totalCount int, err error) - VariableLoad(ctx context.Context, err error) - Load(ctx context.Context) - } - ISysGenCodes interface { - Delete(ctx context.Context, in sysin.GenCodesDeleteInp) (err error) - Edit(ctx context.Context, in sysin.GenCodesEditInp) (res *sysin.GenCodesEditModel, err error) - Status(ctx context.Context, in sysin.GenCodesStatusInp) (err error) - MaxSort(ctx context.Context, in sysin.GenCodesMaxSortInp) (res *sysin.GenCodesMaxSortModel, err error) - View(ctx context.Context, in sysin.GenCodesViewInp) (res *sysin.GenCodesViewModel, err error) - List(ctx context.Context, in sysin.GenCodesListInp) (list []*sysin.GenCodesListModel, totalCount int, err error) - Selects(ctx context.Context, in sysin.GenCodesSelectsInp) (res *sysin.GenCodesSelectsModel, err error) - TableSelect(ctx context.Context, in sysin.GenCodesTableSelectInp) (res []*sysin.GenCodesTableSelectModel, err error) - ColumnSelect(ctx context.Context, in sysin.GenCodesColumnSelectInp) (res []*sysin.GenCodesColumnSelectModel, err error) - ColumnList(ctx context.Context, in sysin.GenCodesColumnListInp) (res []*sysin.GenCodesColumnListModel, err error) - Preview(ctx context.Context, in sysin.GenCodesPreviewInp) (res *sysin.GenCodesPreviewModel, err error) - Build(ctx context.Context, in sysin.GenCodesBuildInp) (err error) + ISysCron interface { + StartCron(ctx context.Context) + Delete(ctx context.Context, in sysin.CronDeleteInp) (err error) + Edit(ctx context.Context, in sysin.CronEditInp) (err error) + Status(ctx context.Context, in sysin.CronStatusInp) (err error) + MaxSort(ctx context.Context, in sysin.CronMaxSortInp) (res *sysin.CronMaxSortModel, err error) + View(ctx context.Context, in sysin.CronViewInp) (res *sysin.CronViewModel, err error) + List(ctx context.Context, in sysin.CronListInp) (list []*sysin.CronListModel, totalCount int, err error) + OnlineExec(ctx context.Context, in sysin.OnlineExecInp) (err error) } ) var ( - localSysEmsLog ISysEmsLog - localSysLog ISysLog - localSysSmsLog ISysSmsLog - localSysCronGroup ISysCronGroup localSysDictData ISysDictData - localSysLoginLog ISysLoginLog - localSysProvinces ISysProvinces + localSysDictType ISysDictType + localSysLog ISysLog localSysServeLog ISysServeLog + localSysProvinces ISysProvinces + localSysSmsLog ISysSmsLog localSysAddons ISysAddons - localSysConfig ISysConfig + localSysCron ISysCron + localSysCurdDemo ISysCurdDemo + localSysEmsLog ISysEmsLog localSysGenCodes ISysGenCodes + localSysLoginLog ISysLoginLog + localSysAddonsConfig ISysAddonsConfig localSysAttachment ISysAttachment localSysBlacklist ISysBlacklist - localSysCurdDemo ISysCurdDemo - localSysDictType ISysDictType - localSysAddonsConfig ISysAddonsConfig - localSysCron ISysCron + localSysCronGroup ISysCronGroup + localSysConfig ISysConfig ) -func SysAddonsConfig() ISysAddonsConfig { - if localSysAddonsConfig == nil { - panic("implement not found for interface ISysAddonsConfig, forgot register?") +func SysDictData() ISysDictData { + if localSysDictData == nil { + panic("implement not found for interface ISysDictData, forgot register?") } - return localSysAddonsConfig + return localSysDictData } -func RegisterSysAddonsConfig(i ISysAddonsConfig) { - localSysAddonsConfig = i -} - -func SysCron() ISysCron { - if localSysCron == nil { - panic("implement not found for interface ISysCron, forgot register?") - } - return localSysCron -} - -func RegisterSysCron(i ISysCron) { - localSysCron = i -} - -func SysCurdDemo() ISysCurdDemo { - if localSysCurdDemo == nil { - panic("implement not found for interface ISysCurdDemo, forgot register?") - } - return localSysCurdDemo -} - -func RegisterSysCurdDemo(i ISysCurdDemo) { - localSysCurdDemo = i +func RegisterSysDictData(i ISysDictData) { + localSysDictData = i } func SysDictType() ISysDictType { @@ -253,39 +232,6 @@ func RegisterSysDictType(i ISysDictType) { localSysDictType = i } -func SysCronGroup() ISysCronGroup { - if localSysCronGroup == nil { - panic("implement not found for interface ISysCronGroup, forgot register?") - } - return localSysCronGroup -} - -func RegisterSysCronGroup(i ISysCronGroup) { - localSysCronGroup = i -} - -func SysDictData() ISysDictData { - if localSysDictData == nil { - panic("implement not found for interface ISysDictData, forgot register?") - } - return localSysDictData -} - -func RegisterSysDictData(i ISysDictData) { - localSysDictData = i -} - -func SysEmsLog() ISysEmsLog { - if localSysEmsLog == nil { - panic("implement not found for interface ISysEmsLog, forgot register?") - } - return localSysEmsLog -} - -func RegisterSysEmsLog(i ISysEmsLog) { - localSysEmsLog = i -} - func SysLog() ISysLog { if localSysLog == nil { panic("implement not found for interface ISysLog, forgot register?") @@ -297,6 +243,28 @@ func RegisterSysLog(i ISysLog) { localSysLog = i } +func SysServeLog() ISysServeLog { + if localSysServeLog == nil { + panic("implement not found for interface ISysServeLog, forgot register?") + } + return localSysServeLog +} + +func RegisterSysServeLog(i ISysServeLog) { + localSysServeLog = i +} + +func SysProvinces() ISysProvinces { + if localSysProvinces == nil { + panic("implement not found for interface ISysProvinces, forgot register?") + } + return localSysProvinces +} + +func RegisterSysProvinces(i ISysProvinces) { + localSysProvinces = i +} + func SysSmsLog() ISysSmsLog { if localSysSmsLog == nil { panic("implement not found for interface ISysSmsLog, forgot register?") @@ -319,15 +287,48 @@ func RegisterSysAddons(i ISysAddons) { localSysAddons = i } -func SysConfig() ISysConfig { - if localSysConfig == nil { - panic("implement not found for interface ISysConfig, forgot register?") +func SysCron() ISysCron { + if localSysCron == nil { + panic("implement not found for interface ISysCron, forgot register?") } - return localSysConfig + return localSysCron } -func RegisterSysConfig(i ISysConfig) { - localSysConfig = i +func RegisterSysCron(i ISysCron) { + localSysCron = i +} + +func SysCurdDemo() ISysCurdDemo { + if localSysCurdDemo == nil { + panic("implement not found for interface ISysCurdDemo, forgot register?") + } + return localSysCurdDemo +} + +func RegisterSysCurdDemo(i ISysCurdDemo) { + localSysCurdDemo = i +} + +func SysEmsLog() ISysEmsLog { + if localSysEmsLog == nil { + panic("implement not found for interface ISysEmsLog, forgot register?") + } + return localSysEmsLog +} + +func RegisterSysEmsLog(i ISysEmsLog) { + localSysEmsLog = i +} + +func SysGenCodes() ISysGenCodes { + if localSysGenCodes == nil { + panic("implement not found for interface ISysGenCodes, forgot register?") + } + return localSysGenCodes +} + +func RegisterSysGenCodes(i ISysGenCodes) { + localSysGenCodes = i } func SysLoginLog() ISysLoginLog { @@ -341,26 +342,15 @@ func RegisterSysLoginLog(i ISysLoginLog) { localSysLoginLog = i } -func SysProvinces() ISysProvinces { - if localSysProvinces == nil { - panic("implement not found for interface ISysProvinces, forgot register?") +func SysAddonsConfig() ISysAddonsConfig { + if localSysAddonsConfig == nil { + panic("implement not found for interface ISysAddonsConfig, forgot register?") } - return localSysProvinces + return localSysAddonsConfig } -func RegisterSysProvinces(i ISysProvinces) { - localSysProvinces = i -} - -func SysServeLog() ISysServeLog { - if localSysServeLog == nil { - panic("implement not found for interface ISysServeLog, forgot register?") - } - return localSysServeLog -} - -func RegisterSysServeLog(i ISysServeLog) { - localSysServeLog = i +func RegisterSysAddonsConfig(i ISysAddonsConfig) { + localSysAddonsConfig = i } func SysAttachment() ISysAttachment { @@ -385,13 +375,24 @@ func RegisterSysBlacklist(i ISysBlacklist) { localSysBlacklist = i } -func SysGenCodes() ISysGenCodes { - if localSysGenCodes == nil { - panic("implement not found for interface ISysGenCodes, forgot register?") +func SysCronGroup() ISysCronGroup { + if localSysCronGroup == nil { + panic("implement not found for interface ISysCronGroup, forgot register?") } - return localSysGenCodes + return localSysCronGroup } -func RegisterSysGenCodes(i ISysGenCodes) { - localSysGenCodes = i +func RegisterSysCronGroup(i ISysCronGroup) { + localSysCronGroup = i +} + +func SysConfig() ISysConfig { + if localSysConfig == nil { + panic("implement not found for interface ISysConfig, forgot register?") + } + return localSysConfig +} + +func RegisterSysConfig(i ISysConfig) { + localSysConfig = i } diff --git a/server/manifest/config/config.example.yaml b/server/manifest/config/config.example.yaml index 43dbe04..55abb85 100644 --- a/server/manifest/config/config.example.yaml +++ b/server/manifest/config/config.example.yaml @@ -109,14 +109,11 @@ router: prefix: "/admin" # 不需要验证登录的路由地址 exceptLogin: [ - "/site/captcha", # 登录验证码 - "/site/login", # 登录 - "/site/ping", # ping + "/sms/send", # 短信验证码 "/wechat/authorizeCall", # 微信用户授权回调 ] # 不需要验证权限的路由地址 exceptAuth: [ - "/site/config", # 获取后台配置 "/member/info", # 登录用户信息 "/role/dynamic", # 获取动态路由 "/notice/pullMessages", # 拉取我的消息 diff --git a/server/resource/generate/default/curd/logic.go.template b/server/resource/generate/default/curd/logic.go.template index 67da6d5..5fe7f82 100644 --- a/server/resource/generate/default/curd/logic.go.template +++ b/server/resource/generate/default/curd/logic.go.template @@ -140,7 +140,7 @@ func (s *s@{.servFunName}) Status(ctx context.Context, in @{.templateGroup}in.@{ return } - if !validate.InSliceInt(consts.StatusMap, in.Status) { + if !validate.InSliceInt(consts.StatusSlice, in.Status) { err = gerror.New("状态不正确") return } diff --git a/server/storage/data/hotgo.sql b/server/storage/data/hotgo.sql index 9aabd20..1755261 100644 --- a/server/storage/data/hotgo.sql +++ b/server/storage/data/hotgo.sql @@ -1,14 +1,13 @@ -- phpMyAdmin SQL Dump --- version 4.9.0.1 +-- version 5.2.1 -- https://www.phpmyadmin.net/ -- --- 主机: localhost:3306 --- 生成日期: 2023-05-12 15:45:52 --- 服务器版本: 5.7.38-log --- PHP 版本: 5.6.40 +-- 主机: localhost +-- 生成日期: 2023-05-14 08:51:30 +-- 服务器版本: 5.7.41 +-- PHP 版本: 7.3.33 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; @@ -73,8 +72,8 @@ CREATE TABLE `hg_addon_hgexample_table` ( -- INSERT INTO `hg_addon_hgexample_table` (`id`, `category_id`, `flag`, `title`, `description`, `content`, `image`, `images`, `attachfile`, `attachfiles`, `map`, `star`, `price`, `views`, `activity_at`, `start_at`, `end_at`, `switch`, `sort`, `avatar`, `sex`, `qq`, `email`, `mobile`, `hobby`, `channel`, `city_id`, `pid`, `level`, `tree`, `remark`, `status`, `created_by`, `updated_by`, `created_at`, `updated_at`, `deleted_at`) VALUES -(1, 1, '[1, 2]', '测试标题', '描述', '
这是内容............
', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqamvhlq4w3ki6bl.webp', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqap5l9brk2lkavu.jpg\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaqua7fw8ukbbp5.jpg\"]', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqawg96ba4cuezvv.xlsx\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc\"]', '[{\"key\": \"qwe\", \"value\": \"123\"}, {\"key\": \"asd\", \"value\": \"456\"}]', '3.0', '88.00', 10, '2022-12-23', '2022-12-01 00:00:00', '2022-12-31 23:59:59', 1, 20, '', 15, '133814250', '133814250@qq.com', '15303830571', '[3, 2, 1]', 1, 140406, 0, 1, '', '备注!', 1, 1, 3, '2022-12-15 19:30:14', '2023-04-28 16:46:17', NULL), -(2, 0, '[1]', '测试2', '描述', '这是内容............
', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqamvhlq4w3ki6bl.webp', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqap5l9brk2lkavu.jpg\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaqua7fw8ukbbp5.jpg\"]', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqawg96ba4cuezvv.xlsx\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc\"]', '[{\"key\": \"qwe\", \"value\": \"123\"}, {\"key\": \"asd\", \"value\": \"456\"}]', 3.0, 88.00, 10, '2022-12-23', '2022-12-01 00:00:00', '2022-12-31 23:59:59', 1, 20, '', 15, '133814250', '133814250@qq.com', '15303830571', '[3, 2, 1]', 1, 140406, 0, 1, '', '备注!', 1, 1, 3, '2022-12-15 19:30:14', '2023-04-28 16:46:17', NULL), +(2, 0, '[1]', '测试2', '描述', '用户协议..
', '', 1120, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), +(115, 'login', '隐私权政策', 'string', 'loginPolicy', '隐私权政策..
', '', 1130, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), +(116, 'login', '默认注册角色', 'int64', 'loginRoleId', '202', '', 1140, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), +(117, 'login', '默认注册部门', 'int64', 'loginDeptId', '112', '', 1150, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), +(118, 'login', '默认注册岗位', '[]int64', 'loginPostIds', '[4,6]', '', 1160, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), +(119, 'login', '默认注册头像', 'string', 'loginAvatar', 'http://localhost:8000/attachment/2023-05-14/csltf747yrr4gd4kc5.png', '', 1170, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'); -- -------------------------------------------------------- @@ -1715,13 +1726,6 @@ CREATE TABLE `hg_sys_login_log` ( `updated_at` datetime DEFAULT NULL COMMENT '修改时间' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统_登录日志'; --- --- 转存表中的数据 `hg_sys_login_log` --- - -INSERT INTO `hg_sys_login_log` (`id`, `req_id`, `member_id`, `username`, `response`, `login_at`, `login_ip`, `err_msg`, `status`, `created_at`, `updated_at`) VALUES -(40, 'c043b70bb0045e17d7eafe258038334d', 1, 'admin', '{\"id\": 1, \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOiJhZG1pbiIsImF2YXRhciI6Imh0dHA6Ly9idWZhbnl1bi5jbi1iai51ZmlsZW9zLmNvbS9ob3Rnby9hdHRhY2htZW50LzIwMjMtMDItMDkvY3FkcThlcjluZmtjaGRvcGF2LnBuZyIsImRlcHRJZCI6MTAwLCJlbWFpbCI6IjEzMzgxNDI1MEBxcS5jb20iLCJleHAiOjE2ODQ2NTI0NjQsImV4cGlyZXMiOjg2NDAwMCwiaWQiOjEsImlzUmVmcmVzaCI6ZmFsc2UsImp3dFZlcnNpb24iOiIxLjAiLCJtb2JpbGUiOiIxNTMwMzgzMDU3MSIsInBpZCI6MCwicmVhbE5hbWUiOiLlrZ_luIUiLCJyb2xlSWQiOjEsInJvbGVLZXkiOiJzdXBlciIsInVzZXJuYW1lIjoiYWRtaW4ifQ.66ppHKrI8QbIo4u_fH88BlI6NdiomqnuIVGkyDKy1-I\", \"expires\": 864000}', '2023-05-11 15:01:04', '127.0.0.1', '', 1, '2023-05-11 15:41:45', '2023-05-11 15:41:45'); - -- -------------------------------------------------------- -- @@ -5469,7 +5473,7 @@ CREATE TABLE `hg_sys_serve_license` ( -- INSERT INTO `hg_sys_serve_license` (`id`, `group`, `name`, `appid`, `secret_key`, `desc`, `remote_addr`, `online`, `online_limit`, `login_times`, `last_login_at`, `last_active_at`, `routes`, `allowed_ips`, `end_at`, `remark`, `status`, `created_at`, `updated_at`) VALUES -(1, 'cron', '默认的定时任务', '1002', 'hotgo', '这是默认的定时任务TCP客户端授权凭证。', '127.0.0.1:52537', 1, 1, 163, '2023-05-11 15:52:56', '2023-05-11 15:54:30', NULL, '127.0.0.1', '2033-03-09 00:00:00', '', 1, '2023-03-11 00:00:00', '2023-05-11 15:54:30'), +(1, 'cron', '默认的定时任务', '1002', 'hotgo', '这是默认的定时任务TCP客户端授权凭证。', '127.0.0.1:62905', 1, 1, 295, '2023-05-14 16:44:30', '2023-05-14 16:50:30', NULL, '127.0.0.1', '2033-03-09 00:00:00', '', 1, '2023-03-11 00:00:00', '2023-05-14 16:50:30'), (2, 'auth', '测试授权', 'mengshuai', '123456', '这是一个测试的授权服务,可以为第三方平台提供授权支持。', '127.0.0.1:51615', 1, 1, 0, '2023-05-04 23:23:52', '2023-05-04 23:23:52', NULL, '127.0.0.1', '2033-03-09 00:00:00', '', 1, '2023-03-11 00:00:00', '2023-05-04 23:23:52'); -- -------------------------------------------------------- @@ -5586,6 +5590,7 @@ ALTER TABLE `hg_admin_dept` -- ALTER TABLE `hg_admin_member` ADD PRIMARY KEY (`id`), + ADD UNIQUE KEY `invite_code` (`invite_code`), ADD KEY `dept_id` (`dept_id`), ADD KEY `pid` (`pid`); @@ -5846,7 +5851,7 @@ ALTER TABLE `hg_admin_dept` -- 使用表AUTO_INCREMENT `hg_admin_member` -- ALTER TABLE `hg_admin_member` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '管理员ID', AUTO_INCREMENT=10; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '管理员ID', AUTO_INCREMENT=14; -- -- 使用表AUTO_INCREMENT `hg_admin_menu` @@ -5894,7 +5899,7 @@ ALTER TABLE `hg_admin_role` -- 使用表AUTO_INCREMENT `hg_admin_role_casbin` -- ALTER TABLE `hg_admin_role_casbin` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=20237; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28232; -- -- 使用表AUTO_INCREMENT `hg_pay_log` @@ -5924,7 +5929,7 @@ ALTER TABLE `hg_sys_addons_install` -- 使用表AUTO_INCREMENT `hg_sys_attachment` -- ALTER TABLE `hg_sys_attachment` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '文件ID', AUTO_INCREMENT=55; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '文件ID', AUTO_INCREMENT=56; -- -- 使用表AUTO_INCREMENT `hg_sys_blacklist` @@ -5936,7 +5941,7 @@ ALTER TABLE `hg_sys_blacklist` -- 使用表AUTO_INCREMENT `hg_sys_config` -- ALTER TABLE `hg_sys_config` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '配置ID', AUTO_INCREMENT=112; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '配置ID', AUTO_INCREMENT=120; -- -- 使用表AUTO_INCREMENT `hg_sys_cron` @@ -5990,7 +5995,7 @@ ALTER TABLE `hg_sys_log` -- 使用表AUTO_INCREMENT `hg_sys_login_log` -- ALTER TABLE `hg_sys_login_log` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '日志ID', AUTO_INCREMENT=41; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '日志ID'; -- -- 使用表AUTO_INCREMENT `hg_sys_serve_license` @@ -6008,7 +6013,7 @@ ALTER TABLE `hg_sys_serve_log` -- 使用表AUTO_INCREMENT `hg_sys_sms_log` -- ALTER TABLE `hg_sys_sms_log` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', AUTO_INCREMENT=3; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', AUTO_INCREMENT=6; -- -- 使用表AUTO_INCREMENT `hg_test_category` diff --git a/web/.env b/web/.env index c7ac7a5..a55418a 100644 --- a/web/.env +++ b/web/.env @@ -2,10 +2,8 @@ VITE_PORT=8001 # spa-title -VITE_GLOB_APP_TITLE=HG后台管理系统 +VITE_GLOB_APP_TITLE=HotGo管理系统 # spa shortname VITE_GLOB_APP_SHORT_NAME=HG -# 生产环境 开启mock -VITE_GLOB_PROD_MOCK=false diff --git a/web/.env.development b/web/.env.development index 79c773f..6a1e227 100644 --- a/web/.env.development +++ b/web/.env.development @@ -3,9 +3,6 @@ # 网站根目录 VITE_PUBLIC_PATH=/ -# 是否开启mock -VITE_USE_MOCK=false - # 网站前缀 VITE_BASE_URL=/ diff --git a/web/.env.production b/web/.env.production index ab49e2e..7a6c774 100644 --- a/web/.env.production +++ b/web/.env.production @@ -3,9 +3,6 @@ # 网站根目录 VITE_PUBLIC_PATH=/admin -# 是否开启mock -VITE_USE_MOCK=false - # 网站前缀 VITE_BASE_URL=/ diff --git a/web/build/vite/plugin/index.ts b/web/build/vite/plugin/index.ts index 0f62f80..16cc8c7 100644 --- a/web/build/vite/plugin/index.ts +++ b/web/build/vite/plugin/index.ts @@ -4,13 +4,11 @@ import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'; import topLevelAwait from 'vite-plugin-top-level-await'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; - import { configHtmlPlugin } from './html'; -import { configMockPlugin } from './mock'; import { configCompressPlugin } from './compress'; -export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, prodMock) { - const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv; +export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { + const { VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv; const vitePlugins: (Plugin | Plugin[])[] = [ // have to @@ -36,9 +34,6 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, prodMock) // vite-plugin-html vitePlugins.push(configHtmlPlugin(viteEnv, isBuild)); - // vite-plugin-mock - VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild, prodMock)); - if (isBuild) { // rollup-plugin-gzip vitePlugins.push( diff --git a/web/build/vite/plugin/mock.ts b/web/build/vite/plugin/mock.ts deleted file mode 100644 index 84bf144..0000000 --- a/web/build/vite/plugin/mock.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Mock plugin for development and production. - * https://github.com/anncwb/vite-plugin-mock - */ -import { viteMockServe } from 'vite-plugin-mock'; - -export function configMockPlugin(isBuild: boolean, prodMock: boolean) { - return viteMockServe({ - ignore: /^\_/, - mockPath: 'mock', - localEnabled: !isBuild, - prodEnabled: isBuild && prodMock, - injectCode: ` - import { setupProdMockServer } from '../mock/_createProductionServer'; - - setupProdMockServer(); - `, - }); -} diff --git a/web/mock/_createProductionServer.ts b/web/mock/_createProductionServer.ts deleted file mode 100644 index a44310b..0000000 --- a/web/mock/_createProductionServer.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'; - -const modules = import.meta.globEager('./**/*.ts'); - -const mockModules: any[] = []; -Object.keys(modules).forEach((key) => { - if (key.includes('/_')) { - return; - } - mockModules.push(...modules[key].default); -}); - -/** - * Used in a production environment. Need to manually import all modules - */ -export function setupProdMockServer() { - createProdMockServer(mockModules); -} diff --git a/web/mock/_util.ts b/web/mock/_util.ts deleted file mode 100644 index 9e4b3b3..0000000 --- a/web/mock/_util.ts +++ /dev/null @@ -1,73 +0,0 @@ -import Mock from 'mockjs'; - -export function resultSuccess(data, { message = 'ok' } = {}) { - return Mock.mock({ - code: 0, - data, - message, - type: 'success', - }); -} - -export function resultPageSuccess这是内容............
', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqamvhlq4w3ki6bl.webp', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqap5l9brk2lkavu.jpg\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaqua7fw8ukbbp5.jpg\"]', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqawg96ba4cuezvv.xlsx\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc\"]', '[{\"key\": \"qwe\", \"value\": \"123\"}, {\"key\": \"asd\", \"value\": \"456\"}]', 3.0, 88.00, 10, '2022-12-23', '2022-12-01 00:00:00', '2022-12-31 23:59:59', 1, 20, '', 15, '133814250', '133814250@qq.com', '15303830571', '[3, 2, 1]', 1, 140406, 0, 1, '', '备注!', 1, 1, 3, '2022-12-15 19:30:14', '2023-04-28 16:46:17', NULL), -(2, 0, '[1]', '测试2', '描述', '这是内容............
', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqamvhlq4w3ki6bl.webp', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqap5l9brk2lkavu.jpg\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaqua7fw8ukbbp5.jpg\"]', 'http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc', '[\"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqawg96ba4cuezvv.xlsx\", \"http://bufanyun.cn-bj.ufileos.com/hotgo/attachment/2023-02-09/cqdqaup19k9oznyixz.doc\"]', '[{\"key\": \"qwe\", \"value\": \"123\"}, {\"key\": \"asd\", \"value\": \"456\"}]', '3.0', '88.00', 10, '2022-12-23', '2022-12-01 00:00:00', '2022-12-31 23:59:59', 1, 20, '', 15, '133814250', '133814250@qq.com', '15303830571', '[3, 2, 1]', 1, 140406, 0, 1, '', '备注!', 1, 1, 3, '2022-12-15 19:30:14', '2023-04-28 16:46:17', NULL), +(2, 0, '[1]', '测试2', '描述', '用户协议..
', '', 1120, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(115, 'login', '隐私权政策', 'string', 'loginPolicy', '隐私权政策..
', '', 1130, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(116, 'login', '默认注册角色', 'int64', 'loginRoleId', '202', '', 1140, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(117, 'login', '默认注册部门', 'int64', 'loginDeptId', '112', '', 1150, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(118, 'login', '默认注册岗位', '[]int64', 'loginPostIds', '[4,6]', '', 1160, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'), -(119, 'login', '默认注册头像', 'string', 'loginAvatar', 'http://localhost:8000/attachment/2023-05-14/csltf747yrr4gd4kc5.png', '', 1170, '', 1, 1, '2021-09-29 23:51:21', '2023-05-14 16:35:46'); +(112, 'login', '注册开关', 'int', 'loginRegisterSwitch', '1', '1', 1100, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(113, 'login', '验证码开关', 'int', 'loginCaptchaSwitch', '1', '1', 1110, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(114, 'login', '用户协议', 'string', 'loginProtocol', '用户协议..
', '', 1120, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(115, 'login', '隐私权政策', 'string', 'loginPolicy', '隐私权政策..
', '', 1130, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(116, 'login', '默认注册角色', 'int64', 'loginRoleId', '202', '', 1140, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(117, 'login', '默认注册部门', 'int64', 'loginDeptId', '112', '', 1150, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(118, 'login', '默认注册岗位', '[]int64', 'loginPostIds', '[6]', '', 1160, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(119, 'login', '默认注册头像', 'string', 'loginAvatar', 'http://localhost:8000/attachment/2023-05-14/csltf747yrr4gd4kc5.png', '', 1170, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(120, 'login', '强制邀请', 'int', 'loginForceInvite', '2', '1', 1190, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'), +(121, 'login', '自动获取openId', 'int', 'loginAutoOpenId', '2', '1', 1195, '', 1, 1, '2021-09-29 23:51:21', '2023-05-15 09:46:09'); -- -------------------------------------------------------- @@ -5941,7 +5944,7 @@ ALTER TABLE `hg_sys_blacklist` -- 使用表AUTO_INCREMENT `hg_sys_config` -- ALTER TABLE `hg_sys_config` - MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '配置ID', AUTO_INCREMENT=120; + MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '配置ID', AUTO_INCREMENT=122; -- -- 使用表AUTO_INCREMENT `hg_sys_cron` diff --git a/server/utility/file/mime.go b/server/utility/file/mime.go index b6f59ca..7857ba6 100644 --- a/server/utility/file/mime.go +++ b/server/utility/file/mime.go @@ -3,7 +3,6 @@ // @Copyright Copyright (c) 2023 HotGo CLI // @Author Ms <133814250@qq.com> // @License https://github.com/bufanyun/hotgo/blob/master/LICENSE -// package file import ( @@ -11,7 +10,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/text/gstr" - "io/ioutil" + "io" "path" ) @@ -139,7 +138,7 @@ func UploadFileByte(file *ghttp.UploadFile) (b []byte, err error) { if err != nil { return } - all, err := ioutil.ReadAll(open) + all, err := io.ReadAll(open) if err != nil { return } diff --git a/web/src/router/router-guards.ts b/web/src/router/router-guards.ts index b22f793..52b33ce 100644 --- a/web/src/router/router-guards.ts +++ b/web/src/router/router-guards.ts @@ -1,13 +1,13 @@ import type { RouteRecordRaw } from 'vue-router'; import { isNavigationFailure, Router } from 'vue-router'; -import { UserInfoState, useUserStoreWidthOut } from '@/store/modules/user'; +import { useUserStoreWidthOut } from '@/store/modules/user'; import { useAsyncRouteStoreWidthOut } from '@/store/modules/asyncRoute'; import { ACCESS_TOKEN } from '@/store/mutation-types'; import { storage } from '@/utils/Storage'; import { PageEnum } from '@/enums/pageEnum'; import { ErrorPageRoute } from '@/router/base'; -import { isWechatBrowser } from '@/utils/is'; import { jump } from '@/utils/http/axios'; +import { getNowUrl } from '@/utils/urlUtils'; const LOGIN_PATH = PageEnum.BASE_LOGIN; const whitePathList = [LOGIN_PATH]; // no redirect whitelist @@ -64,21 +64,20 @@ export function createRouterGuards(router: Router) { const redirect = decodeURIComponent(redirectPath); const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }; const userInfo = await userStore.GetInfo(); + await userStore.LoadLoginConfig(); - // 如果是微信访问,则记录本次登录的openid - if (isWechatBrowser() && (userInfo as UserInfoState).openId === '') { + // 是否允许获取微信openid + if (userStore.allowWxOpenId()) { let path = nextData.path; if (path === LOGIN_PATH) { path = PageEnum.BASE_HOME_REDIRECT; } - const w = window.location; - const URI = w.protocol + '//' + w.host + w.pathname + '#' + path; + const URI = getNowUrl() + '#' + path; jump('/wechat/authorize', { type: 'openId', syncRedirect: URI }); return; } - await userStore.LoadLoginConfig(); await userStore.GetConfig(); const routes = await asyncRouteStore.generateRoutes(userInfo); diff --git a/web/src/store/modules/user.ts b/web/src/store/modules/user.ts index 419a8e5..ea4bdac 100644 --- a/web/src/store/modules/user.ts +++ b/web/src/store/modules/user.ts @@ -17,6 +17,7 @@ import { logout, mobileLogin, } from '@/api/system/user'; +import { isWechatBrowser } from '@/utils/is'; const Storage = createStorage({ storage: localStorage }); export interface UserInfoState { @@ -59,6 +60,7 @@ export interface ConfigState { export interface LoginConfigState { loginRegisterSwitch: number; loginCaptchaSwitch: number; + loginAutoOpenId: number; loginProtocol: string; loginPolicy: string; } @@ -218,6 +220,18 @@ export const useUserStore = defineStore({ }); }); }, + // 是否允许获取微信openid + allowWxOpenId(): boolean { + if (!isWechatBrowser()) { + return false; + } + + if (this.loginConfig?.loginAutoOpenId !== 1) { + return false; + } + + return this.info?.openId === ''; + }, // 登出 async logout() { try { diff --git a/web/src/utils/urlUtils.ts b/web/src/utils/urlUtils.ts index d0d6216..584b156 100644 --- a/web/src/utils/urlUtils.ts +++ b/web/src/utils/urlUtils.ts @@ -41,3 +41,11 @@ export function getFileExt(fileName: string) { } return fileName.substring(fileName.lastIndexOf('.') + 1); } + +/** + * 获取当访问的url,不含参数 + */ +export function getNowUrl(): string { + const w = window.location; + return w.protocol + '//' + w.host + w.pathname; +} diff --git a/web/src/views/login/components/form-other.vue b/web/src/views/login/components/form-other.vue index 7aae11f..dbe11ea 100644 --- a/web/src/views/login/components/form-other.vue +++ b/web/src/views/login/components/form-other.vue @@ -18,7 +18,11 @@