mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-16 06:53:44 +08:00
发布v2.2.10版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
41
server/internal/controller/admin/common/console.go
Normal file
41
server/internal/controller/admin/common/console.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Package common
|
||||
// @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 common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/api/admin/common"
|
||||
)
|
||||
|
||||
var Console = cConsole{}
|
||||
|
||||
type cConsole struct{}
|
||||
|
||||
// Stat 综合数据统计
|
||||
func (c *cConsole) Stat(ctx context.Context, req *common.ConsoleStatReq) (res *common.ConsoleStatRes, err error) {
|
||||
res = new(common.ConsoleStatRes)
|
||||
|
||||
res.Visits.DayVisits = 12010
|
||||
res.Visits.Rise = 13501
|
||||
res.Visits.Decline = 10502
|
||||
res.Visits.Amount = 10403
|
||||
|
||||
res.Saleroom.WeekSaleroom = 20501
|
||||
res.Saleroom.Amount = 21002
|
||||
res.Saleroom.Degree = 83.66
|
||||
|
||||
res.OrderLarge.WeekLarge = 39901
|
||||
res.OrderLarge.Rise = 31012
|
||||
res.OrderLarge.Decline = 30603
|
||||
res.OrderLarge.Amount = 36084
|
||||
|
||||
res.Volume.WeekLarge = 40021
|
||||
res.Volume.Rise = 40202
|
||||
res.Volume.Decline = 45003
|
||||
res.Volume.Amount = 49004
|
||||
return
|
||||
}
|
79
server/internal/controller/admin/common/ems.go
Normal file
79
server/internal/controller/admin/common/ems.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// Package common
|
||||
// @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 common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/api/admin/common"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
var Ems = new(cEms)
|
||||
|
||||
type cEms struct{}
|
||||
|
||||
// SendTest 发送测试邮件
|
||||
func (c *cEms) SendTest(ctx context.Context, req *common.SendTestEmailReq) (res *common.SendTestEmailRes, err error) {
|
||||
err = service.SysEmsLog().Send(ctx, sysin.SendEmsInp{
|
||||
Event: consts.EmsTemplateText,
|
||||
Email: req.To,
|
||||
Content: `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="iso-8859-15">
|
||||
<title>这是一封来自HotGo的测试邮件</title>
|
||||
</head>
|
||||
<body>
|
||||
这是您通过HotGo后台发送的测试邮件。当你收到这封邮件的时候,说明已经联调成功了,恭喜你!
|
||||
</body>
|
||||
</html>`,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// SendBindEms 发送换绑邮件
|
||||
func (c *cSms) SendBindEms(ctx context.Context, req *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) {
|
||||
var (
|
||||
memberId = contexts.GetUserId(ctx)
|
||||
models *entity.AdminMember
|
||||
)
|
||||
if memberId <= 0 {
|
||||
err = gerror.New("用户身份异常,请重新登录!")
|
||||
return
|
||||
}
|
||||
|
||||
err = g.Model("admin_member").
|
||||
Fields("email").
|
||||
Where("id", memberId).
|
||||
Scan(&models)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if models == nil {
|
||||
err = gerror.New("用户信息不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if models.Email == "" {
|
||||
err = gerror.New("未绑定邮箱无需发送")
|
||||
return
|
||||
}
|
||||
|
||||
err = service.SysEmsLog().Send(ctx, sysin.SendEmsInp{
|
||||
Event: consts.EmsTemplateBind,
|
||||
Email: models.Email,
|
||||
})
|
||||
return
|
||||
}
|
124
server/internal/controller/admin/common/site.go
Normal file
124
server/internal/controller/admin/common/site.go
Normal file
@@ -0,0 +1,124 @@
|
||||
// Package common
|
||||
// @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 common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/api/admin/common"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/cache"
|
||||
"hotgo/internal/library/captcha"
|
||||
"hotgo/internal/library/jwt"
|
||||
"hotgo/internal/model/input/adminin"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
var Site = cSite{}
|
||||
|
||||
type cSite struct{}
|
||||
|
||||
// Ping ping
|
||||
func (c *cSite) Ping(ctx context.Context, req *common.SitePingReq) (res *common.SitePingRes, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Config 获取配置
|
||||
func (c *cSite) Config(ctx context.Context, req *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),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *cSite) getWsAddr(ctx context.Context, request *ghttp.Request) string {
|
||||
// 如果是本地IP访问,则认为是调试模式,走实际请求地址,否则走配置中的地址
|
||||
ip := ghttp.RequestFromCtx(ctx).GetHeader("hostname")
|
||||
if validate.IsLocalIPAddr(ip) {
|
||||
return "ws://" + ip + ":" + gstr.StrEx(request.Host, ":") + "/socket"
|
||||
}
|
||||
|
||||
basic, err := service.SysConfig().GetBasic(ctx)
|
||||
if err != nil || basic == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return basic.WsAddr
|
||||
}
|
||||
|
||||
func (c *cSite) getDomain(ctx context.Context, request *ghttp.Request) string {
|
||||
// 如果是本地IP访问,则认为是调试模式,走实际请求地址,否则走配置中的地址
|
||||
ip := request.GetHeader("hostname")
|
||||
if validate.IsLocalIPAddr(ip) {
|
||||
return "http://" + ip + ":" + gstr.StrEx(request.Host, ":")
|
||||
}
|
||||
|
||||
basic, err := service.SysConfig().GetBasic(ctx)
|
||||
if err != nil || basic == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return basic.Domain
|
||||
}
|
||||
|
||||
// Captcha 登录验证码
|
||||
func (c *cSite) Captcha(ctx context.Context, req *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
|
||||
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("验证码错误")
|
||||
return
|
||||
}
|
||||
|
||||
model, err := service.AdminMember().Login(ctx, in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = gconv.Scan(model, &res)
|
||||
return
|
||||
}
|
||||
|
||||
// Logout 注销登录
|
||||
func (c *cSite) Logout(ctx context.Context, req *common.LoginLogoutReq) (res *common.LoginLogoutRes, err error) {
|
||||
token := consts.CacheJwtToken + gmd5.MustEncryptString(jwt.GetAuthorization(ghttp.RequestFromCtx(ctx)))
|
||||
if len(token) == 0 {
|
||||
err = gerror.New("当前用户未登录!")
|
||||
return
|
||||
}
|
||||
|
||||
// 删除登录token
|
||||
_, err = cache.Instance().Remove(ctx, token)
|
||||
return
|
||||
}
|
77
server/internal/controller/admin/common/sms.go
Normal file
77
server/internal/controller/admin/common/sms.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// Package common
|
||||
// @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 common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/api/admin/common"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
var Sms = new(cSms)
|
||||
|
||||
type cSms struct{}
|
||||
|
||||
// SendTest 发送测试短信
|
||||
func (c *cSms) SendTest(ctx context.Context, req *common.SendTestSmsReq) (res *common.SendTestSmsRes, 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
|
||||
}
|
||||
|
||||
// SendBindSms 发送换绑短信
|
||||
func (c *cSms) SendBindSms(ctx context.Context, req *common.SendBindSmsReq) (res *common.SendBindSmsRes, err error) {
|
||||
var (
|
||||
memberId = contexts.GetUserId(ctx)
|
||||
models *entity.AdminMember
|
||||
)
|
||||
|
||||
if memberId <= 0 {
|
||||
err = gerror.New("用户身份异常,请重新登录!")
|
||||
return
|
||||
}
|
||||
|
||||
err = g.Model("admin_member").
|
||||
Fields("mobile").
|
||||
Where("id", memberId).
|
||||
Scan(&models)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if models == nil {
|
||||
err = gerror.New("用户信息不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if models.Mobile == "" {
|
||||
err = gerror.New("未绑定手机号无需发送")
|
||||
return
|
||||
}
|
||||
|
||||
err = service.SysSmsLog().SendCode(ctx, sysin.SendCodeInp{
|
||||
Event: consts.SmsTemplateBind,
|
||||
Mobile: models.Mobile,
|
||||
})
|
||||
return
|
||||
}
|
41
server/internal/controller/admin/common/upload.go
Normal file
41
server/internal/controller/admin/common/upload.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Package common
|
||||
// @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 common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/api/admin/common"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
var Upload = new(cUpload)
|
||||
|
||||
type cUpload struct{}
|
||||
|
||||
// UploadImage 上传图片
|
||||
func (c *cUpload) UploadImage(ctx context.Context, req *common.UploadImageReq) (res common.UploadImageRes, err error) {
|
||||
file := g.RequestFromCtx(ctx).GetUploadFile("file")
|
||||
if file == nil {
|
||||
err = gerror.New("没有找到上传的文件")
|
||||
return
|
||||
}
|
||||
|
||||
return service.CommonUpload().UploadImage(ctx, file)
|
||||
}
|
||||
|
||||
// UploadFile 上传附件
|
||||
func (c *cUpload) UploadFile(ctx context.Context, req *common.UploadFileReq) (res common.UploadFileRes, err error) {
|
||||
file := g.RequestFromCtx(ctx).GetUploadFile("file")
|
||||
if file == nil {
|
||||
err = gerror.New("没有找到上传的文件")
|
||||
return
|
||||
}
|
||||
|
||||
return service.CommonUpload().UploadFile(ctx, file)
|
||||
}
|
Reference in New Issue
Block a user