mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-10 03:03:44 +08:00
v2.0
This commit is contained in:
42
server/internal/controller/backend/common/console.go
Normal file
42
server/internal/controller/backend/common/console.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Package common
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/api/backend/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
|
||||
}
|
||||
32
server/internal/controller/backend/common/ems.go
Normal file
32
server/internal/controller/backend/common/ems.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Package common
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/api/backend/common"
|
||||
"hotgo/internal/library/ems"
|
||||
"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) {
|
||||
|
||||
conf, err := service.SysConfig().GetSmtp(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = ems.SendTestMail(conf, req.To); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
101
server/internal/controller/backend/common/site.go
Normal file
101
server/internal/controller/backend/common/site.go
Normal file
@@ -0,0 +1,101 @@
|
||||
// Package common
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 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/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/api/backend/common"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/cache"
|
||||
"hotgo/internal/library/captcha"
|
||||
"hotgo/internal/library/jwt"
|
||||
"hotgo/internal/model/input/adminin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
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) {
|
||||
|
||||
wsAddr, _ := g.Cfg().Get(ctx, "hotgo.wsAddr", "ws://127.0.0.1:8000/ws")
|
||||
g.Log().Warningf(ctx, "wsAddr:%+v", wsAddr.String())
|
||||
res = &common.SiteConfigRes{
|
||||
Version: consts.VersionApp,
|
||||
WsAddr: wsAddr.String(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Captcha 登录验证码
|
||||
func (c *cSite) Captcha(ctx context.Context, req *common.LoginCaptchaReq) (res *common.LoginCaptchaRes, err error) {
|
||||
|
||||
// 获取生成的验证码图片
|
||||
Cid, Base64 := captcha.GetVerifyImgString(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) {
|
||||
|
||||
//// 校验 验证码
|
||||
//if !captcha.VerifyString(req.Cid, req.Code) {
|
||||
// err = gerror.New("验证码错误")
|
||||
// return
|
||||
//}
|
||||
//
|
||||
var in adminin.MemberLoginInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model, err := service.AdminMember().Login(ctx, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = gconv.Scan(model, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Logout 注销登录
|
||||
func (c *cSite) Logout(ctx context.Context, req *common.LoginLogoutReq) (res *common.LoginLogoutRes, err error) {
|
||||
|
||||
var authorization = jwt.GetAuthorization(ghttp.RequestFromCtx(ctx))
|
||||
|
||||
// 获取jwtToken
|
||||
jwtToken := consts.RedisJwtToken + gmd5.MustEncryptString(authorization)
|
||||
if len(jwtToken) == 0 {
|
||||
err = gerror.New("当前用户未登录!")
|
||||
return res, err
|
||||
}
|
||||
|
||||
// 删除登录token
|
||||
ca := cache.New()
|
||||
_, err = ca.Remove(ctx, jwtToken)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
36
server/internal/controller/backend/common/upload.go
Normal file
36
server/internal/controller/backend/common/upload.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Package common
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 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/backend/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) {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
file := r.GetUploadFile("file")
|
||||
if file == nil {
|
||||
err = gerror.New("没有找到上传的文件")
|
||||
return
|
||||
}
|
||||
|
||||
res, err = service.CommonUpload().UploadImage(ctx, file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user