Commit 3f75bcd5 authored by lishangke's avatar lishangke
parents 7363d887 db283d39
Pipeline #19302 passed with stage
in 56 seconds
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, STRING, DATE } = app.Sequelize;
const DuxiaomanLog = app.prometheusModel.define('duxiaoman_log', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_id: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
user_sid: INTEGER,
phone: STRING,
is_target_user: INTEGER,
request: STRING,
response: STRING,
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}
}, {
timestamps: false,
tableName: 'duxiaoman_log',
});
return DuxiaomanLog;
};
...@@ -12,7 +12,8 @@ class CheckService extends Service { ...@@ -12,7 +12,8 @@ class CheckService extends Service {
async getUserHidePhone() { async getUserHidePhone() {
const { ctx } = this; const { ctx } = this;
let ret = { let ret = {
hidePhone: '' hide_phone: '',
is_reject: false,//30天之内是否有被拒记录
}; };
if (!ctx.oldUserId || !ctx.userId) { if (!ctx.oldUserId || !ctx.userId) {
//如果没有登录就不做处理 //如果没有登录就不做处理
...@@ -30,7 +31,20 @@ class CheckService extends Service { ...@@ -30,7 +31,20 @@ class CheckService extends Service {
if (!userInfo) { if (!userInfo) {
ctx.failed('没有找到对应的手机号'); ctx.failed('没有找到对应的手机号');
} }
ret.hidePhone = userInfo.passport.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'); ret.hide_phone = userInfo.passport.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
//最近30天是否有被拒记录
let rejectFilter = {
attributes: ['user_sid'],
where: {
user_sid: userSid,
created_at: { $gt: moment().subtract(30, 'days').format('YYYY-MM-DD HH:mm:ss') },
is_target_user: { $ne: 1 }
}
}
let rejectRecord = await ctx.prometheusModel.DuxiaomanLog.findOne(rejectFilter);
ret.is_reject = !rejectRecord ? false : true;
return ret; return ret;
} }
...@@ -63,6 +77,10 @@ class CheckService extends Service { ...@@ -63,6 +77,10 @@ class CheckService extends Service {
async check() { async check() {
const { ctx } = this; const { ctx } = this;
let ret = {
is_target_user: 0,//1 true 0 false -1 NOT_FOUND
url: ''
}
if (!ctx.oldUserId || !ctx.userId) { if (!ctx.oldUserId || !ctx.userId) {
//如果没有登录就不做处理 //如果没有登录就不做处理
ctx.failed('登录异常'); ctx.failed('登录异常');
...@@ -95,10 +113,50 @@ class CheckService extends Service { ...@@ -95,10 +113,50 @@ class CheckService extends Service {
ctx.logger.info('dxmUrl:' + dxmUrl); ctx.logger.info('dxmUrl:' + dxmUrl);
let result = await ctx.helper.send_request(dxmUrl, {}, { method: 'GET' }); let result = await ctx.helper.send_request(dxmUrl, {}, { method: 'GET' });
ctx.logger.info('result:' + JSON.stringify(result)); ctx.logger.info('result:' + JSON.stringify(result));
return result; if (result.status === 200) {
if (result.data.retCode === 0) {
ret.is_target_user = result.data.result.is_target_user;
}
//数据库记录
let addData = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
user_sid: userSid,
phone: userInfo.passport,
is_target_user: result.data.result.is_target_user,
request: JSON.stringify(params),
response: JSON.stringify(result.data),
}
await ctx.prometheusModel.DuxiaomanLog.create(addData);
} else {
ctx.failed('服务异常,请稍后再试');
}
if (ret.is_target_user === 1) {
let businessId = this.config.CFG_ENV === 'dev' ? 1 : (this.config.CFG_ENV === 'uat' ? 174 : 3);
let businessInfo = await this.getBusinessInfo(businessId);
ret.url = businessInfo.url;
}
return ret;
}
/**
* 获取业务信息,type=4表示普通贷款
* @param {integer|string} id 业务编号
* @returns {object} businessInfo 业务相关信息
*/
async getBusinessInfo(id) {
const { ctx } = this;
let url = this.config.CASSANDRA_API + '/huodong/bu_basic/' + id + '?type=4';
let result = await ctx.helper.send_request(url, {}, {
method: 'GET',
});
ctx.logger.info(url + ':' + JSON.stringify(result));
let businessInfo = (result.status === 200 && result.data && result.data.ret) ? result.data.ret : {};
return businessInfo;
} }
......
...@@ -164,6 +164,10 @@ module.exports = appInfo => { ...@@ -164,6 +164,10 @@ module.exports = appInfo => {
config.DXM_SECRET = process.env.DXM_SECRET; config.DXM_SECRET = process.env.DXM_SECRET;
config.DXM_URL = process.env.DXM_URL; config.DXM_URL = process.env.DXM_URL;
config.CFG_ENV = process.env.CFG_ENV;
config.CASSANDRA_API = process.env.CASSANDRA_API;
return config; return config;
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment