所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数
This commit is contained in:
@@ -12,10 +12,11 @@ import (
|
||||
"fusenapi/utils/encryption_decryption"
|
||||
"fusenapi/utils/id_generator"
|
||||
"fusenapi/utils/ip"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -23,6 +24,7 @@ type DesignGatherLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
ipAddr string
|
||||
}
|
||||
|
||||
func NewDesignGatherLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DesignGatherLogic {
|
||||
@@ -33,7 +35,23 @@ func NewDesignGatherLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Desi
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *auth.UserInfo, r *http.Request) (resp *basic.Response) {
|
||||
// 处理进入前逻辑w,r
|
||||
func (l *DesignGatherLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
//获取ip地址
|
||||
ipAddr, err := ip.GetClientIP(r)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "client ip is not available")
|
||||
}
|
||||
l.ipAddr = ipAddr
|
||||
}
|
||||
|
||||
func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if l.ipAddr == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "client ip is not available")
|
||||
}
|
||||
|
||||
encryptWebsetting, err := l.svcCtx.AllModels.FsWebSet.FindValueByKey(l.ctx, "is_encrypt")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -60,13 +78,12 @@ func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *a
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json data,format may be invalid")
|
||||
}
|
||||
}
|
||||
//获取ip地址
|
||||
ipAddr, err := ip.GetClientIP(r)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "client ip is not available")
|
||||
}
|
||||
postInfo["client_ip"] = ipAddr
|
||||
postInfo["client_ip"] = l.ipAddr
|
||||
var (
|
||||
optionalId int64
|
||||
sizeId int64
|
||||
@@ -129,7 +146,7 @@ func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *a
|
||||
Cover: &cover,
|
||||
Info: &info,
|
||||
Utime: &now,
|
||||
ClientIp: &ipAddr,
|
||||
ClientIp: &l.ipAddr,
|
||||
ClientNo: &clientNo,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -33,7 +33,7 @@ func NewGetSizeByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||
}
|
||||
|
||||
// 获取分类下的产品以及尺寸
|
||||
func (l *GetSizeByProductLogic) GetSizeByProduct(userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user