Files
hotgo/server/internal/controller/admin/common/ems.go
maxbad b051c98dec fix generate
接口返回list如果是nil,则赋值为空数组
前端State类加构造函数
2024-01-08 17:51:20 +08:00

76 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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 *cEms) SendBindEms(ctx context.Context, _ *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) {
var (
memberId = contexts.GetUserId(ctx)
models *entity.AdminMember
)
if memberId <= 0 {
err = gerror.New("用户身份异常,请重新登录!")
return
}
if err = g.Model("admin_member").Fields("email").Where("id", memberId).Scan(&models); 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
}