Commit 7161837c authored by 李尚科's avatar 李尚科

fix

parent f038c111
Pipeline #14249 passed with stage
in 5 seconds
...@@ -18,6 +18,8 @@ module.exports = (options, app) => { ...@@ -18,6 +18,8 @@ module.exports = (options, app) => {
if (ctx.helper.md5(openid + uuid + 'jbwl') != auth_token) { if (ctx.helper.md5(openid + uuid + 'jbwl') != auth_token) {
ctx.failed('login auth error'); ctx.failed('login auth error');
} }
// console.info('11111111111111111111111111111111');
// console.info(auth_info);
ctx.setUserUuid(user_uuid); ctx.setUserUuid(user_uuid);
await next(); await next();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
const Service = require('egg').Service; const Service = require('egg').Service;
const R = require('ramda'); const R = require('ramda');
const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
class InstitutionService extends Service { class InstitutionService extends Service {
...@@ -156,7 +157,7 @@ class InstitutionService extends Service { ...@@ -156,7 +157,7 @@ class InstitutionService extends Service {
let classs = await ctx.classModel.CourseClass.one({ where }); let classs = await ctx.classModel.CourseClass.one({ where });
classs.dataValues.age_text = `${classs.min_age}-${classs.max_age}岁`; classs.dataValues.age_text = `${classs.min_age}-${classs.max_age}岁`;
classs.dataValues.point_tags = classs.point ? classs.point.split(';') : []; classs.dataValues.point_tags = classs.point ? classs.point.split(';') : [];
classs.dataValues.photo_album = classs.image ? classs.image.split(';') : [] ; classs.dataValues.photo_album = classs.image ? classs.image.split(';') : [];
return classs; return classs;
} }
...@@ -301,8 +302,8 @@ class InstitutionService extends Service { ...@@ -301,8 +302,8 @@ class InstitutionService extends Service {
const results = []; const results = [];
for (let i in lbs_array) { for (let i in lbs_array) {
let lbs = lbs_array[i]; let lbs = lbs_array[i];
const driving = drivings[i] ? drivings[i] : { distance: 0, duration: 0 }; const driving = (drivings[i] && drivings[i].distance !== -1) ? drivings[i] : { distance: 0, duration: 0 };
const walking = walkings[i] ? walkings[i] : { distance: 0, duration: 0 }; const walking = (walkings[i] && walkings[i].distance !== -1) ? walkings[i] : { distance: 0, duration: 0 };
const lbs_distance = driving.distance > distance ? driving : walking; const lbs_distance = driving.distance > distance ? driving : walking;
const travel_method = driving.distance > distance ? 'driving' : 'walking'; const travel_method = driving.distance > distance ? 'driving' : 'walking';
results.push({ results.push({
...@@ -327,12 +328,14 @@ class InstitutionService extends Service { ...@@ -327,12 +328,14 @@ class InstitutionService extends Service {
const { ctx } = this; const { ctx } = this;
const ret = []; let ret = [];
// const institution_lbs = await this.computeDistance(areas_list); // const institution_lbs = await this.computeDistance(areas_list);
const institution_lbs = areas_list; const institution_lbs = areas_list;
for (let i in institution_areas) { for (let i in institution_areas) {
let institution_area = institution_areas[i]; let institution_area = institution_areas[i];
//TODO 校验经纬度
const lbs = institution_lbs[i]; const lbs = institution_lbs[i];
const area_name = institution_area.area_name; const area_name = institution_area.area_name;
...@@ -353,10 +356,19 @@ class InstitutionService extends Service { ...@@ -353,10 +356,19 @@ class InstitutionService extends Service {
institution_area.duration = duration; institution_area.duration = duration;
institution_area.travel_tips = travel_tips; institution_area.travel_tips = travel_tips;
ret.push(institution_area); ret[i] = institution_area;
} }
return ret; const results = [];
ret = _.orderBy(ret, ['distance'], ['asc']);
for (let j in ret) {
const val = ret[j];
if (!results[val.id] && val.distance !== 0) {
results[val.id] = val;
}
}
return results;
} }
async formatInstitutions(institutions) { async formatInstitutions(institutions) {
......
...@@ -313,6 +313,7 @@ class ApplyService extends Service { ...@@ -313,6 +313,7 @@ class ApplyService extends Service {
* @param {*} inputParams * @param {*} inputParams
*/ */
async applyCallrisk(input) { async applyCallrisk(input) {
const { ctx } = this; const { ctx } = this;
const { name, phone, id_card, password } = input; const { name, phone, id_card, password } = input;
const user_id = ctx.userId; const user_id = ctx.userId;
...@@ -329,26 +330,26 @@ class ApplyService extends Service { ...@@ -329,26 +330,26 @@ class ApplyService extends Service {
if (!check_second_ret.order_id) { if (!check_second_ret.order_id) {
return check_second_ret; return check_second_ret;
} }
let ret = {
order_id,
report_id: null,
first: check_second_ret.first,
second: check_second_ret.second,
order_sn: null
}
// let ret = {
// order_id,
// report_id: null,
// first: check_second_ret.first,
// second: check_second_ret.second,
// order_sn: null
// }
//生成订单 //生成订单
const order_data = { type, name, phone, id_card }; const order_data = { type, name, phone, id_card };
const order = await ctx.service.credit.order.createOrder(order_data); const order = await ctx.service.credit.order.createOrder(order_data);
let order_id = order.id; const order_id = order.id;
//运营商API.创建订单号 //运营商API.创建订单号
let orderSnInfo = await ctx.service.credit.yys.getOrderSn(phone); const order_sn_info = await ctx.service.credit.yys.getOrderSn(phone);
if (orderSnInfo.code !== 0) { if (orderSnInfo.code !== 0) {
ctx.failed('getOrderSn error msg:' + orderSnInfo.msg); ctx.failed('getOrderSn error msg:' + orderSnInfo.msg);
} }
const order_sn = order_sn_info.data.orderSn;
let addYysOrder = { const addYysOrder = {
order_id, order_id,
user_id, user_id,
app_type_id, app_type_id,
...@@ -358,15 +359,30 @@ class ApplyService extends Service { ...@@ -358,15 +359,30 @@ class ApplyService extends Service {
phone, phone,
id_card, id_card,
password, password,
r_order_sn: orderSnInfo.data.orderSn, r_order_sn: order_sn,
order_sn_operator: orderSnInfo.data.operator order_sn_operator: orderSnInfo.data.operator
} }
let YysOrderInfo = await ctx.prometheusModel.CreditYysOrder.create(addYysOrder); const yys_order_info = await ctx.prometheusModel.CreditYysOrder.create(addYysOrder);
ret.order_sn = orderSnInfo.data.orderSn; // ret.order_sn = yys_order_info.data.orderSn;
return ret; //调用运营商获取验证码接口
const yys_get_code = await ctx.service.credit.yys.getCode({ password, order_sn });
if (yys_get_code.code !== 0) {
ctx.failed('getCode error msg:' + yys_get_code.msg);
}
// //提交任务
// const yys_commit = await this.commitYys(orderSnInfo.data.orderSn, { phone, name, ID: id_card, password, phoneCode });
// if (yys_commit.code !== 0) {
// ctx.failed('getCode error msg:' + yys_commit.msg);
// }
return { order_id, report_id, first: check_second_ret.first, second: check_second_ret.second, order_sn };
} }
async createApply() { async createApply() {
const { ctx } = this; const { ctx } = this;
......
...@@ -490,8 +490,23 @@ class CallriskService extends Service { ...@@ -490,8 +490,23 @@ class CallriskService extends Service {
call_count_array = ['较高', '不符合', '不利于']; call_count_array = ['较高', '不符合', '不利于'];
} }
//TODO 计算近6个月每个月通话的城市有几个。 //TODO 计算近6个月每个月通话的城市有几个。
const call_active_msg = `您的夜间通话次数占【${call_count_array[0]}】,【${call_count_array[1]}】日常社交时间,【${call_count_array[2]}】贷款机构对您的放贷评估。您的通话活跃地区【变动较大/变化不大】,您当前个人的社交/社会状态稳定度【较好/一般】,【有利于/不利于】贷款机构对您的放贷评估。`; const call_most_city = call_active.city_active.slice(0, 3);
let total_time = 0;
let top_three_city_total_time = 0;
for (let i in call_most_city) {
const call_city = call_most_city[i];
top_three_city_total_time += call_city.call_time;
}
for (let j in call_active.city_active) {
const call = call_active.city_active[j];
total_time += call.call_time;
}
const percent = (top_three_city_total_time / total_time).toFixed(2);
let call_active_text = ['变化不大', '较好', '有利于'];
if (percent <= 0.6) {
call_active_text = ['变动较大', '一般', '不利于'];
}
const call_active_msg = `您的夜间通话次数占【${call_count_array[0]}】,【${call_count_array[1]}】日常社交时间,【${call_count_array[2]}】贷款机构对您的放贷评估。您的通话活跃地区【${call_active_text[0]}】,您当前个人的社交/社会状态稳定度【${call_active_text[1]}】,【${call_active_text[2]}】贷款机构对您的放贷评估。`;
//通话行为解析 //通话行为解析
let call_behavior_array = ['较少', '稳定', '有利于',]; let call_behavior_array = ['较少', '稳定', '有利于',];
...@@ -510,6 +525,77 @@ class CallriskService extends Service { ...@@ -510,6 +525,77 @@ class CallriskService extends Service {
} }
//获取验证码
async getCode(order_id) {
const { ctx } = this;
const user_id = ctx.userId;
// const { order_id } = input;
const yys_order_info = await ctx.prometheusModel.CreditYysOrder.one({ where: { order_id, user_id } });
if (!yys_order_info || !yys_order_info.id) {
ctx.failed('error order_sn');
}
const password = yys_order_info.password;
const params = { order_sn, password };
const ret = await ctx.service.credit.yys.getCode(params);
if (ret.code !== 0) {
ctx.failed('getCode error msg:' + ret.msg);
}
return { order_id };
}
//提交任务给运营商
async commitYys(input) {
const { ctx } = this;
const user_id = ctx.userId;
const { order_id, code } = input;
const yys_order = await ctx.prometheusModel.CreditYysOrder.one({ where: { order_id, user_id } });
// const order_id = yys_order.order_id;
const order_info = await ctx.prometheusModel.CreditOrder.one({ where: { id: order_id, user_id } });
const input = {
phone: order_info.phone,
name: order_info.name,
ID: order_info.id_card,
password: yys_order.password,
phoneCode: code,
};
const operator = yys_order.operator;
const params = operator.params;
let request_params = {};
for (let i in params) {
const column = params[i].name;
request_params[column] = input[column];
}
const request_data = { orderSn, params: request_params };
const yys_commit = await ctx.service.credit.yys.commit(request_data);
if (yys_commit.code !== 0) {
ctx.failed('commit error msg:' + yys_commit.msg);
}
return { order_id };
}
//查询任务状态
async queryTaskStatus(order_id) {
const { ctx } = this;
const code_array = [];
const yys_order = await ctx.prometheusModel.CreditYysOrder({ where: { order_id } });
const order_sn = yys_order.r_order_sn;
const query_resp = await ctx.service.credit.yys.query(order_sn);
const r_code = query_resp.code;
if (r_code === 0) {
const yys_report_data = await ctx.service.credit.yys.getData(order_sn);
}
return query_resp;
}
......
...@@ -17,7 +17,7 @@ class YysService extends Service { ...@@ -17,7 +17,7 @@ class YysService extends Service {
let params = { let params = {
phone: phone phone: phone
} }
let url = this.config.NODE_BASE_URL + '/getorderSn' + '?appKey=' + this.config.YYS_APP_KEY; let url = this.config.NODE_BASE_URL + '/yys_api/getorderSn' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); let resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info({ url: JSON.stringify(resp) });
return resp.data; return resp.data;
...@@ -35,7 +35,7 @@ class YysService extends Service { ...@@ -35,7 +35,7 @@ class YysService extends Service {
password: params.password password: params.password
} }
} }
let url = this.config.NODE_BASE_URL + '/getCode' + '?appKey=' + this.config.YYS_APP_KEY; let url = this.config.NODE_BASE_URL + '/yys_api/getCode' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); let resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info({ url: JSON.stringify(resp) });
return resp.data; return resp.data;
...@@ -47,15 +47,16 @@ class YysService extends Service { ...@@ -47,15 +47,16 @@ class YysService extends Service {
* @param {*} params 需要提交的参数,根据getOrderSn的operator来确定需要的参数 * @param {*} params 需要提交的参数,根据getOrderSn的operator来确定需要的参数
*/ */
async commit(params) { async commit(params) {
const { ctx } = this; const { ctx } = this;
let params = { // let params = {
orderSn: params.order_sn, // orderSn: params.order_sn,
params: { // params: {
password: params.password // password: params.password
} // }
} // }
let url = this.config.NODE_BASE_URL + '/commit' + '?appKey=' + this.config.YYS_APP_KEY; const url = this.config.NODE_BASE_URL + '/yys_api/commit' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); const resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info({ url: JSON.stringify(resp) });
return resp.data; return resp.data;
} }
...@@ -69,12 +70,34 @@ class YysService extends Service { ...@@ -69,12 +70,34 @@ class YysService extends Service {
let params = { let params = {
orderSn: orderSn, orderSn: orderSn,
} }
let url = this.config.NODE_BASE_URL + '/query' + '?appKey=' + this.config.YYS_APP_KEY; let url = this.config.NODE_BASE_URL + '/yys_api/query' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); let resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info({ url: JSON.stringify(resp) });
return resp.data; return resp.data;
} }
/**
* 获取报告
* @param {*} orderSn 创建订单时生成的订单号
*/
async getData(orderSn) {
const { ctx } = this;
const data = {
sign: '',
params: {
appKey: this.config.YYS_APP_KEY,
timestamp: new Date().getTime(),
token: '',
orderSn,
}
};
let url = this.config.NODE_BASE_URL + '/yys_api/getData' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, data, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) });
return resp.data;
}
} }
......
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