调整微信扫码登录相关接口,拆分门店奖励:奖励类型、奖励详情

This commit is contained in:
2025-06-03 11:06:00 +08:00
parent ea87bc829e
commit fdc9cc3463
37 changed files with 698 additions and 189 deletions

View File

@ -2,6 +2,8 @@ package admin
import (
"context"
"github.com/gogf/gf/v2/os/glog"
"server/internal/consts"
"server/internal/dao"
"server/internal/model"
"server/internal/model/do"
@ -19,8 +21,29 @@ func New() service.IAdmin {
return &sAdmin{}
}
func checkAdmin() {
ctx := context.Background()
exist, err := dao.Admins.Ctx(ctx).Where(do.Admins{Username: "admin"}).Exist()
if err != nil {
panic("初始化管理员失败")
}
if !exist {
passwordHash, _ := utility.EncryptPassword("Aa123456")
_, err = dao.Admins.Ctx(ctx).Insert(do.Admins{
Username: "admin",
PasswordHash: passwordHash,
Status: 1,
})
if err != nil {
panic("初始化管理员失败")
}
}
glog.Infof(ctx, "初始化管理员成功")
}
func init() {
service.RegisterAdmin(New())
go checkAdmin()
}
func (s *sAdmin) Login(ctx context.Context, in *model.AdminLoginIn) (out *model.LoginOut, err error) {
exist, err := dao.Admins.Ctx(ctx).Exist(do.Admins{Username: in.Username})
@ -35,12 +58,13 @@ func (s *sAdmin) Login(ctx context.Context, in *model.AdminLoginIn) (out *model.
return nil, ecode.Fail.Sub("查询管理员失败")
}
if !utility.ComparePassword(admin.PasswordHash, in.Password) {
return nil, ecode.Auth.Sub("密码错误")
return nil, ecode.Auth
}
token, err := jwt.GenerateToken(&jwt.TokenIn{UserId: admin.Id, Permission: "admin"})
token, err := jwt.GenerateToken(&jwt.TokenIn{UserId: admin.Id, Permission: consts.AdminPermission})
if err != nil {
return nil, ecode.Fail.Sub("生成token失败")
}
out = &model.LoginOut{
Token: token,
}
@ -55,5 +79,12 @@ func (s *sAdmin) Info(ctx context.Context, in *model.AdminInfoIn) (out *model.Ad
if !exist {
return nil, ecode.Params.Sub("该用户不存在")
}
var admin entity.Admins
if err := dao.Admins.Ctx(ctx).WherePri(in.Id).Scan(&admin); err != nil {
return nil, ecode.Fail.Sub("查询管理员失败")
}
out = &model.AdminInfoOut{
Username: admin.Username,
}
return
}