Merge remote-tracking branch 'origin/master'

# Conflicts:
#	internal/controller/task/task_v1_ranking.go
This commit is contained in:
chy
2025-06-09 16:30:53 +08:00
23 changed files with 715 additions and 25 deletions

View File

@ -0,0 +1,10 @@
package consts
const (
GamelifeExtplatType = "bindcode"
GamelifeExtplatExtraMobile = "mobile"
GamelifeExtplatExtraPc = "pc"
GamelifeExtplatBoundTypeQQ = "qq"
GamelifeExtplatBoundTypeWX = "wx"
GamelifeMiniProgramBand = "1"
)

View File

@ -5,3 +5,8 @@ const (
UserBindPhoneKey = "user:bindPhone:%d"
UserCodeExpire = 5 * 60
)
const (
GameLifeUserKey = "gamelife:user:%s"
GameLifeUserExpire = 2 * 60 * 60
)

View File

@ -0,0 +1,17 @@
package user
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/user/v1"
)
func (c *ControllerV1) GetBoundUrl(ctx context.Context, req *v1.GetBoundUrlReq) (res *v1.GetBoundUrlRes, err error) {
out, err := service.User().BoundUrl(ctx, &model.UserBoundUrlIn{PopenId: req.PopenId, AppName: req.AppName, BindType: req.BindType, IsBound: true})
if err != nil {
return nil, err
}
return &v1.GetBoundUrlRes{Url: out.Url}, nil
}

View File

@ -0,0 +1,17 @@
package user
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/user/v1"
)
func (c *ControllerV1) GetUnboundUrl(ctx context.Context, req *v1.GetUnboundUrlReq) (res *v1.GetUnboundUrlRes, err error) {
out, err := service.User().UnBoundUrl(ctx, &model.UserBoundUrlIn{PopenId: req.PopenId, AppName: req.AppName, BindType: req.BindType, IsBound: false, Nickname: req.Nickname})
if err != nil {
return nil, err
}
return &v1.GetUnboundUrlRes{Url: out.Url}, nil
}

View File

@ -0,0 +1,17 @@
package user
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/user/v1"
)
func (c *ControllerV1) GetUserBoundInfo(ctx context.Context, req *v1.GetUserBoundInfoReq) (res *v1.GetUserBoundInfoRes, err error) {
out, err := service.User().BoundInfo(ctx, &model.UserBoundInfoIn{PopenId: req.PopenId})
if err != nil {
return nil, err
}
return &v1.GetUserBoundInfoRes{IsBound: out.IsBound}, nil
}

View File

@ -11,7 +11,7 @@ import (
"server/internal/model/entity"
"server/internal/service"
"server/utility/ecode"
utility "server/utility/encrypt"
"server/utility/encrypt"
"server/utility/jwt"
)
@ -54,7 +54,7 @@ func checkAdmin() {
return err
}
if !exist {
password, err := utility.EncryptPassword("Aa123456")
password, err := encrypt.EncryptPassword("Aa123456")
if err != nil {
return err
}
@ -91,7 +91,7 @@ func (s *sAdmin) Login(ctx context.Context, in *model.AdminLoginIn) (out *model.
if err := dao.Admins.Ctx(ctx).Where(do.Admins{Username: in.Username}).Scan(&admin); err != nil {
return nil, ecode.Fail.Sub("查询管理员失败")
}
if !utility.ComparePassword(admin.PasswordHash, in.Password) {
if !encrypt.ComparePassword(admin.PasswordHash, in.Password) {
return nil, ecode.Auth
}
value, err := dao.Roles.Ctx(ctx).WherePri(admin.RoleId).Fields(dao.Roles.Columns().Code).Value()

View File

@ -15,7 +15,7 @@ import (
"server/internal/model/entity"
"server/internal/service"
"server/utility/ecode"
utility "server/utility/encrypt"
"server/utility/encrypt"
"server/utility/jwt"
"server/utility/snowid"
)
@ -65,7 +65,7 @@ func (s *sMerchantAdmin) Login(ctx context.Context, in *model.MerchantLoginIn) (
if mAdmin[dao.MerchantAdmins.Columns().Status].Int() == consts.MerchantAdministratorDisable {
return nil, ecode.Params.Sub("该用户已被禁用")
}
if !utility.ComparePassword(mAdmin[dao.MerchantAdmins.Columns().PasswordHash].String(), in.Password) {
if !encrypt.ComparePassword(mAdmin[dao.MerchantAdmins.Columns().PasswordHash].String(), in.Password) {
return nil, ecode.Params.Sub("密码错误")
}
value, err := dao.Roles.Ctx(ctx).WherePri(mAdmin[dao.MerchantAdmins.Columns().RoleId].Int()).Fields(dao.Roles.Columns().Code).Value()
@ -145,7 +145,7 @@ func (s *sMerchantAdmin) Register(ctx context.Context, in *model.MerchantAdminRe
if code.String() != in.Code {
return nil, ecode.Fail.Sub("验证码错误")
}
hashPass, err := utility.EncryptPassword(in.Password)
hashPass, err := encrypt.EncryptPassword(in.Password)
if err != nil {
return nil, ecode.Fail.Sub("密码加密失败")
}

View File

@ -8,8 +8,9 @@ import (
"server/internal/model/do"
"server/internal/model/entity"
"server/internal/service"
"server/utility/encrypt"
"server/utility/ecode"
utility "server/utility/encrypt"
"server/utility/jwt"
)
@ -56,7 +57,7 @@ func (s *sStoreAdmin) Login(ctx context.Context, in *model.StoreAdminLoginIn) (o
if one[dao.StoreAdmins.Columns().Status].Int() == consts.StoreAdminDisable {
return nil, ecode.Params.Sub("该用户已被禁用")
}
if !utility.ComparePassword(one[dao.StoreAdmins.Columns().PasswordHash].String(), in.Password) {
if !encrypt.ComparePassword(one[dao.StoreAdmins.Columns().PasswordHash].String(), in.Password) {
return nil, ecode.Params.Sub("密码错误")
}
value, err := dao.Roles.Ctx(ctx).WherePri(one[dao.StoreAdmins.Columns().RoleId].Int()).Fields(dao.Roles.Columns().Code).Value()

View File

@ -3,6 +3,7 @@ package internal
import (
"context"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/gogf/gf/v2/frame/g"
"server/internal/consts"
"server/internal/dao"
@ -11,6 +12,7 @@ import (
"server/internal/model/entity"
"server/internal/service"
"server/utility/ecode"
"server/utility/gamelife"
"server/utility/jwt"
"github.com/gogf/gf/v2/os/gtime"
@ -200,3 +202,41 @@ func (s *sUser) List(ctx context.Context, in *model.UserListIn) (out *model.User
// 用于系统管理员、商户、门店查看用户列表, 展示用户最近的相关信息
return
}
func (s *sUser) BoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserBoundUrlOut, err error) {
url, err := gamelife.GetGamelifeClient(ctx).GetUrl(ctx, in.PopenId, in.AppName, "", in.BindType, in.IsBound)
if err != nil {
return nil, ecode.Fail.Sub("获取绑定链接失败")
}
return &model.UserBoundUrlOut{
Url: url,
}, nil
}
func (s *sUser) UnBoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserUnBoundUrlOut, err error) {
url, err := gamelife.GetGamelifeClient(ctx).GetUrl(ctx, in.PopenId, in.AppName, in.Nickname, in.BindType, in.IsBound)
if err != nil {
return nil, ecode.Fail.Sub("获取绑定链接失败")
}
return &model.UserUnBoundUrlOut{
Url: url,
}, nil
}
func (s *sUser) BoundInfo(ctx context.Context, in *model.UserBoundInfoIn) (out *model.UserBoundInfoOut, err error) {
url, err := gamelife.GetGamelifeClient(ctx).GetBound(ctx, in.PopenId)
if err != nil {
return nil, ecode.Fail.Sub("获取绑定信息失败")
}
var result model.UserBoundResult
resp, err := resty.New().R().SetResult(&result).Post(url)
if err != nil {
return nil, ecode.Fail.Sub("获取绑定信息失败")
}
if resp.StatusCode() != 200 {
return nil, ecode.Fail.Sub("获取绑定信息失败")
}
return &model.UserBoundInfoOut{
IsBound: result.Result,
}, nil
}

View File

@ -133,3 +133,38 @@ type GetPhoneCodeIn struct {
type GetPhoneCodeOut struct {
Success bool
}
type UserGamelifeCache struct {
Aes string `json:"aes"`
IV string `json:"iv"`
Token string `json:"token"`
}
type UserBoundResult struct {
Result bool `json:"result"`
Nick string `json:"nick"`
Ctime uint32 `json:"ctime"`
Utype int8 `json:"utype"`
AppName []string `json:"app_name"`
}
type UserBoundUrlIn struct {
PopenId string
BindType int
AppName string
Nickname string
IsBound bool
}
type UserBoundUrlOut struct {
Url string
}
type UserUnBoundUrlOut struct {
Url string
}
type UserBoundInfoIn struct {
PopenId string
}
type UserBoundInfoOut struct {
IsBound bool
}

View File

@ -4,6 +4,7 @@ import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
_ "server/utility/myCasbin"
_ "server/utility/rsa"
_ "server/utility/snowid"
_ "server/utility/wechat"
)

View File

@ -19,6 +19,9 @@ type (
Update(ctx context.Context, in *model.UserUpdateIn) (out *model.UpdateOut, err error)
BindPhone(ctx context.Context, in *model.UserBindPhoneIn) (out *model.UserBindPhoneOut, err error)
List(ctx context.Context, in *model.UserListIn) (out *model.UserListOut, err error)
BoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserBoundUrlOut, err error)
UnBoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserUnBoundUrlOut, err error)
BoundInfo(ctx context.Context, in *model.UserBoundInfoIn) (out *model.UserBoundInfoOut, err error)
}
)