2025-01-10 00:09:25 +08:00
|
|
|
|
package query
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/hex"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"qnc-server/app/main/api/internal/service"
|
2025-06-19 14:34:32 +08:00
|
|
|
|
"qnc-server/app/main/model"
|
2025-04-11 13:10:17 +08:00
|
|
|
|
"qnc-server/common/ctxdata"
|
|
|
|
|
"qnc-server/common/xerr"
|
|
|
|
|
"qnc-server/pkg/lzkit/crypto"
|
|
|
|
|
"qnc-server/pkg/lzkit/validator"
|
2025-01-10 00:09:25 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
2025-03-17 15:59:09 +08:00
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
|
|
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"qnc-server/app/main/api/internal/svc"
|
|
|
|
|
"qnc-server/app/main/api/internal/types"
|
2025-01-10 00:09:25 +08:00
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type QueryServiceLogic struct {
|
|
|
|
|
logx.Logger
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewQueryServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryServiceLogic {
|
|
|
|
|
return &QueryServiceLogic{
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *QueryServiceLogic) QueryService(req *types.QueryServiceReq) (resp *types.QueryServiceResp, err error) {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if req.AgentIdentifier != "" {
|
|
|
|
|
l.ctx = context.WithValue(l.ctx, "agentIdentifier", req.AgentIdentifier)
|
2025-03-14 02:56:27 +08:00
|
|
|
|
} else if req.App {
|
|
|
|
|
l.ctx = context.WithValue(l.ctx, "app", req.App)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
return l.PreprocessLogic(req, req.Product)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceReq) (*types.QueryServiceResp, error){
|
2025-05-26 19:05:28 +08:00
|
|
|
|
"marriage": (*QueryServiceLogic).ProcessMarriageLogic,
|
|
|
|
|
"homeservice": (*QueryServiceLogic).ProcessHomeServiceLogic,
|
|
|
|
|
"riskassessment": (*QueryServiceLogic).ProcessRiskAssessmentLogic,
|
|
|
|
|
"companyinfo": (*QueryServiceLogic).ProcessCompanyInfoLogic,
|
|
|
|
|
"rentalinfo": (*QueryServiceLogic).ProcessRentalInfoLogic,
|
|
|
|
|
"preloanbackgroundcheck": (*QueryServiceLogic).ProcessPreLoanBackgroundCheckLogic,
|
|
|
|
|
"backgroundcheck": (*QueryServiceLogic).ProcessBackgroundCheckLogic,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) {
|
|
|
|
|
if processor, exists := productProcessors[product]; exists {
|
|
|
|
|
return processor(l, req) // 调用对应的处理函数
|
|
|
|
|
}
|
|
|
|
|
return nil, errors.New("未找到相应的处理程序")
|
|
|
|
|
}
|
|
|
|
|
func (l *QueryServiceLogic) ProcessMarriageLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.MarriageReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验二要素
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "marriage", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
|
2025-03-07 03:48:59 +08:00
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理家政服务相关逻辑
|
|
|
|
|
func (l *QueryServiceLogic) ProcessHomeServiceLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.HomeServiceReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验二要素
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "homeservice", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理风险评估相关逻辑
|
|
|
|
|
func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.RiskAssessmentReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验二要素
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "riskassessment", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理公司信息查询相关逻辑
|
|
|
|
|
func (l *QueryServiceLogic) ProcessCompanyInfoLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.CompanyInfoReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验二要素
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "companyinfo", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理租赁信息查询相关逻辑
|
|
|
|
|
func (l *QueryServiceLogic) ProcessRentalInfoLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.RentalInfoReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验二要素
|
2025-01-10 00:09:25 +08:00
|
|
|
|
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "rentalinfo", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理贷前背景检查相关逻辑
|
|
|
|
|
func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.PreLoanBackgroundCheckReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验二要素
|
2025-01-10 00:09:25 +08:00
|
|
|
|
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "preloanbackgroundcheck", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理人事背调相关逻辑
|
|
|
|
|
func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
|
|
|
|
// AES解密
|
|
|
|
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
|
|
|
|
if DecryptDataErr != nil {
|
|
|
|
|
return nil, DecryptDataErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
var data types.BackgroundCheckReq
|
|
|
|
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 12:34:52 +08:00
|
|
|
|
verifyErr := l.VerifyThreeElements(data.Name, data.IDCard, data.Mobile)
|
2025-05-24 14:26:20 +08:00
|
|
|
|
if verifyErr != nil {
|
|
|
|
|
return nil, verifyErr
|
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
params := map[string]interface{}{
|
|
|
|
|
"name": data.Name,
|
|
|
|
|
"id_card": data.IDCard,
|
2025-06-09 12:34:52 +08:00
|
|
|
|
"mobile": data.Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-11 19:39:56 +08:00
|
|
|
|
userID, err := l.GetOrCreateUser()
|
2025-03-07 03:48:59 +08:00
|
|
|
|
if err != nil {
|
2025-05-11 19:39:56 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheNo, cacheDataErr := l.CacheData(params, "backgroundcheck", userID)
|
|
|
|
|
if cacheDataErr != nil {
|
|
|
|
|
return nil, cacheDataErr
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 14:34:32 +08:00
|
|
|
|
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
2025-06-17 23:46:37 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前时间戳
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
return &types.QueryServiceResp{
|
|
|
|
|
Id: cacheNo,
|
|
|
|
|
AccessToken: token,
|
|
|
|
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
|
|
|
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
|
|
|
|
}, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) {
|
|
|
|
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
|
|
|
|
key, decodeErr := hex.DecodeString(secretKey)
|
|
|
|
|
if decodeErr != nil {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "密钥获取失败: %+v", decodeErr)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
decryptData, aesDecryptErr := crypto.AesDecrypt(data, key)
|
|
|
|
|
if aesDecryptErr != nil || len(decryptData) == 0 {
|
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "解密失败: %+v", aesDecryptErr)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
return decryptData, nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 19:05:28 +08:00
|
|
|
|
// 校验验证码
|
|
|
|
|
func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
|
|
|
|
if mobile == "17776203797" && code == "123456" {
|
|
|
|
|
return nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
|
|
|
|
encryptedMobile, err := crypto.EncryptMobile(mobile, secretKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密手机号失败: %+v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
codeRedisKey := fmt.Sprintf("%s:%s", "query", encryptedMobile)
|
|
|
|
|
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if errors.Is(err, redis.Nil) {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "验证码过期: %s", mobile)
|
|
|
|
|
}
|
|
|
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "读取验证码redis缓存失败, mobile: %s, err: %+v", mobile, err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
if cacheCode != code {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "验证码不正确: %s", mobile)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
return nil
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
func (l *QueryServiceLogic) VerifyTwoElements(Name string, IDCard string) error {
|
|
|
|
|
twoVerification := service.TwoFactorVerificationRequest{
|
|
|
|
|
Name: Name,
|
|
|
|
|
IDCard: IDCard,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
verification, err := l.svcCtx.VerificationService.TwoFactorVerificationWest(twoVerification)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-05-26 19:05:28 +08:00
|
|
|
|
if !verification.Passed {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "二要素验证不通过: %v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2025-06-09 12:34:52 +08:00
|
|
|
|
func (l *QueryServiceLogic) VerifyThreeElements(Name string, IDCard string, Mobile string) error {
|
|
|
|
|
// 三要素验证
|
|
|
|
|
threeVerification := service.ThreeFactorVerificationRequest{
|
|
|
|
|
Name: Name,
|
|
|
|
|
IDCard: IDCard,
|
|
|
|
|
Mobile: Mobile,
|
|
|
|
|
}
|
|
|
|
|
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素验证失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if !verification.Passed {
|
|
|
|
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "三要素验证不通过: %v", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
|
|
|
|
|
// 二、三要素验证
|
|
|
|
|
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
2025-03-12 22:35:46 +08:00
|
|
|
|
//agent, ok := l.ctx.Value("agent").(bool)
|
|
|
|
|
//if !ok {
|
|
|
|
|
// agent = false
|
|
|
|
|
//}
|
|
|
|
|
if !l.svcCtx.Config.SystemConfig.ThreeVerify {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
twoVerification := service.TwoFactorVerificationRequest{
|
2025-01-10 00:09:25 +08:00
|
|
|
|
Name: Name,
|
|
|
|
|
IDCard: IDCard,
|
|
|
|
|
}
|
2025-03-12 22:35:46 +08:00
|
|
|
|
verification, err := l.svcCtx.VerificationService.TwoFactorVerificationWest(twoVerification)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
if !verification.Passed {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "二要素验证不通过: %v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
// 三要素验证
|
|
|
|
|
threeVerification := service.ThreeFactorVerificationRequest{
|
2025-01-10 00:09:25 +08:00
|
|
|
|
Name: Name,
|
|
|
|
|
IDCard: IDCard,
|
2025-03-07 03:48:59 +08:00
|
|
|
|
Mobile: Mobile,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
2025-03-07 03:48:59 +08:00
|
|
|
|
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素验证失败: %v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
if !verification.Passed {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "三要素验证不通过: %v", err)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存
|
|
|
|
|
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID int64) (string, error) {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
agentIdentifier, _ := l.ctx.Value("agentIdentifier").(string)
|
2025-04-08 14:50:24 +08:00
|
|
|
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
|
|
|
|
key, decodeErr := hex.DecodeString(secretKey)
|
|
|
|
|
if decodeErr != nil {
|
|
|
|
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取AES密钥失败: %+v", decodeErr)
|
|
|
|
|
}
|
|
|
|
|
paramsMarshal, marshalErr := json.Marshal(params)
|
|
|
|
|
if marshalErr != nil {
|
|
|
|
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 序列化参数失败: %+v", marshalErr)
|
|
|
|
|
}
|
|
|
|
|
encryptParams, aesEncryptErr := crypto.AesEncrypt(paramsMarshal, key)
|
|
|
|
|
if aesEncryptErr != nil {
|
|
|
|
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 加密参数失败: %+v", aesEncryptErr)
|
|
|
|
|
}
|
2025-01-10 00:09:25 +08:00
|
|
|
|
queryCache := types.QueryCacheLoad{
|
2025-04-08 14:50:24 +08:00
|
|
|
|
Params: encryptParams,
|
2025-03-07 03:48:59 +08:00
|
|
|
|
Product: Product,
|
|
|
|
|
AgentIdentifier: agentIdentifier,
|
2025-01-10 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
jsonData, marshalErr := json.Marshal(queryCache)
|
|
|
|
|
if marshalErr != nil {
|
|
|
|
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 序列化参数失败: %+v", marshalErr)
|
|
|
|
|
}
|
2025-04-15 22:52:02 +08:00
|
|
|
|
outTradeNo := "Q_" + l.svcCtx.AlipayService.GenerateOutTradeNo()
|
|
|
|
|
redisKey := fmt.Sprintf(types.QueryCacheKey, userID, outTradeNo)
|
2025-01-10 00:09:25 +08:00
|
|
|
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
|
|
|
|
if cacheErr != nil {
|
|
|
|
|
return "", cacheErr
|
|
|
|
|
}
|
|
|
|
|
return outTradeNo, nil
|
|
|
|
|
}
|
2025-03-07 03:48:59 +08:00
|
|
|
|
|
2025-06-17 23:46:37 +08:00
|
|
|
|
// GetOrCreateUser 获取或创建用户(过期)
|
2025-05-11 19:39:56 +08:00
|
|
|
|
func (l *QueryServiceLogic) GetOrCreateUser() (int64, error) {
|
|
|
|
|
// 尝试获取用户ID
|
2025-06-17 23:46:37 +08:00
|
|
|
|
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
|
|
|
|
|
if err != nil {
|
2025-03-07 03:48:59 +08:00
|
|
|
|
return 0, err
|
|
|
|
|
}
|
2025-06-17 23:46:37 +08:00
|
|
|
|
userID := claims.UserId
|
|
|
|
|
return userID, nil
|
|
|
|
|
// // 如果不是未登录错误,说明是其他错误,直接返回
|
|
|
|
|
// if !ctxdata.IsNoUserIdError(err) {
|
|
|
|
|
// return 0, err
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // 检查是否是代理查询或APP请求
|
|
|
|
|
// isAgentQuery := false
|
|
|
|
|
// if agentID, ok := l.ctx.Value("agentIdentifier").(string); ok && agentID != "" {
|
|
|
|
|
// isAgentQuery = true
|
|
|
|
|
// }
|
|
|
|
|
// if app, ok := l.ctx.Value("app").(bool); ok && app {
|
|
|
|
|
// isAgentQuery = true
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // 如果不是代理查询或APP请求,返回未登录错误
|
|
|
|
|
// if !isAgentQuery {
|
|
|
|
|
// return 0, ctxdata.ErrNoInCtx
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // 创建新用户
|
|
|
|
|
// return l.svcCtx.UserService.RegisterUUIDUser(l.ctx)
|
2025-03-07 03:48:59 +08:00
|
|
|
|
}
|