修复序列化代码

This commit is contained in:
eson
2023-06-15 16:08:43 +08:00
parent f3be74e78c
commit ab4e5852c1
51 changed files with 538 additions and 369 deletions

View File

@@ -1,6 +1,7 @@
package logic
import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@@ -31,8 +32,15 @@ func (l *AcceptCookieLogic) AcceptCookie(req *types.Request, userinfo *auth.User
// userinfo 传入值时, 一定不为null
idtyp := userinfo.GetIdType()
if idtyp == auth.IDTYPE_Guest {
return resp.SetStatus(basic.CodeDupGuestErr)
return resp.SetStatus(basic.CodeGuestDupErr)
}
return resp.SetStatus(basic.CodeOK)
m := gmodel.NewFsGuestModel(l.svcCtx.MysqlConn)
token, err := m.GenerateGuestID(l.ctx, &l.svcCtx.Config.Auth.AccessSecret)
if err != nil {
return resp.SetStatus(basic.CodeGuestGenErr)
}
return resp.SetStatus(basic.CodeOK, types.DataGuest{
Token: token,
})
}

View File

@@ -3,7 +3,7 @@ package logic
import (
"context"
"fusenapi/model"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
@@ -28,7 +28,7 @@ func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
m := model.NewFsAddressModel(l.svcCtx.MysqlConn)
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
userinfo.GetIdType()
// user := auth.GetUserInfoFormCtx(l.ctx)
// if user.UserId == 0 {
@@ -36,7 +36,7 @@ func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *aut
// }
// user.UserId = 22
// model里设置了 返回值. 和 types 里的一至可以直接返回
data, err := m.FindDataAddressList(l.ctx, 22)
data, err := m.GetUserAllAddress(l.ctx, 22)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())

View File

@@ -2,7 +2,7 @@ package logic
import (
"context"
"fusenapi/model"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
@@ -26,14 +26,37 @@ func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Use
}
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
if loginInfo.UserId == 0 {
return resp.SetStatus(basic.CodeOK, "parse login info err ")
if !userinfo.IsUser() {
// 返回未授权
return resp.SetStatus(basic.CodeUnAuth)
}
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := m.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.Set(510, err.Error())
return resp.SetStatus(basic.CodeServiceErr)
}
return resp.SetStatus(basic.CodeOK, fsUserModel)
// $userInfo->type = $userInfo->type != 0 ? $userInfo->type : '';
// $userInfo->is_order_status_email = (boolean)$userInfo->is_order_status_email;
// $userInfo->is_email_advertisement = (boolean)$userInfo->is_email_advertisement;
// $userInfo->is_order_status_phone = (boolean)$userInfo->is_order_status_phone;
// $userInfo->is_phone_advertisement = (boolean)$userInfo->is_phone_advertisement;
// $userInfo->is_open_render = (boolean)$userInfo->is_open_render;
// $userInfo->is_low_rendering = (boolean)$userInfo->is_low_rendering;
// $userInfo->is_remove_bg = (boolean)$userInfo->is_remove_bg;
return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{
Type: *user.Type,
IsOrderStatusEmail: *user.IsOrderStatusEmail > 0,
IsEmailAdvertisement: *user.IsEmailAdvertisement > 0,
IsOrderStatusPhone: *user.IsOrderStatusPhone > 0,
IsPhoneAdvertisement: *user.IsPhoneAdvertisement > 0,
IsOpenRender: *user.IsOpenRender > 0,
IsLowRendering: *user.IsLowRendering > 0,
IsRemoveBg: *user.IsRemoveBg > 0,
})
}

View File

@@ -3,13 +3,14 @@ package logic
import (
"context"
"fusenapi/model"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type UserFontsLogic struct {
@@ -27,11 +28,10 @@ func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFon
}
func (l *UserFontsLogic) UserFonts(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
data, err := model.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
if err != nil {
data, err := gmodel.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
if err != gorm.ErrRecordNotFound && err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOK, data)
}
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -3,7 +3,7 @@ package logic
import (
"context"
"fusenapi/model"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
@@ -28,8 +28,12 @@ func NewUserGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserG
func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatus(basic.CodeUnAuth)
}
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return

View File

@@ -4,13 +4,14 @@ import (
"context"
"time"
"fusenapi/model"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type UserLoginLogic struct {
@@ -29,26 +30,23 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Response, jwtToken string) {
// 创建一个 FsUserModel 对象 m 并实例化之,该对象用于操作 MySQL 数据库中的用户数据表。
m := model.NewFsUserModel(l.svcCtx.MysqlConn)
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
// 在用户数据表中根据登录名查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
userModel, err := m.FindOneByEmail(l.ctx, req.Name)
// 如果在用户数据表中没有找到登录名匹配的用户记录,则抛出 ErrNotFound 错误并返回未认证的状态码以及错误信息。
if err == model.ErrNotFound {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()), jwtToken
// 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
user, err := m.FindUserByEmail(l.ctx, req.Name)
if err == gorm.ErrRecordNotFound {
return resp.SetStatus(basic.CodeEmailNotFoundErr), ""
}
// 如果在用户数据表中找到了登录名匹配的用户记录,则判断密码是否匹配。
if userModel.PasswordHash != req.Password {
if *user.PasswordHash != req.Password {
logx.Info("密码错误")
return resp.SetStatusWithMessage(basic.CodeUnAuth, "密码错误"), jwtToken
return resp.SetStatus(basic.CodePasswordErr), jwtToken
}
// 如果密码匹配,则生成 JWT Token。
nowSec := time.Now().Unix()
jwtToken, err = auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, int64(userModel.Id), 0)
jwtToken, err = auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0)
// 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。
if err != nil {
@@ -56,9 +54,6 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Res
return resp.SetStatus(basic.CodeUnAuth), jwtToken
}
// 更新 MySQL 数据库中用户记录对应的 VerificationToken 字段值为生成的 JWT Token。
err = m.UpdateVerificationToken(l.ctx, userModel.Id, jwtToken)
// 如果更新 VerificationToken 字段失败,则返回未认证的状态码。
if err != nil {
return resp.SetStatus(basic.CodeUnAuth), jwtToken

View File

@@ -2,9 +2,9 @@ package logic
import (
"context"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/model"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
@@ -27,19 +27,16 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *basic.Response) {
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
if loginInfo.UserId == 0 {
return resp.SetStatus(basic.CodeOK, "parse login info err ")
}
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
if err != nil {
if err == model.ErrNotFound {
return resp
}
logx.Error(err)
return resp
if !userinfo.IsUser() {
return resp.SetStatus(basic.CodeUnAuth)
}
return resp.SetStatus(basic.CodeOK, fsUserModel)
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := m.FindUserById(l.ctx, userinfo.UserId)
if err == gmodel.ErrRecordNotFound {
return resp.SetStatus(basic.CodeUserIdNotFoundErr)
}
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -3,22 +3,23 @@ package svc
import (
"errors"
"fmt"
"fusenapi/initalize"
"fusenapi/server/home-user-auth/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
MysqlConn sqlx.SqlConn
MysqlConn *gorm.DB
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.SourceMysql),
MysqlConn: initalize.InitMysql(c.SourceMysql),
}
}

View File

@@ -14,7 +14,6 @@ type RequestBasicInfoForm struct {
Company string `form:"company,optional" db:"company"` // 公司名称
Mobile string `form:"mobile,optional" db:"mobile"` // 手机号码
Email string `form:"email" db:"email"` // 邮箱
Status int64 `form:"status,optional" db:"status"` // 1正常 0不正常
IsOrderStatusEmail int64 `form:"is_order_status_email,optional" db:"is_order_status_email"` // 订单状态改变时是否接收邮件
IsEmailAdvertisement int64 `form:"is_email_advertisement,optional" db:"is_email_advertisement"` // 是否接收邮件广告
IsOrderStatusPhone int64 `form:"is_order_status_phone,optional" db:"is_order_status_phone"` // 订单状态改变是是否接收电话
@@ -22,7 +21,6 @@ type RequestBasicInfoForm struct {
IsOpenRender int64 `form:"is_open_render,optional" db:"is_open_render"` // 是否打开个性化渲染1开启0关闭
IsLowRendering int64 `form:"is_low_rendering,optional" db:"is_low_rendering"` // 是否开启低渲染模型渲染
IsRemoveBg int64 `form:"is_remove_bg,optional" db:"is_remove_bg"` // 用户上传logo是否去除背景
NewPassword string `form:"new_password,optional" db:"new_password"` // new_password 如果存在新密码
}
type RequestUserLogin struct {
@@ -31,37 +29,23 @@ type RequestUserLogin struct {
}
type DataUserLogin struct {
Token string `json:"token"` // 充值密码token
JwtToken string `json:"jwt_token"` // jwt 的Token
Token string `json:"token"` // 登录jwt token
}
type DataGuest struct {
Token string `json:"token"` // 登录jwt token
}
type DataUserBasicInfo struct {
Id int64 `db:"id"` // ID
FaceId int64 `db:"face_id"` // facebook的userid
Sub int64 `db:"sub"` // google的sub
FirstName string `db:"first_name"` // FirstName
LastName string `db:"last_name"` // LastName
Username string `db:"username"` // 用户名
Company string `db:"company"` // 公司名称
Mobile string `db:"mobile"` // 手机号码
AuthKey string `db:"auth_key"`
PasswordHash string `db:"password_hash"`
VerificationToken string `db:"verification_token"`
PasswordResetToken string `db:"password_reset_token"`
Email string `db:"email"` // 邮箱
Type int64 `db:"type"` // 1普通餐厅 2连锁餐厅
Status int64 `db:"status"` // 1正常 0不正常
IsDel int64 `db:"is_del"` // 是否删除 1删除
CreatedAt int64 `db:"created_at"` // 添加时间
UpdatedAt int64 `db:"updated_at"` // 更新时间
IsOrderStatusEmail int64 `db:"is_order_status_email"` // 订单状态改变时是否接收邮件
IsEmailAdvertisement int64 `db:"is_email_advertisement"` // 是否接收邮件广告
IsOrderStatusPhone int64 `db:"is_order_status_phone"` // 订单状态改变是是否接收电话
IsPhoneAdvertisement int64 `db:"is_phone_advertisement"` // 是否接收短信广告
IsOpenRender int64 `db:"is_open_render"` // 是否打开个性化渲染1开启0关闭
IsThousandFace int64 `db:"is_thousand_face"` // 是否已经存在千人千面1存在0不存在
IsLowRendering int64 `db:"is_low_rendering"` // 是否开启低渲染模型渲染
IsRemoveBg int64 `db:"is_remove_bg"` // 用户上传logo是否去除背景
Type int64 `db:"type"` // 1普通餐厅 2连锁餐厅
IsOrderStatusEmail bool `db:"is_order_status_email"` // 订单状态改变时是否接收邮件
IsEmailAdvertisement bool `db:"is_email_advertisement"` // 是否接收邮件广告
IsOrderStatusPhone bool `db:"is_order_status_phone"` // 订单状态改变是是否接收电话
IsPhoneAdvertisement bool `db:"is_phone_advertisement"` // 是否接收短信广告
IsOpenRender bool `db:"is_open_render"` // 是否打开个性化渲染1开启0关闭
IsThousandFace bool `db:"is_thousand_face"` // 是否已经存在千人千面1存在0不存在
IsLowRendering bool `db:"is_low_rendering"` // 是否开启低渲染模型渲染
IsRemoveBg bool `db:"is_remove_bg"` // 用户上传logo是否去除背景
}
type DataGetType struct {