更新一次
This commit is contained in:
parent
08e6f00ff5
commit
2f01aa24c4
|
@ -12,3 +12,9 @@ type response {
|
|||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
|
||||
type Auth {
|
||||
AccessSecret string `json:"AccessSecret"`
|
||||
AccessExpire int `json:"AccessExpire"`
|
||||
}
|
34
ddl/fs_user.sql
Normal file
34
ddl/fs_user.sql
Normal file
|
@ -0,0 +1,34 @@
|
|||
-- fusentest.fs_user definition
|
||||
|
||||
CREATE TABLE `fs_user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`face_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'facebook的userid',
|
||||
`sub` bigint(20) NOT NULL DEFAULT '0' COMMENT 'google的sub',
|
||||
`first_name` varchar(64) DEFAULT NULL COMMENT 'FirstName',
|
||||
`last_name` varchar(64) DEFAULT NULL COMMENT 'LastName',
|
||||
`username` varchar(255) DEFAULT NULL COMMENT '用户名',
|
||||
`company` varchar(64) DEFAULT NULL COMMENT '公司名称',
|
||||
`mobile` varchar(16) DEFAULT NULL COMMENT '手机号码',
|
||||
`auth_key` varchar(32) NOT NULL,
|
||||
`password_hash` varchar(255) NOT NULL,
|
||||
`verification_token` varchar(255) DEFAULT NULL,
|
||||
`password_reset_token` varchar(255) DEFAULT NULL,
|
||||
`email` varchar(255) NOT NULL COMMENT '邮箱',
|
||||
`type` tinyint(1) NOT NULL COMMENT '1普通餐厅 2连锁餐厅',
|
||||
`status` tinyint(3) unsigned DEFAULT '1' COMMENT '1正常 0不正常',
|
||||
`is_del` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 1删除',
|
||||
`created_at` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
|
||||
`updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
|
||||
`is_order_status_email` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单状态改变时是否接收邮件',
|
||||
`is_email_advertisement` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否接收邮件广告',
|
||||
`is_order_status_phone` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单状态改变是是否接收电话',
|
||||
`is_phone_advertisement` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否接收短信广告',
|
||||
`is_open_render` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否打开个性化渲染(1:开启,0:关闭)',
|
||||
`is_thousand_face` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已经存在千人千面(1:存在,0:不存在)',
|
||||
`is_low_rendering` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0' COMMENT '是否开启低渲染模型渲染',
|
||||
`is_remove_bg` tinyint(1) NOT NULL DEFAULT '1' COMMENT '用户上传logo是否去除背景',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `email` (`email`) USING BTREE,
|
||||
UNIQUE KEY `username` (`username`) USING BTREE,
|
||||
UNIQUE KEY `password_reset_token` (`password_reset_token`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='用户表';
|
|
@ -14,15 +14,69 @@ type request {
|
|||
// Name string `form:"name"` // parameters are auto validated
|
||||
}
|
||||
|
||||
type GetTypeData {
|
||||
// UserLoginHandler 用户登录请求结构
|
||||
type RequestUserLogin {
|
||||
Name string `form:"name"`
|
||||
Password string `form:"pwd"`
|
||||
}
|
||||
|
||||
// UserLoginHandler 用户登录请求结构
|
||||
type DataUserLogin {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// UserBasicInfoHandler 返回data结构
|
||||
type DataUserBasicInfo {
|
||||
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是否去除背景
|
||||
}
|
||||
|
||||
// /user/get-type reponse.data 结构
|
||||
type DataGetType {
|
||||
Id int64 `db:"id" json:"key"` // ID
|
||||
Name string `db:"name" json:"name"` // 餐厅名字
|
||||
}
|
||||
|
||||
service home-user-auth {
|
||||
|
||||
@handler UserLoginHandler
|
||||
post /user/login(RequestUserLogin) returns (response);
|
||||
|
||||
@handler UserFontsHandler
|
||||
get /user/fonts(request) returns (response);
|
||||
|
||||
@handler GetTypeHandler
|
||||
get /user/get-type(request) returns (response);
|
||||
}
|
||||
|
||||
@server(
|
||||
jwt: Auth
|
||||
)
|
||||
service home-user-auth {
|
||||
@handler UserBasicInfoHandler
|
||||
get /user/basic-info(request) returns (response);
|
||||
}
|
|
@ -2,3 +2,8 @@ Name: home-user-auth
|
|||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
DataSource: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
|
||||
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
AccessExpire: 604800
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
import (
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
DataSource string
|
||||
Auth types.Auth
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ import (
|
|||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/login",
|
||||
Handler: UserLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/fonts",
|
||||
|
@ -24,4 +29,15 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
},
|
||||
},
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/basic-info",
|
||||
Handler: UserBasicInfoHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
)
|
||||
}
|
||||
|
|
29
home-user-auth/internal/handler/userbasicinfohandler.go
Normal file
29
home-user-auth/internal/handler/userbasicinfohandler.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserBasicInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserBasicInfo(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
28
home-user-auth/internal/handler/userloginhandler.go
Normal file
28
home-user-auth/internal/handler/userloginhandler.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RequestUserLogin
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserLogin(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
31
home-user-auth/internal/logic/userbasicinfologic.go
Normal file
31
home-user-auth/internal/logic/userbasicinfologic.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserBasicInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBasicInfoLogic {
|
||||
return &UserBasicInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
// l.svcCtx.FsUserModel.FindOne(l.ctx, )
|
||||
return
|
||||
}
|
62
home-user-auth/internal/logic/userloginlogic.go
Normal file
62
home-user-auth/internal/logic/userloginlogic.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserLoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
|
||||
return &UserLoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserLoginLogic) getJwtToken(secretKey string, iat, seconds, userId int64) (string, error) {
|
||||
claims := make(jwt.MapClaims)
|
||||
claims["exp"] = iat + seconds
|
||||
claims["iat"] = iat
|
||||
claims["userId"] = userId
|
||||
token := jwt.New(jwt.SigningMethodHS256)
|
||||
token.Claims = claims
|
||||
return token.SignedString([]byte(secretKey))
|
||||
}
|
||||
|
||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
data, err := l.svcCtx.FsUserModel.FindOneByEmail(l.ctx, req.Name)
|
||||
// logx.Info(err.Error())
|
||||
log.Printf("%t %t %v", err, model.ErrNotFound, err == model.ErrNotFound)
|
||||
if err == model.ErrNotFound {
|
||||
// logx.Error(err)
|
||||
resp = &types.Response{
|
||||
Code: 304,
|
||||
Message: "fail",
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
resp = &types.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: &types.DataUserLogin{
|
||||
Token: data.PasswordResetToken.String,
|
||||
},
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
|
@ -11,6 +11,7 @@ type ServiceContext struct {
|
|||
Config config.Config
|
||||
FsFontModel model.FsFontModel
|
||||
FsCanteenTypeModel model.FsCanteenTypeModel
|
||||
FsUserModel model.FsUserModel
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
@ -19,5 +20,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
Config: c,
|
||||
FsFontModel: model.NewFsFontModel(conn),
|
||||
FsCanteenTypeModel: model.NewFsCanteenTypeModel(conn),
|
||||
FsUserModel: model.NewFsUserModel(conn),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,45 @@ package types
|
|||
type Request struct {
|
||||
}
|
||||
|
||||
type GetTypeData struct {
|
||||
type RequestUserLogin struct {
|
||||
Name string `form:"name"`
|
||||
Password string `form:"pwd"`
|
||||
}
|
||||
|
||||
type DataUserLogin struct {
|
||||
Token string `json:"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 DataGetType struct {
|
||||
Id int64 `db:"id" json:"key"` // ID
|
||||
Name string `db:"name" json:"name"` // 餐厅名字
|
||||
}
|
||||
|
@ -14,3 +52,8 @@ type Response struct {
|
|||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
AccessSecret string `json:"AccessSecret"`
|
||||
AccessExpire int `json:"AccessExpire"`
|
||||
}
|
||||
|
|
24
model/fsusermodel.go
Executable file
24
model/fsusermodel.go
Executable file
|
@ -0,0 +1,24 @@
|
|||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ FsUserModel = (*customFsUserModel)(nil)
|
||||
|
||||
type (
|
||||
// FsUserModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customFsUserModel.
|
||||
FsUserModel interface {
|
||||
fsUserModel
|
||||
}
|
||||
|
||||
customFsUserModel struct {
|
||||
*defaultFsUserModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewFsUserModel returns a model for the database table.
|
||||
func NewFsUserModel(conn sqlx.SqlConn) FsUserModel {
|
||||
return &customFsUserModel{
|
||||
defaultFsUserModel: newFsUserModel(conn),
|
||||
}
|
||||
}
|
153
model/fsusermodel_gen.go
Executable file
153
model/fsusermodel_gen.go
Executable file
|
@ -0,0 +1,153 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
fsUserFieldNames = builder.RawFieldNames(&FsUser{})
|
||||
fsUserRows = strings.Join(fsUserFieldNames, ",")
|
||||
fsUserRowsExpectAutoSet = strings.Join(stringx.Remove(fsUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
fsUserRowsWithPlaceHolder = strings.Join(stringx.Remove(fsUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
fsUserModel interface {
|
||||
Insert(ctx context.Context, data *FsUser) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*FsUser, error)
|
||||
FindOneByEmail(ctx context.Context, email string) (*FsUser, error)
|
||||
FindOneByPasswordResetToken(ctx context.Context, passwordResetToken sql.NullString) (*FsUser, error)
|
||||
FindOneByUsername(ctx context.Context, username sql.NullString) (*FsUser, error)
|
||||
Update(ctx context.Context, data *FsUser) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultFsUserModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
FsUser struct {
|
||||
Id int64 `db:"id"` // ID
|
||||
FaceId int64 `db:"face_id"` // facebook的userid
|
||||
Sub int64 `db:"sub"` // google的sub
|
||||
FirstName sql.NullString `db:"first_name"` // FirstName
|
||||
LastName sql.NullString `db:"last_name"` // LastName
|
||||
Username sql.NullString `db:"username"` // 用户名
|
||||
Company sql.NullString `db:"company"` // 公司名称
|
||||
Mobile sql.NullString `db:"mobile"` // 手机号码
|
||||
AuthKey string `db:"auth_key"`
|
||||
PasswordHash string `db:"password_hash"`
|
||||
VerificationToken sql.NullString `db:"verification_token"`
|
||||
PasswordResetToken sql.NullString `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是否去除背景
|
||||
}
|
||||
)
|
||||
|
||||
func newFsUserModel(conn sqlx.SqlConn) *defaultFsUserModel {
|
||||
return &defaultFsUserModel{
|
||||
conn: conn,
|
||||
table: "`fs_user`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) Delete(ctx context.Context, id int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) FindOne(ctx context.Context, id int64) (*FsUser, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsUserRows, m.table)
|
||||
var resp FsUser
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) FindOneByEmail(ctx context.Context, email string) (*FsUser, error) {
|
||||
var resp FsUser
|
||||
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", fsUserRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) FindOneByPasswordResetToken(ctx context.Context, passwordResetToken sql.NullString) (*FsUser, error) {
|
||||
var resp FsUser
|
||||
query := fmt.Sprintf("select %s from %s where `password_reset_token` = ? limit 1", fsUserRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, passwordResetToken)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) FindOneByUsername(ctx context.Context, username sql.NullString) (*FsUser, error) {
|
||||
var resp FsUser
|
||||
query := fmt.Sprintf("select %s from %s where `username` = ? limit 1", fsUserRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, username)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) Insert(ctx context.Context, data *FsUser) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsUserRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.FaceId, data.Sub, data.FirstName, data.LastName, data.Username, data.Company, data.Mobile, data.AuthKey, data.PasswordHash, data.VerificationToken, data.PasswordResetToken, data.Email, data.Type, data.Status, data.IsDel, data.IsOrderStatusEmail, data.IsEmailAdvertisement, data.IsOrderStatusPhone, data.IsPhoneAdvertisement, data.IsOpenRender, data.IsThousandFace, data.IsLowRendering, data.IsRemoveBg)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) Update(ctx context.Context, newData *FsUser) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsUserRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.FaceId, newData.Sub, newData.FirstName, newData.LastName, newData.Username, newData.Company, newData.Mobile, newData.AuthKey, newData.PasswordHash, newData.VerificationToken, newData.PasswordResetToken, newData.Email, newData.Type, newData.Status, newData.IsDel, newData.IsOrderStatusEmail, newData.IsEmailAdvertisement, newData.IsOrderStatusPhone, newData.IsPhoneAdvertisement, newData.IsOpenRender, newData.IsThousandFace, newData.IsLowRendering, newData.IsRemoveBg, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsUserModel) tableName() string {
|
||||
return m.table
|
||||
}
|
Loading…
Reference in New Issue
Block a user