fix
This commit is contained in:
parent
255c3c3c88
commit
33600c48eb
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.GetCanteenDetailReq
|
var req types.GetCanteenDetailReq
|
||||||
@ -55,7 +67,6 @@ func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx)
|
l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetCanteenDetail(&req, userinfo)
|
resp := l.GetCanteenDetail(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.SaveCanteenTypeProductReq
|
var req types.SaveCanteenTypeProductReq
|
||||||
@ -55,7 +67,6 @@ func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
|||||||
l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx)
|
l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx)
|
||||||
resp := l.SaveCanteenTypeProduct(&req, userinfo)
|
resp := l.SaveCanteenTypeProduct(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,7 +27,10 @@ func NewGetCanteenDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取餐厅详情
|
// 获取餐厅详情
|
||||||
func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq, loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||||
|
}
|
||||||
//获取餐厅类型数据
|
//获取餐厅类型数据
|
||||||
canteenTypeModel := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn)
|
canteenTypeModel := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn)
|
||||||
canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id)
|
canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id)
|
||||||
|
@ -29,7 +29,10 @@ func NewSaveCanteenTypeProductLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 保存餐厅类型的关联产品
|
// 保存餐厅类型的关联产品
|
||||||
func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq, loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||||
|
}
|
||||||
if len(req.ProductList) == 0 {
|
if len(req.ProductList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "product list can`t be empty")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "product list can`t be empty")
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,6 @@ type SaveCanteenProduct struct {
|
|||||||
SId string `json:"s_id"`
|
SId string `json:"s_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
@ -16,9 +16,29 @@ import (
|
|||||||
|
|
||||||
func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -27,23 +47,14 @@ func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l := logic.NewGetQrCodeSetListLogic(r.Context(), svcCtx)
|
l := logic.NewGetQrCodeSetListLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetQrCodeSetList(userinfo)
|
resp := l.GetQrCodeSetList(userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,9 +16,29 @@ import (
|
|||||||
|
|
||||||
func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -27,23 +47,14 @@ func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l := logic.NewGetStandardLogoListLogic(r.Context(), svcCtx)
|
l := logic.NewGetStandardLogoListLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetStandardLogoList(userinfo)
|
resp := l.GetStandardLogoList(userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.UploadQrcodeReq
|
var req types.UploadQrcodeReq
|
||||||
@ -55,7 +67,6 @@ func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewUploadQrcodeLogic(r.Context(), svcCtx)
|
l := logic.NewUploadQrcodeLogic(r.Context(), svcCtx)
|
||||||
resp := l.UploadQrcode(&req, userinfo)
|
resp := l.UploadQrcode(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,7 +27,10 @@ func NewGetQrCodeSetListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取二维码配置列表
|
// 获取二维码配置列表
|
||||||
func (l *GetQrCodeSetListLogic) GetQrCodeSetList(loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetQrCodeSetListLogic) GetQrCodeSetList(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||||
|
}
|
||||||
qrCodeModel := gmodel.NewFsQrcodeSetModel(l.svcCtx.MysqlConn)
|
qrCodeModel := gmodel.NewFsQrcodeSetModel(l.svcCtx.MysqlConn)
|
||||||
qrCodeList, err := qrCodeModel.GetAll(l.ctx)
|
qrCodeList, err := qrCodeModel.GetAll(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,7 +26,10 @@ func NewGetStandardLogoListLogic(ctx context.Context, svcCtx *svc2.ServiceContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取标准logo列表
|
// 获取标准logo列表
|
||||||
func (l *GetStandardLogoListLogic) GetStandardLogoList(loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetStandardLogoListLogic) GetStandardLogoList(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||||
|
}
|
||||||
standardLogoModel := gmodel.NewFsStandardLogoModel(l.svcCtx.MysqlConn)
|
standardLogoModel := gmodel.NewFsStandardLogoModel(l.svcCtx.MysqlConn)
|
||||||
logoList, err := standardLogoModel.GetAll(l.ctx)
|
logoList, err := standardLogoModel.GetAll(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,7 +27,10 @@ func NewUploadQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Uplo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成base64二维码
|
// 生成base64二维码
|
||||||
func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||||
|
}
|
||||||
if req.Url == "" {
|
if req.Url == "" {
|
||||||
resp.SetStatus(basic.CodeApiErr, "param url is empty")
|
resp.SetStatus(basic.CodeApiErr, "param url is empty")
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/map_library/internal/types"
|
"fusenapi/server/map-library/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
@ -0,0 +1,66 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/map-library/internal/logic"
|
||||||
|
"fusenapi/server/map-library/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
l := logic.NewGetMapLibraryListLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.GetMapLibraryList(userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
if resp != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
} else {
|
||||||
|
err := errors.New("server logic is error, resp must not be nil")
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
logx.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fusenapi/server/map_library/internal/svc"
|
"fusenapi/server/map-library/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
@ -3,14 +3,13 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/server/map_library/internal/types"
|
"fusenapi/server/map-library/internal/svc"
|
||||||
|
"fusenapi/server/map-library/internal/types"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"fusenapi/server/map_library/internal/svc"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,6 +28,9 @@ func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||||
|
}
|
||||||
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||||
mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx)
|
mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
"fusenapi/server/map_library/internal/config"
|
"fusenapi/server/map-library/internal/config"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"net/http"
|
"net/http"
|
@ -4,9 +4,9 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"fusenapi/server/map_library/internal/config"
|
"fusenapi/server/map-library/internal/config"
|
||||||
"fusenapi/server/map_library/internal/handler"
|
"fusenapi/server/map-library/internal/handler"
|
||||||
"fusenapi/server/map_library/internal/svc"
|
"fusenapi/server/map-library/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
@ -1,55 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/map_library/internal/logic"
|
|
||||||
"fusenapi/server/map_library/internal/svc"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// 解析jwtToken
|
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从Token里获取对应的信息
|
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
l := logic.NewGetMapLibraryListLogic(r.Context(), svcCtx)
|
|
||||||
resp := l.GetMapLibraryList(userinfo)
|
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
} else {
|
|
||||||
err := errors.New("server logic is error, resp must not be nil")
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
logx.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.GetProductListReq
|
var req types.GetProductListReq
|
||||||
@ -55,7 +67,6 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
|
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetProductList(&req, userinfo)
|
resp := l.GetProductList(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,9 +16,29 @@ import (
|
|||||||
|
|
||||||
func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -27,23 +47,14 @@ func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx)
|
l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetSizeByProduct(userinfo)
|
resp := l.GetSizeByProduct(userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.GetSuccessRecommandReq
|
var req types.GetSuccessRecommandReq
|
||||||
@ -55,7 +67,6 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx)
|
l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetSuccessRecommand(&req, userinfo)
|
resp := l.GetSuccessRecommand(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,7 +33,10 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取产品列表
|
// 获取产品列表
|
||||||
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
//如果是demo
|
//如果是demo
|
||||||
if req.IsDemo == 1 {
|
if req.IsDemo == 1 {
|
||||||
var demo types.GetProductListRsp
|
var demo types.GetProductListRsp
|
||||||
@ -52,7 +55,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||||||
}
|
}
|
||||||
//查询用户信息
|
//查询用户信息
|
||||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
userInfo, err := userModel.FindOne(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
|
@ -33,7 +33,10 @@ func NewGetSizeByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取分类下的产品以及尺寸
|
// 获取分类下的产品以及尺寸
|
||||||
func (l *GetSizeByProductLogic) GetSizeByProduct(loginInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetSizeByProductLogic) GetSizeByProduct(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
//获取所有网站目录
|
//获取所有网站目录
|
||||||
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||||
tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE)
|
tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE)
|
||||||
|
@ -27,6 +27,9 @@ func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext
|
|||||||
|
|
||||||
// 获取推荐的产品列表
|
// 获取推荐的产品列表
|
||||||
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, userInfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, userInfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userInfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
user, err := userModel.FindOne(l.ctx, userInfo.UserId)
|
user, err := userModel.FindOne(l.ctx, userInfo.UserId)
|
||||||
|
@ -96,9 +96,6 @@ type PriceObj struct {
|
|||||||
Price float64 `json:"price"`
|
Price float64 `json:"price"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.CartAddReq
|
var req types.CartAddReq
|
||||||
@ -55,7 +67,6 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewCartAddLogic(r.Context(), svcCtx)
|
l := logic.NewCartAddLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartAdd(&req, userinfo)
|
resp := l.CartAdd(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.CartDeleteReq
|
var req types.CartDeleteReq
|
||||||
@ -55,7 +67,6 @@ func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewCartDeleteLogic(r.Context(), svcCtx)
|
l := logic.NewCartDeleteLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartDelete(&req, userinfo)
|
resp := l.CartDelete(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.CartListReq
|
var req types.CartListReq
|
||||||
@ -55,7 +67,6 @@ func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewCartListLogic(r.Context(), svcCtx)
|
l := logic.NewCartListLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartList(&req, userinfo)
|
resp := l.CartList(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,9 +16,29 @@ import (
|
|||||||
|
|
||||||
func CartNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -27,23 +47,14 @@ func CartNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l := logic.NewCartNumberLogic(r.Context(), svcCtx)
|
l := logic.NewCartNumberLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartNumber(userinfo)
|
resp := l.CartNumber(userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.CartOrderDetailReq
|
var req types.CartOrderDetailReq
|
||||||
@ -55,7 +67,6 @@ func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewCartOrderDetailLogic(r.Context(), svcCtx)
|
l := logic.NewCartOrderDetailLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartOrderDetail(&req, userinfo)
|
resp := l.CartOrderDetail(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,9 +17,29 @@ import (
|
|||||||
|
|
||||||
func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
@ -28,17 +48,9 @@ func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// 从Token里获取对应的信息
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.ChangeOrderMethodReq
|
var req types.ChangeOrderMethodReq
|
||||||
@ -55,7 +67,6 @@ func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
l := logic.NewChangeOrderMethodLogic(r.Context(), svcCtx)
|
l := logic.NewChangeOrderMethodLogic(r.Context(), svcCtx)
|
||||||
resp := l.ChangeOrderMethod(&req, userinfo)
|
resp := l.ChangeOrderMethod(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,6 +31,9 @@ func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLo
|
|||||||
|
|
||||||
// 添加入购物车
|
// 添加入购物车
|
||||||
func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
if req.BuyNum == 0 {
|
if req.BuyNum == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param buy_num can`t be 0")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param buy_num can`t be 0")
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,9 @@ func NewCartDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *CartDeleteLogic) CartDelete(req *types.CartDeleteReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CartDeleteLogic) CartDelete(req *types.CartDeleteReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
if req.Id <= 0 {
|
if req.Id <= 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param id")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param id")
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,9 @@ func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartList
|
|||||||
|
|
||||||
// 获取用户购物车列表
|
// 获取用户购物车列表
|
||||||
func (l *CartListLogic) CartList(req *types.CartListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CartListLogic) CartList(req *types.CartListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
//获取当前图片应该返回的尺寸大小
|
//获取当前图片应该返回的尺寸大小
|
||||||
if req.Size > 0 {
|
if req.Size > 0 {
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
|
@ -27,6 +27,9 @@ func NewCartNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartNu
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *CartNumberLogic) CartNumber(userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CartNumberLogic) CartNumber(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
cartModel := gmodel.NewFsCartModel(l.svcCtx.MysqlConn)
|
cartModel := gmodel.NewFsCartModel(l.svcCtx.MysqlConn)
|
||||||
total, err := cartModel.CountUserCart(l.ctx, userinfo.UserId)
|
total, err := cartModel.CountUserCart(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,6 +31,9 @@ func NewCartOrderDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *CartOrderDetailLogic) CartOrderDetail(req *types.CartOrderDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CartOrderDetailLogic) CartOrderDetail(req *types.CartOrderDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
req.Sn = strings.Trim(req.Sn, " ")
|
req.Sn = strings.Trim(req.Sn, " ")
|
||||||
if req.Sn == "" {
|
if req.Sn == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
||||||
|
@ -30,6 +30,9 @@ func NewChangeOrderMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *ChangeOrderMethodLogic) ChangeOrderMethod(req *types.ChangeOrderMethodReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *ChangeOrderMethodLogic) ChangeOrderMethod(req *types.ChangeOrderMethodReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
req.Sn = strings.Trim(req.Sn, " ")
|
req.Sn = strings.Trim(req.Sn, " ")
|
||||||
if req.Sn == "" {
|
if req.Sn == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user