Commit ede5c571 authored by 方斌's avatar 方斌
parents f2c11b29 cbeecb20
Pipeline #15700 passed with stage
in 1 minute 16 seconds
...@@ -6,7 +6,7 @@ class TestController extends Controller { ...@@ -6,7 +6,7 @@ class TestController extends Controller {
const { service, ctx } = this; const { service, ctx } = this;
const from = { lng: 120.069206, lat: 30.291121 }; const from = { lng: 120.069206, lat: 30.291121 };
const to = { lng: 120.212997, lat: 30.29133 }; const to = { lng: 120.212997, lat: 30.29133 };
const ret = await service.course.lbs.getLBSDistance('driving', from, [ to ]); const ret = await service.course.lbs.getLBSDistance('walking', from, [ to, to ]);
ctx.success(ret); ctx.success(ret);
} }
} }
......
'use strict';
const Controller = require('egg').Controller;
const crypto = require('crypto');
const fs = require('fs');
const request = require('request');
class WechatController extends Controller {
async test() {
const { ctx, service } = this;
const data = {MsgType: 'miniprogrampage'};
await service.course.wechat.sendMsg(data);
ctx.success();
}
async callbackAction() {
const { ctx, service } = this;
await service.course.wechat.callbackAction();
ctx.success('success');
}
async check() {
const { ctx } = this;
const params = ctx.request.query;
const {
signature,
timestamp,
nonce,
echostr,
} = params;
const array = [ '51gjj', timestamp, nonce ];
array.sort();
// 3.将三个参数字符串拼接成一个字符串进行sha1加密
const tempStr = array.join('');
const hashCode = crypto.createHash('sha1'); // 创建加密类型
const resultCode = hashCode.update(tempStr, 'utf8').digest('hex');
console.log(resultCode);
// 4.开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
if (resultCode === signature) {
ctx.success(echostr);
} else {
ctx.success();
}
}
}
module.exports = WechatController;
...@@ -39,7 +39,8 @@ class CallriskController extends Controller { ...@@ -39,7 +39,8 @@ class CallriskController extends Controller {
name: { type: 'string', required: true }, name: { type: 'string', required: true },
phone: { type: 'string', required: true }, phone: { type: 'string', required: true },
id_card: { type: 'string', required: true }, id_card: { type: 'string', required: true },
password: { type: 'string', required: true } password: { type: 'string', required: true },
net: { type: 'number', required: true },
} }
ctx.validate(rule, input_params); ctx.validate(rule, input_params);
const result = await ctx.service.credit.apply.applyCallrisk(input_params); const result = await ctx.service.credit.apply.applyCallrisk(input_params);
...@@ -70,7 +71,7 @@ class CallriskController extends Controller { ...@@ -70,7 +71,7 @@ class CallriskController extends Controller {
const { ctx } = this; const { ctx } = this;
const order_id = ctx.params.order_id; const order_id = ctx.params.order_id;
const result = await ctx.service.credit.callrisk.queryTaskStatus(order_id); const result = await ctx.service.credit.callrisk.queryTaskStatus(order_id);
ctx.success({ result }); ctx.success({ result });
} }
......
...@@ -13,6 +13,15 @@ class HomeController extends Controller { ...@@ -13,6 +13,15 @@ class HomeController extends Controller {
ctx.success(ret); ctx.success(ret);
} }
async test() {
const { ctx } = this;
const orderSn = await ctx.query.sn;
const yys_report_data = await ctx.service.credit.yys.getData(orderSn);//拉取报告数据
// const stream1 = await ctx.getFileStream();
// await pump(stream, writeStream);
ctx.success(yys_report_data);
}
} }
module.exports = HomeController; module.exports = HomeController;
...@@ -34,7 +34,7 @@ class OrderController extends Controller { ...@@ -34,7 +34,7 @@ class OrderController extends Controller {
const { method, order_id, reject_url } = input_params; const { method, order_id, reject_url } = input_params;
let result = await ctx.service.credit.order.unifiedOrder(method, order_id); let result = await ctx.service.credit.order.unifiedOrder(method, order_id);
// result.reject_url = reject_url; // result.reject_url = reject_url;
result.url = `${result.url}&py=#shanp.com&redirect_url=${reject_url}`; result.url = `${result.url}&redirect_url=${reject_url}`;
ctx.success({ result }); ctx.success({ result });
} }
......
'use strict';
const Controller = require('egg').Controller;
const WECHAT_CODE_URL = 'https://open.weixin.qq.com/connect/oauth2/authorize';
const WECHAT_AUTH = 'https://api.weixin.qq.com/sns/oauth2/access_token';
const WECHAT_APPID = 'wx3c772df2d8d78da3';
const WECHAT_APPID_TEST = 'wxa9df2d60730b25d9';
const WECHAT_SECRET = 'b369fd28a9f9320ebe4e35dfaa00b194';
const WECHAT_SECRET_TEST = 'dfede7a3b543149a88b07b46bcc28e00';
const REDIRECT_PAGE = '/webserve/accumulation/index';
class WechatController extends Controller {
//公众号公积金查询H5授权跳转
async oauthLogin() {
const { ctx } = this;
const code = ctx.query.code;
const channel_id = ctx.query.channel_id;
const app_id = ['https://lan-nginx.jianbing.com', 'https://pro-nginx.jianbing.com'].includes(this.config.NODE_BASE_URL) ? WECHAT_APPID : WECHAT_APPID_TEST;
const appsecret = ['https://lan-nginx.jianbing.com', 'https://pro-nginx.jianbing.com'].includes(this.config.NODE_BASE_URL) ? WECHAT_SECRET : WECHAT_SECRET_TEST;
if (!code || code.length === 0) {
const target_url = WECHAT_CODE_URL + `?appid=${app_id}&redirect_uri=${encodeURIComponent(`${this.app.config.OUT_P_NODE_URL}/51business/api/gjj/wechat/oauth_login?&channel_id=${channel_id}`)}&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`;
ctx.redirect(target_url); return;
}
const url = `${WECHAT_AUTH}?appid=${app_id}&secret=${appsecret}&code=${code}&grant_type=authorization_code`
const result = await ctx.helper.send_request(url, {}, { method: 'GET' });
ctx.logger.info(JSON.stringify({ wx_gjj_query: result }));
if (result.status !== 200) {
ctx.failed('获取openid失败1');
}
const wx_ret = result.data;
if (!wx_ret.openid) {
ctx.failed('获取openid失败2');
}
const openid = wx_ret.openid;
ctx.cookies.set('openid', openid, { httpOnly: false, signed: false, path: '/', overwrite: true });
const redirect_url = this.app.config.OUT_P_NODE_URL + REDIRECT_PAGE;
//判断是否已绑定手机号
const user_exist_url = `${this.app.config.NODE_BASE_URL}/user_api/v1/user/is_exist/${openid}`;
const bind_phone_result = await ctx.helper.send_request(user_exist_url, { type: 5 }, { method: 'GET' });
ctx.logger.info(JSON.stringify({ bind_phone_result: bind_phone_result }));
if (bind_phone_result.status !== 200) {
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin&openid=${openid}`); return;
}
const user_exist_ret = bind_phone_result.data;
if (user_exist_ret.result != 'true') {//未绑定的手机号时
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin&openid=${openid}`); return;
}
const user_id = user_exist_ret.uid;
//已绑定手机的 继续 判断是否有导入公积金
await this.user_login({ code, openid, channel_id });//已绑定的用户 直接登录
const gjj_exist_url = `${this.app.config.NODE_BASE_URL}/cassandra-server/gjj/list/${user_id}`;
const gjj_exist_result = await ctx.helper.send_request(gjj_exist_url, {}, { method: 'GET' });
ctx.logger.info(JSON.stringify({ gjj_exist_result: gjj_exist_result }));
if (gjj_exist_result.status !== 200) {//调用公积金接口出错
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin`); return;
}
const gjj_exist_ret = gjj_exist_result.data;
if (!gjj_exist_ret.ret || gjj_exist_ret.ret.length === 0) {//没有导入公积金时
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin`); return;
}
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=hasLogin`); return;//已导入公积金
}
//判断是否有公积金导入并跳转
// async checkGjj() {
// const { ctx } = this;
// const user_id = ctx.userId;
// //判断是否有导入公积金
// console.info(user_id);
// const gjj_exist_url = `${this.app.config.NODE_BASE_URL}/cassandra-server/gjj/list/${user_id}`;
// const gjj_exist_result = await ctx.helper.send_request(gjj_exist_url, {}, { method: 'GET' });
// ctx.logger.info(JSON.stringify({ gjj_exist_result: gjj_exist_result }));
// if (gjj_exist_result.status !== 200) {
// ctx.redirect(NO_GJJ_PAGE); return;
// }
// ctx.redirect(GJJ_DETAIL_PAGE); return;
// }
async checkLogin() {
const { ctx } = this;
const user_id = ctx.userId;
let is_login = false;
if (user_id) {
is_login = true;
}
// const phone = await ctx.helper.getPhoneCity('15968762898');
ctx.success({ result: is_login });
}
async user_login(params) {
const { ctx } = this;
const { code, openid, channel_id } = params;
const user_agent = ctx.request.header.user_agent ? ctx.request.header.user_agent : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36';
const ip = ctx.helper.getClientIP();
const past_deviceno = ctx.helper.md5(user_agent + ip);
const app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: channel_id } });
if (!app_channel_info || Object.keys(app_channel_info).length === 0) {
ctx.failed('渠道未配置');
}
if (!app_channel_info.app_id) {
ctx.failed('渠道未关联APPID');
}
const device_login_params = {
past_deviceno: past_deviceno,
channel_id: app_channel_info.channel_id,
app_id: app_channel_info.app_id,
device_info: {},
}
const result_device_login = await ctx.helper.send_request(this.config.NODE_URL + '/login/device', device_login_params, { method: 'POST' });//设备登录
const device_login_data = result_device_login.data;//设备登录返回结果
if (!device_login_data || Object.keys(device_login_data).length === 0) {
ctx.failed('device login error, device_login_data empty');
}
if (!device_login_data.past_deviceno) {//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5
ctx.failed('device login error, past_deviceno empty');
}
if (!device_login_data.device_id) {//Devices字段表主键ID
ctx.failed('device login error, device_id empty');
}
if (!device_login_data.device_login_logs_id) {//DeviceLoginLogs字段表主键ID
ctx.failed('device login error, device_login_logs_id empty');
}
const user_login_params = {//用户登录传递的参数
past_deviceno: past_deviceno,//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5登
// device_no: device_login_data.device_no,//使用新的sdk生成的设备指纹
login_type: '5',//登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录,
passport: code,//登录账号:手机登录值为手机
password: code,//类型对应的值
app_user_id: params.app_user_id || '',//app用户ID token登陆时传的参数 可空
code: code || '',//第三方授权登录时的code 可空
device_info: {},//设备信息
openid: openid || '' //例如微信公众号的openid(不传默认是51查个税)
};
const result_user_login = await ctx.helper.send_request(this.config.NODE_URL + '/login/user', user_login_params, { method: 'POST' });//用户登录
ctx.logger.info(JSON.stringify({ user_login_params: user_login_params, result_user_login: result_user_login }));
const user_login_data = result_user_login.data;//用户登录返回结果
if (!user_login_data || Object.keys(user_login_data).length === 0) {
ctx.failed('用户的登录失败');
}
if (!user_login_data.token || !user_login_data.uid) {
const error_msg = user_login_data.error ? user_login_data.error : '用户的登录失败';
ctx.failed(error_msg);
}
//获取用户信息
const login_token = user_login_data.token;
const app_user_id = user_login_data.app_user_id;
const user_id = user_login_data.uid;
const device_id = device_login_data.device_id;
const device_login_id = device_login_data.device_login_logs_id;
const env = this.app.config.env;
let host = this.config.NODE_BASE_URL;
if (env === 'prod') host = host.replace('lan-nginx.jianbing.com', 'p.jianbing.com');
const user_info = {
token: login_token,
app_user_id: app_user_id,
user_id: user_id,
device_id: device_id,
device_login_id: device_login_id,
android_url: `${host}/frontendh5/lp/wc/index?down=${encodeURIComponent(app_channel_info.android_url)}`,
ios_url: app_channel_info.ios_url,
}
for (let key in user_info) {
const value = user_info[key];
ctx.cookies.set(key, value, { httpOnly: false, signed: false, path: '/', overwrite: true });
}
return user_info;
}
}
module.exports = WechatController;
'use strict';
const Controller = require('egg').Controller;
class AbroadHouseController extends Controller {
/**
* 海外房列表
*/
async list() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
page: { type: 'int', required: false },
page_size: { type: 'int', required: false },
name: { type: 'string', required: false },
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.abroadHouse.abroadHouseList(inputParams);
ctx.success(ret);
}
}
module.exports = AbroadHouseController;
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
class FootPrintController extends Controller { class FootPrintController extends Controller {
/** /**
* 获取足迹列表 * 获取足迹列表
*/ */
...@@ -13,6 +13,22 @@ class FootPrintController extends Controller { ...@@ -13,6 +13,22 @@ class FootPrintController extends Controller {
ctx.success(ret); ctx.success(ret);
} }
/**
* 海外房的足迹记录需要额外记录
*/
async addAbroadFootPrint() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: { type: 'int', required: true },
};
ctx.validate(rule, inputParams);
inputParams.type = 4;
let ret = await ctx.service.house.v2.footPrint.addFootPrint(inputParams);
ctx.success(ret);
}
} }
module.exports = FootPrintController; module.exports = FootPrintController;
'use strict'; 'use strict';
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
const ConfigType = {
1: 'new_house',
2: 'rental_house',
4: 'abroad_house',
}
class searchHistoryController extends Controller { class searchHistoryController extends Controller {
...@@ -19,9 +24,9 @@ class searchHistoryController extends Controller { ...@@ -19,9 +24,9 @@ class searchHistoryController extends Controller {
}; };
ctx.validate(rule, inputParams); ctx.validate(rule, inputParams);
let ret = {}; let ret = {};
let type = [1, 2]; let type = [1, 2, 4];
for (let i in type) { for (let i in type) {
let tag = type[i] === 1 ? 'new_house' : 'rental_house'; let tag = ConfigType[type[i]];
ret[tag] = await ctx.service.house.v2.searchHistory.getSearchHistoryList({ type: type[i], city_code: Number(inputParams.city_code) }); ret[tag] = await ctx.service.house.v2.searchHistory.getSearchHistoryList({ type: type[i], city_code: Number(inputParams.city_code) });
} }
...@@ -39,6 +44,7 @@ class searchHistoryController extends Controller { ...@@ -39,6 +44,7 @@ class searchHistoryController extends Controller {
new_house: 1, new_house: 1,
rental_house: 2, rental_house: 2,
hot_question: 3, hot_question: 3,
abroad_house: 4,
} }
const rule = { const rule = {
type: { type: {
......
...@@ -38,13 +38,13 @@ class ResponseController extends Controller { ...@@ -38,13 +38,13 @@ class ResponseController extends Controller {
const user_sid = ctx.cookies.get('jianbing_customer_id', { signed: false }); const user_sid = ctx.cookies.get('jianbing_customer_id', { signed: false });
const auth_token = ctx.cookies.get('auth_token', { signed: false }); const auth_token = ctx.cookies.get('auth_token', { signed: false });
ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { auth_token, user_sid } })); // ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { auth_token, user_sid } }));
const phone_info = await ctx.service.user.get_phone_by_user_sid({ user_sid: user_sid, token: auth_token });//获取用户手机号码 const phone_info = await ctx.service.user.get_phone_by_user_sid({ user_sid: user_sid, token: auth_token });//获取用户手机号码
ctx.logger.info('phone_info: ' + JSON.stringify(phone_info)); // ctx.logger.info('phone_info: ' + JSON.stringify(phone_info));
const phone = phone_info.phone; const phone = phone_info.phone;
// const phone = '15968762898'; // const phone = '15968762898';
const app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: channel_alias } });// const app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: channel_alias } });//
ctx.logger.info('app_channel_info: ' + JSON.stringify(app_channel_info)); // ctx.logger.info('app_channel_info: ' + JSON.stringify(app_channel_info));
const channel_id = (app_channel_info && app_channel_info.channel_id) ? app_channel_info.channel_id : false; const channel_id = (app_channel_info && app_channel_info.channel_id) ? app_channel_info.channel_id : false;
const app_id = (app_channel_info && app_channel_info.app_id) ? app_channel_info.app_id : false; const app_id = (app_channel_info && app_channel_info.app_id) ? app_channel_info.app_id : false;
...@@ -59,15 +59,16 @@ class ResponseController extends Controller { ...@@ -59,15 +59,16 @@ class ResponseController extends Controller {
// console.info(this.config.NODE_URL + '/login/go_register'); // console.info(this.config.NODE_URL + '/login/go_register');
const result_go_register = await ctx.helper.send_request(this.config.NODE_URL + '/login/go_register', go_register_params, { method: 'POST' });//通过手机号直接注册新用户中心 const result_go_register = await ctx.helper.send_request(this.config.NODE_URL + '/login/go_register', go_register_params, { method: 'POST' });//通过手机号直接注册新用户中心
node_user_center_login_ret = result_go_register.data; node_user_center_login_ret = result_go_register.data;
ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { go_register_params, node_user_center_login_ret } })); // ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { go_register_params, node_user_center_login_ret } }));
// ctx.logger.info('go_register_result: ' + JSON.stringify(node_user_center_login_ret)); // ctx.logger.info('go_register_result: ' + JSON.stringify(node_user_center_login_ret));
ctx.logger.info(JSON.stringify({ url: ctx.app.config.NODE_URL + '/login/go_register', go_register_params: go_register_params, go_register_result: node_user_center_login_ret }));
node_user_center_login_ret.user_id = node_user_center_login_ret.uid; node_user_center_login_ret.user_id = node_user_center_login_ret.uid;
node_user_center_login_ret.device_login_id = node_user_center_login_ret.device_login_logs_id; node_user_center_login_ret.device_login_id = node_user_center_login_ret.device_login_logs_id;
delete (node_user_center_login_ret.uid); delete (node_user_center_login_ret.uid);
delete (node_user_center_login_ret.device_login_logs_id); delete (node_user_center_login_ret.device_login_logs_id);
} }
ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { channel_id, app_id } })); // ctx.logger.info('target_user--' + new Date().getTime() + JSON.stringify({ target_old_user: { channel_id, app_id } }));
if (!phone || !channel_id || !app_id || !node_user_center_login_ret.token) {// 或渠道错误 或直接注册新用户中心失败时 使用设备登录 if (!phone || !channel_id || !app_id || !node_user_center_login_ret.token) {// 或渠道错误 或直接注册新用户中心失败时 使用设备登录
const user_agent = header.user_agent ? header.user_agent : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'; const user_agent = header.user_agent ? header.user_agent : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36';
const ip = ctx.helper.getClientIP(); const ip = ctx.helper.getClientIP();
......
...@@ -13,6 +13,7 @@ const OLDUSERID = Symbol('Context#oldUserId'); ...@@ -13,6 +13,7 @@ const OLDUSERID = Symbol('Context#oldUserId');
const USERID = Symbol('Context#userId'); const USERID = Symbol('Context#userId');
const OLDCOOKIE = Symbol('Context#oldCookie'); const OLDCOOKIE = Symbol('Context#oldCookie');
const USERUUID = Symbol('Context#userUuid'); const USERUUID = Symbol('Context#userUuid');
const OPENID = Symbol('Context#openId');
module.exports = { module.exports = {
failed(message) { failed(message) {
...@@ -177,6 +178,10 @@ module.exports = { ...@@ -177,6 +178,10 @@ module.exports = {
return this[USERUUID]; return this[USERUUID];
}, },
get openId() {
return this[OPENID];
},
setAppUserId(app_user_id) { setAppUserId(app_user_id) {
this[APPUSERID] = app_user_id; this[APPUSERID] = app_user_id;
}, },
...@@ -212,4 +217,8 @@ module.exports = { ...@@ -212,4 +217,8 @@ module.exports = {
setUserUuid(user_uuid) { setUserUuid(user_uuid) {
this[USERUUID] = user_uuid; this[USERUUID] = user_uuid;
}, },
setOpenId(openId) {
this[OPENID] = openId;
},
}; };
...@@ -313,10 +313,10 @@ module.exports = { ...@@ -313,10 +313,10 @@ module.exports = {
return 1; return 1;
}, },
//固定位数前补充 0 操作 //固定位数前补充 0 操作
PrefixInteger(num, length) { PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length); return (Array(length).join('0') + num).slice(-length);
}, },
async xmlTojson(data) { async xmlTojson(data) {
const ret_p = new Promise((resolve, reject) => { const ret_p = new Promise((resolve, reject) => {
XML2JS.parseString(data, (err, result) => { XML2JS.parseString(data, (err, result) => {
...@@ -337,6 +337,33 @@ module.exports = { ...@@ -337,6 +337,33 @@ module.exports = {
const bulider = new XML2JS.Builder(); const bulider = new XML2JS.Builder();
const xml_params = bulider.buildObject(data); const xml_params = bulider.buildObject(data);
return xml_params; return xml_params;
},
//获取手机号码归属地
async getPhoneCity(phone) {
const { ctx } = this;
const url = 'https://mobsec-dianhua.baidu.com/dianhua_api/open/location';
let location = '--';
const result = await ctx.helper.send_request(url, { tel: phone }, { method: 'GET', timeout: 6000 });
if (result.status !== 200) {
return location;
}
const ret = result.data;
let city = '';
if (ret.response && ret.response[phone] && ret.response[phone].detail && ret.response[phone].detail.area) {
city = ret.response[phone].detail.area[0].city;
}
let provinece = '';
if (ret.response && ret.response[phone] && ret.response[phone].detail && ret.response[phone].detail.province) {
provinece = ret.response[phone].detail.province;
}
if (city == provinece) {
city = '';
}
location = provinece + city;
return location;
} }
}; };
...@@ -2,26 +2,27 @@ ...@@ -2,26 +2,27 @@
module.exports = (options, app) => { module.exports = (options, app) => {
return async function (ctx, next) { return async function(ctx, next) {
const uuid = ctx.headers.uuid; const uuid = ctx.headers.uuid;
const key = 'course_user_session_' + uuid; const key = 'course_user_session_' + uuid;
const auth_info = await ctx.app.memcache.get(key); const auth_info = await ctx.app.memcache.get(key);
if (!auth_info) { if (!auth_info) {
// await next(); // await next();
// return; // return;
ctx.failed('login auth error'); ctx.failed('login auth error');
} }
const openid = auth_info.openid; const openid = auth_info.openid;
const user_uuid = auth_info.user_uuid; const user_uuid = auth_info.user_uuid;
const auth_token = ctx.headers.auth_token; const auth_token = ctx.headers.auth_token;
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('11111111111111111111111111111111');
// console.info(auth_info); // console.info(auth_info);
ctx.setUserUuid(user_uuid); ctx.setUserUuid(user_uuid);
ctx.setOpenId(openid);
await next(); await next();
}; };
}; };
...@@ -37,7 +37,7 @@ module.exports = app => { ...@@ -37,7 +37,7 @@ module.exports = app => {
allowNull: false, allowNull: false,
}, },
silence_time_rate_3day: { silence_time_rate_3day: {
type: INTEGER, type: STRING,
allowNull: false, allowNull: false,
}, },
maximum_active_call_count: { maximum_active_call_count: {
...@@ -45,7 +45,7 @@ module.exports = app => { ...@@ -45,7 +45,7 @@ module.exports = app => {
allowNull: false, allowNull: false,
}, },
maximum_active_call_number: { maximum_active_call_number: {
type: INTEGER, type: STRING,
allowNull: false, allowNull: false,
}, },
maximum_active_call_city: { maximum_active_call_city: {
...@@ -57,7 +57,7 @@ module.exports = app => { ...@@ -57,7 +57,7 @@ module.exports = app => {
allowNull: false, allowNull: false,
}, },
maximum_passive_call_number: { maximum_passive_call_number: {
type: INTEGER, type: STRING,
allowNull: false, allowNull: false,
}, },
maximum_passive_call_city: { maximum_passive_call_city: {
...@@ -69,7 +69,7 @@ module.exports = app => { ...@@ -69,7 +69,7 @@ module.exports = app => {
allowNull: false, allowNull: false,
}, },
maximum_call_time_number: { maximum_call_time_number: {
type: INTEGER, type: STRING,
allowNull: false, allowNull: false,
}, },
maximum_call_time_city: { maximum_call_time_city: {
......
...@@ -64,14 +64,14 @@ module.exports = app => { ...@@ -64,14 +64,14 @@ module.exports = app => {
// return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined; // return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
// }, // },
// }, // },
// created_at: { created_at: {
// type: DATE, type: DATE,
// allowNull: false, allowNull: true,
// get() { get() {
// const date = this.getDataValue('created_at'); const date = this.getDataValue('created_at');
// return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined; return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
// }, },
// } }
}, { }, {
timestamps: false, timestamps: false,
tableName: 'credit_callrisk_report', tableName: 'credit_callrisk_report',
......
...@@ -21,12 +21,20 @@ module.exports = app => { ...@@ -21,12 +21,20 @@ module.exports = app => {
allowNull: false, allowNull: false,
}, },
silence_begin_time: { silence_begin_time: {
type: INTEGER, type: DATE,
allowNull: false, allowNull: true,
get() {
const date = this.getDataValue('silence_begin_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}, },
silence_end_time: { silence_end_time: {
type: INTEGER, type: DATE,
allowNull: false, allowNull: true,
get() {
const date = this.getDataValue('silence_end_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}, },
// is_deleted: { // is_deleted: {
// type: INTEGER, // type: INTEGER,
...@@ -49,9 +57,9 @@ module.exports = app => { ...@@ -49,9 +57,9 @@ module.exports = app => {
// }, // },
// } // }
}, { }, {
timestamps: false, timestamps: false,
tableName: 'credit_callrisk_silence_cycle', tableName: 'credit_callrisk_silence_cycle',
}); });
CreditCallriskSilenceCycle.one = async (data) => { CreditCallriskSilenceCycle.one = async (data) => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT, DECIMAL } = app.Sequelize;
const AbroadHouse = app.realestateModel.define('abroad_house', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: STRING,
allowNull: true
},
images: {
type: TEXT,
allowNull: true
},
tags: {
type: STRING,
allowNull: true
},
total_price: {
type: DECIMAL,
allowNull: true
},
url: {
type: STRING,
allowNull: true
},
order: {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
status: {
type: STRING,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'abroad_house',
});
AbroadHouse.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await AbroadHouse.findOne({
attributes: attributes,
where: where,
});
}
AbroadHouse.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await AbroadHouse.findAll({
attributes: attributes,
where: where,
order,
});
}
AbroadHouse.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await AbroadHouse.findAndCountAll(condition);
return { page, count, rows };
}
AbroadHouse.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await AbroadHouse.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
AbroadHouse.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return await AbroadHouse.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return AbroadHouse;
};
'use strict'; 'use strict';
module.exports = app => { module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course'); const router = app.router.namespace(app.config.projectRootPath + '/course');
const loginAuth = app.middleware.loginAuth({ type: 'new' });//登录中间件 const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件
const miniAuth = app.middleware.miniAuth();//因为不跟现有的用户中心系统,所以使用单独的登录中间件 const miniAuth = app.middleware.miniAuth();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
router.get('third', '/options', 'course.option.getOptions');//筛选项 router.get('third', '/options', 'course.option.getOptions');// 筛选项
router.post('third', '/address', miniAuth, 'course.location.getAddress');//根据经纬度或ip获取地理位置信息 router.post('third', '/address', miniAuth, 'course.location.getAddress');// 根据经纬度或ip获取地理位置信息
router.post('third', '/institutions', miniAuth, 'course.institution.institutionList');//机构列表 router.post('third', '/institutions', miniAuth, 'course.institution.institutionList');// 机构列表
router.get('third', '/institutions', miniAuth, 'course.institution.institutionList');//机构列表 router.get('third', '/institutions', miniAuth, 'course.institution.institutionList');// 机构列表
router.get('third', '/institution/:institution_id/:area_id', miniAuth, 'course.institution.institutionInfo');//机构详情 router.get('third', '/institution/:institution_id/:area_id', miniAuth, 'course.institution.institutionInfo');// 机构详情
router.post('third', '/classes', miniAuth, 'course.institution.classList');//课程列表 router.post('third', '/classes', miniAuth, 'course.institution.classList');// 课程列表
router.get('third', '/classes', miniAuth, 'course.institution.classList');//课程列表 router.get('third', '/classes', miniAuth, 'course.institution.classList');// 课程列表
router.get('third', '/class/:class_id', miniAuth, 'course.institution.classInfo');//课程详情 router.get('third', '/class/:class_id', miniAuth, 'course.institution.classInfo');// 课程详情
router.post('third', '/teachers', miniAuth, 'course.institution.teacherList');//老师列表 router.post('third', '/teachers', miniAuth, 'course.institution.teacherList');// 老师列表
router.get('third', '/teachers', miniAuth, 'course.institution.teacherList');//老师详情 router.get('third', '/teachers', miniAuth, 'course.institution.teacherList');// 老师详情
router.get('third', '/teacher/:teacher_id', miniAuth, 'course.institution.teacherInfo');//老师详情 router.get('third', '/teacher/:teacher_id', miniAuth, 'course.institution.teacherInfo');// 老师详情
router.post('third', '/user/auth', 'course.user.auth');//微信授权登录 router.post('third', '/user/auth', 'course.user.auth');// 微信授权登录
router.post('third', '/user/register_user', miniAuth, 'course.user.registerUserInfo');//授权后注册用户 router.post('third', '/user/register_user', miniAuth, 'course.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/baby', miniAuth, 'course.user.getBabyInfo');//获取baby信息 router.get('third', '/user/baby', miniAuth, 'course.user.getBabyInfo');// 获取baby信息
router.post('third', '/user/baby', miniAuth, 'course.user.saveBabyInfo');//保存baby信息 router.post('third', '/user/baby', miniAuth, 'course.user.saveBabyInfo');// 保存baby信息
router.delete('third', '/user/baby', miniAuth, 'course.user.delBabyInfo');//删除baby信息 router.delete('third', '/user/baby', miniAuth, 'course.user.delBabyInfo');// 删除baby信息
router.get('third', '/user/collection/institution', miniAuth, 'course.user.getCollectInstitutions');//收藏的机构列表 router.get('third', '/user/collection/institution', miniAuth, 'course.user.getCollectInstitutions');// 收藏的机构列表
router.post('third', '/user/collection/institution', miniAuth, 'course.user.collectInstitution');//收藏机构 router.post('third', '/user/collection/institution', miniAuth, 'course.user.collectInstitution');// 收藏机构
router.delete('third', '/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');//取消收藏机构 router.delete('third', '/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');// 取消收藏机构
router.get('third', '/wechat/callbackAction', 'course.wechat.check');
router.post('third', '/wechat/callbackAction', 'course.wechat.callbackAction');
router.post('third', '/wechat/test', 'course.wechat.test');
}; };
...@@ -13,6 +13,7 @@ module.exports = app => { ...@@ -13,6 +13,7 @@ module.exports = app => {
router.get('/home', 'credit.home.home');//首页 router.get('/home', 'credit.home.home');//首页
router.get('/test', 'credit.home.test');//首页
//我的信用-黑名单报告 //我的信用-黑名单报告
......
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
module.exports = app => { module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/gjj'); const router = app.router.namespace(app.config.projectRootPath + '/gjj');
router.get('/mine/loans', 'gjj.mine.getMyLoans');// 我的贷款 router.get('/mine/loans', 'gjj.mine.getMyLoans');// 我的贷款
router.get('/mine/creditcards', 'gjj.mine.getMyCreditCards');// 我的信用卡 router.get('/mine/creditcards', 'gjj.mine.getMyCreditCards');// 我的信用卡
router.get('/wechat/check_login', 'gjj.wechat.checkLogin');// 公积金公众号检查用户是否登录
router.get('third', '/wechat/oauth_login', 'gjj.wechat.oauthLogin');// 公积金公众号授权登录
// router.get('/wechat/check_gjj', 'gjj.wechat.checkGjj');// 公积金公众号授权登录
}; };
...@@ -129,6 +129,12 @@ module.exports = app => { ...@@ -129,6 +129,12 @@ module.exports = app => {
router.post('/v2/answer/like/:id', loginAuth, 'house.v2.like.like');//点赞 router.post('/v2/answer/like/:id', loginAuth, 'house.v2.like.like');//点赞
router.put('/v2/answer/like/:id', loginAuth, 'house.v2.like.unLike');//取消点赞 router.put('/v2/answer/like/:id', loginAuth, 'house.v2.like.unLike');//取消点赞
//海外房列表
router.post('/v2/abroad_house/list', 'house.v2.abroadHouse.list');
//海外房足迹记录
router.post('/v2/foot_print/abroad_house', 'house.v2.footPrint.addAbroadFootPrint');
}; };
\ No newline at end of file
...@@ -8,7 +8,7 @@ class HuaYunPaas extends Subscription { ...@@ -8,7 +8,7 @@ class HuaYunPaas extends Subscription {
// 通过 schedule 属性来设置定时任务的执行间隔等配置 // 通过 schedule 属性来设置定时任务的执行间隔等配置
static get schedule() { static get schedule() {
return { return {
cron: '0 50 4 * * *',//每天4:50点执行 cron: '0 0 0 * * *',//每天00:00点执行
// cron: '*/1 * * * *',//每1分钟执行一次脚本 // cron: '*/1 * * * *',//每1分钟执行一次脚本
type: 'worker', type: 'worker',
env: ['prod'], env: ['prod'],
......
...@@ -33,7 +33,7 @@ class SmsService extends Service { ...@@ -33,7 +33,7 @@ class SmsService extends Service {
if (!(/【51公积金】/.test(params.params.content))) { if (!(/【51公积金】/.test(params.params.content))) {
params.params.content = '【51公积金】' + params.params.content; params.params.content = '【51公积金】' + params.params.content;
} }
ctx.logger.info(params); ctx.logger.info(JSON.stringify(params));
let result = await ctx.helper.send_request(url, params, { method: 'POST' }); let result = await ctx.helper.send_request(url, params, { method: 'POST' });
return result; return result;
} }
......
...@@ -8,456 +8,587 @@ const moment = require('moment'); ...@@ -8,456 +8,587 @@ const moment = require('moment');
class InstitutionService extends Service { class InstitutionService extends Service {
//机构列表页 // 机构列表页
async getInstitutions(input) { async getInstitutions(input) {
const { ctx } = this; const { ctx } = this;
const user_uuid = ctx.userUuid; const user_uuid = ctx.userUuid;
const { cats, ages, lat, lng, address } = input; const { cats, ages, lat, lng, address, page } = input;
const where_institutions = input.institutions; const distance = !ctx.isEmpty(input.distance) ? Number(input.distance) : 0;
//保存定位记录 const where_institutions = input.institutions;
if (address && lat && lng) { // 保存定位记录
ctx.classModel.CourseLogUserGps.add({ user_uuid, address, lat, lng }); if (address && lat && lng) {
} ctx.classModel.CourseLogUserGps.add({ user_uuid, address, lat, lng });
}
//处理条件过滤条件
let where = { status: 1, is_deleted: 0 };
if (Number(cats)) {
const cat_ret = await ctx.classModel.CourseCat.one({ where: { id: cats } });
const cat_id = cat_ret.id;
const cat_level = cat_ret.level;
const next_level = cat_level + 1;
const next_next_level = cat_level + 2;
const next_cat = await ctx.classModel.CourseCat.all({ where: { level: next_level, parent_id: cat_id } });
const next_next_cat = await ctx.classModel.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } });
let cat_ids = [cat_id,];
cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat));
const institutions = await ctx.classModel.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } });
where.id = { $in: R.pluck('institution_id', institutions) };
}
if (Number(ages)) {
where.max_age = { $gte: ages };
where.min_age = { $lte: ages };
}
if (where_institutions) {
where.corner = { $ne: '' };
}
//关联校区表查找信息
const include = [{ model: ctx.classModel.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: ['id', 'institution_id', 'name', 'address', 'lat', 'lng'] }];
const attributes = ['id', 'name', 'type', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic',];
const institutions = await ctx.classModel.CourseInstitution.findAll({ attributes, include, where });
const institution_area_list = await this.getInstitutionAreaList(institutions);//将校区表处理成数组 // 处理条件过滤条件
// const from = { lat, lng }; const where = { status: 1, is_deleted: 0 };
const area_lbs = await this.computeDistance(institution_area_list, { lat, lng });//计算距离信息 if (Number(cats)) {
const institution_areas = await this.findShortestDistanceAreas(institution_area_list, area_lbs);//查找最短距离并输出 const cat_ret = await ctx.classModel.CourseCat.one({ where: { id: cats } });
const ret = await this.formatInstitutions(institution_areas); const cat_id = cat_ret.id;
const cat_level = cat_ret.level;
const next_level = cat_level + 1;
const next_next_level = cat_level + 2;
const next_cat = await ctx.classModel.CourseCat.all({ where: { level: next_level, parent_id: cat_id } });
const next_next_cat = await ctx.classModel.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } });
let cat_ids = [ cat_id ];
cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat));
const institutions = await ctx.classModel.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } });
const institutions_ids = Array.from(new Set(R.pluck('institution_id', institutions)));
institutions_ids.length !== 0 ? where.id = { $in: institutions_ids } : [];
}
if (Number(ages)) {
where.max_age = { $gte: ages };
where.min_age = { $lte: ages };
}
if (where_institutions) {
where.corner = { $ne: '' };
}
return ret; // 关联校区表查找信息
const include = [{ model: ctx.classModel.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: [ 'id', 'institution_id', 'name', 'address', 'lat', 'lng' ] }];
const attributes = [ 'id', 'name', 'type', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic' ];
const institutions = await ctx.classModel.CourseInstitution.findAll({ attributes, include, where });
const institution_area_list = await this.getInstitutionAreaList(institutions);// 将校区表处理成数组
// const from = { lat, lng };
// const area_lbs = await this.computeDistance(institution_area_list, { lat, lng });// 计算距离信息
const area_distance_list = await this.calcDistance(institution_area_list, { lat, lng }, page, distance);
const area_distance = area_distance_list.rows;
console.log(area_distance_list);
const institution_areas = await this.computeDistance(area_distance, { lat, lng });
for (const i in institution_areas) {
area_distance[i].distance = Number(institution_areas[i].distance) === 0 ? 999999999.0 : parseFloat(institution_areas[i].distance);
area_distance[i].duration = institution_areas[i].duration;
area_distance[i].travel_method = institution_areas[i].travel_method;
area_distance[i].travel_tips = `距我${area_distance[i].distance}km,开车${area_distance[i].duration}分钟`;
if (area_distance[i].travel_method === 'walking') {
area_distance[i].travel_tips = `距我${area_distance[i].distance}km,步行${area_distance[i].duration}分钟`;
}
if (Number(institution_areas[i].distance) === 0 && institution_areas[i].duration === 0) {
area_distance[i].travel_tips = '暂无法计算出距离';
}
} }
// const institution_areas = await this.findShortestDistanceAreas(institution_area_list, area_lbs);// 查找最短距离并输出
// const ret = await this.formatInstitutions(institution_areas);
const ret = await this.formatInstitutions(area_distance, distance);
return { count: area_distance_list.count, rows: ret };
}
/** /**
* 机构详情页 * 机构详情页
*/ */
async getInstitution(input) { async getInstitution(input) {
const { ctx } = this; const { ctx } = this;
const user_uuid = ctx.userUuid; const user_uuid = ctx.userUuid;
const { institution_id, area_id } = input; const { institution_id, area_id } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat; const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng; const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
const institution = await ctx.classModel.CourseInstitution.one({ where: { id: institution_id } }); const institution = await ctx.classModel.CourseInstitution.one({ where: { id: institution_id } });
const teachers = await this.getTeachers({ institution_id, limit: 6 }); const teachers = await this.getTeachers({ institution_id, limit: 6 });
const classes = await this.getClasses({ institution_id, limit: 4 }); const classes = await this.getClasses({ institution_id, limit: 4 });
const institution_images = await ctx.classModel.CourseImages.all({ where: { type: 1, type_id: institution_id } });//图片 const institution_images = await ctx.classModel.CourseImages.all({ where: { type: 1, type_id: institution_id } });// 图片
//处理详情页信息 // 处理详情页信息
const current_area = await ctx.classModel.CourseArea.one({ id: area_id }); const current_area = await ctx.classModel.CourseArea.one({ where: { id: area_id } });
let institution_detail = await this.formatInstitutions([institution]); let institution_detail = await this.formatInstitutions([ institution ]);
institution_detail = institution_detail[0]; institution_detail = institution_detail[0];
institution_detail.address = current_area.address; institution_detail.address = current_area.address;
institution_detail.phone = current_area.phone; institution_detail.phone = current_area.phone;
institution_detail.description = institution.description; institution_detail.description = institution.description;
institution_detail.point = institution.point; institution_detail.point = institution.point;
institution_detail.honor = institution.honor; institution_detail.honor = institution.honor;
institution_detail.is_collect = 0; institution_detail.is_collect = 0;
//计算校区距离 // 计算校区距离
const areas_ret = await this.getInstitutionAreas({ institution_id, limit: 1000 });//校区 const areas_ret = await this.getInstitutionAreas({ institution_id, limit: 1000 });// 校区
const area_rows = areas_ret.rows; const area_rows = areas_ret.rows;
const area_lbs = (lat > 0 || lng > 0) ? await this.computeDistance(area_rows, { lat, lng }) : [];//计算距离信息 const area_lbs = (lat > 0 || lng > 0) ? await this.computeDistance(area_rows, { lat, lng }) : [];// 计算距离信息
const areas = []; let areas = [];
for (let i in area_rows) { for (const i in area_rows) {
const area = area_rows[i]; const area = area_rows[i];
const lbs = i < area_lbs.length ? area_lbs[i] : { distance: 0, duration: 0, travel_method: '' }; const lbs = i < area_lbs.length ? area_lbs[i] : { distance: 0, duration: 0, travel_method: '' };
const area_name = area.name; const area_name = area.name;
const distance = lbs.distance; const distance = lbs.distance;
const duration = lbs.duration; const duration = lbs.duration;
let travel_tips = `距我${distance}km,开车${duration}分钟`; let travel_tips = `距我${distance}km,开车${duration}分钟`;
if (lbs.travel_method === 'walking') { if (lbs.travel_method === 'walking') {
travel_tips = `距我${distance}km,步行${duration}分钟`; travel_tips = `距我${distance}km,步行${duration}分钟`;
} }
if (distance === 0 && duration === 0) { if (Number(distance) === 0 && duration === 0) {
travel_tips = '暂无法计算出距离'; travel_tips = '暂无法计算出距离';
} }
if (area.id == area_id && area.institution_id == institution_id) { if (area.id == area_id && area.institution_id == institution_id) {
institution_detail.travel_tips = travel_tips; institution_detail.travel_tips = travel_tips;
institution_detail.lat = area.lat; institution_detail.lat = area.lat;
institution_detail.lng = area.lng; institution_detail.lng = area.lng;
} }
areas.push({ areas.push({
id: area.id, id: area.id,
institution_id: area.institution_id, institution_id: area.institution_id,
name: area_name, name: area_name,
address: area.address, address: area.address,
phone: area.phone, phone: area.phone,
travel_tips, travel_tips,
lat: area.lat, lat: area.lat,
lng: area.lng, lng: area.lng,
}); distance: Number(distance) === 0 ? 999999999.0 : parseFloat(distance),
} });
//是否收藏过
const collection_ret = await ctx.classModel.CourseUserCollection.one({ where: { user_uuid, institution_id, is_deleted: 0 } });
if (collection_ret && collection_ret.id) {
institution_detail.is_collect = 1;
}
//处理图片
const photo_album = [];
for (let i in institution_images) {
const institution_image = institution_images[i];
photo_album.push({
image: institution_image.image_url,
is_video: institution_image.is_video,
video_url: institution_image.video_url,
});
}
institution_detail.photo_album = photo_album;
return { institution_detail, teachers: teachers.rows, classes: classes.rows, areas: areas };
} }
areas = _.orderBy(areas, [ 'distance' ], [ 'asc' ]);
async getTeacher(teacher_id) { // 是否收藏过
const collection_ret = await ctx.classModel.CourseUserCollection.one({ where: { user_uuid, institution_id, is_deleted: 0 } });
const { ctx } = this; if (collection_ret && collection_ret.id) {
const where = { id: teacher_id }; institution_detail.is_collect = 1;
let teacher = await ctx.classModel.CourseTeacher.one({ where });
teacher.dataValues.point_tags = teacher.point ? teacher.point.split(';') : [];
teacher.dataValues.work_experience_tags = teacher.work_experience ? teacher.work_experience.split(';') : [];
const institution = await ctx.classModel.CourseInstitution.find({ where: { id: teacher.institution_id } });
teacher.dataValues.institution_name = institution.name;
return teacher;
} }
async getClass(class_id) {
const { ctx } = this; // 处理图片
const where = { id: class_id }; const photo_album = [];
let classs = await ctx.classModel.CourseClass.one({ where }); const photo_check = []; // 去重
classs.dataValues.age_text = `${classs.min_age}-${classs.max_age}岁`; for (const i in institution_images) {
classs.dataValues.point_tags = classs.point ? classs.point.split(';') : []; const institution_image = institution_images[i];
classs.dataValues.photo_album = classs.image ? classs.image.split(';') : []; if (institution_image.is_video > 0) {
if (photo_check.includes(institution_image.video_url)) {
return classs; continue;
} else {
photo_check.push(institution_image.video_url);
}
} else {
if (photo_check.includes(institution_image.image_url)) {
continue;
} else {
photo_check.push(institution_image.image_url);
}
}
photo_album.push({
image: institution_image.image_url,
is_video: institution_image.is_video,
video_url: institution_image.video_url,
});
} }
institution_detail.photo_album = photo_album;
async getTeachers(input) {
return { institution_detail, teachers: teachers.rows, classes: classes.rows, areas };
const { ctx } = this; }
const attributes = ['id', 'institution_id', 'name', 'avatar', 'teacher_experience', 'lesson', 'educational_background', 'certificate'];
const { institution_id, page, limit } = input; async getTeacher(teacher_id) {
const where = { institution_id };
const teachers = await ctx.classModel.CourseTeacher.list({ attributes, page, limit, where }); const { ctx } = this;
const where = { id: teacher_id };
const ret = []; const teacher = await ctx.classModel.CourseTeacher.one({ where });
for (let i in teachers) { teacher.dataValues.point_tags = teacher.point ? teacher.point.split(',') : [];
const teacher = teachers[i]; teacher.dataValues.work_experience_tags = teacher.work_experience ? teacher.work_experience.split(';') : [];
ret.push({
id: teacher.id, const institution = await ctx.classModel.CourseInstitution.find({ where: { id: teacher.institution_id } });
institution_id: teacher.institution_id, teacher.dataValues.institution_name = institution.name;
name: teacher.name ? teacher.name : '',
avatar: teacher.avatar ? teacher.avatar : '', return teacher;
teacher_experience: teacher.teacher_experience ? teacher.teacher_experience : '', }
lesson: teacher.lesson ? teacher.lesson : '',
educational_background: teacher.educational_background ? teacher.educational_background : '', async getClass(class_id) {
certificate: teacher.certificate ? teacher.certificate : '',
}); const { ctx } = this;
const where = { id: class_id };
const classs = await ctx.classModel.CourseClass.one({ where });
classs.dataValues.age_text = Number(classs.max_age) > 0 ? `${classs.min_age}-${classs.max_age}岁` : '';
classs.dataValues.point_tags = classs.point ? classs.point.split(',') : [];
const class_images = await ctx.classModel.CourseImages.findAll({ where: { type: 2, type_id: classs.id } });
// 处理图片
const photo_album = [];
const photo_check = []; // 去重
for (const i in class_images) {
const class_image = class_images[i];
if (class_image.is_video > 0) {
if (photo_check.includes(class_image.video_url)) {
continue;
} else {
photo_check.push(class_image.video_url);
} }
} else {
return ret; if (photo_check.includes(class_image.image_url)) {
continue;
} else {
photo_check.push(class_image.image_url);
}
}
photo_album.push({
image: class_image.image_url,
is_video: class_image.is_video,
video_url: class_image.video_url,
});
}
classs.dataValues.photo_album = photo_album;
classs.dataValues.class_period = classs.class_period > 0 ? classs.class_period : '';
return classs;
}
async getTeachers(input) {
const { ctx } = this;
const attributes = [ 'id', 'institution_id', 'name', 'avatar', 'teacher_experience', 'lesson', 'educational_background', 'certificate' ];
const { institution_id, page, limit } = input;
const where = { institution_id };
const teachers = await ctx.classModel.CourseTeacher.list({ attributes, page, limit, where });
const ret = [];
for (const i in teachers.rows) {
const teacher = teachers.rows[i];
ret.push({
id: teacher.id,
institution_id: teacher.institution_id,
name: teacher.name ? teacher.name : '',
avatar: teacher.avatar ? teacher.avatar : '',
teacher_experience: teacher.teacher_experience ? teacher.teacher_experience : '',
lesson: teacher.lesson ? teacher.lesson : '',
educational_background: teacher.educational_background ? teacher.educational_background : '',
certificate: teacher.certificate ? teacher.certificate : '',
});
} }
async getClasses(input) { return { page, count: ret.length, rows: ret };
const { ctx } = this; }
const attributes = ['id', 'institution_id', 'name', 'type', 'price'];
const { institution_id, page, limit } = input;
const where = { institution_id };
const classes = await ctx.classModel.CourseClass.list({ attributes, page, limit, where });
const p_class_images = [];
//获取图片信息 async getClasses(input) {
for (let j in classes.rows) {
const classs = classes.rows[j];
p_class_images[j] = ctx.classModel.CourseImages.one({ where: { type: 2, type_id: classs.id, is_cover: 1, is_video: 0 } });
}
const class_images = await Promise.all(p_class_images).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
//格式化课程信息 const { ctx } = this;
let ret = []; const attributes = [ 'id', 'institution_id', 'name', 'type', 'price' ];
for (let i in classes.rows) { const { institution_id, page, limit } = input;
let classs = classes.rows[i]; const where = { institution_id };
classs.dataValues.image = class_images[i] ? class_images[i].image_url : '';; const classes = await ctx.classModel.CourseClass.list({ attributes, page, limit, where });
classs.dataValues.price_text = classs.price ? classs.price : '现场咨询'; const p_class_images = [];
ret.push(classs);
}
return { page: classes.page, count: classes.count, rows: ret };
// 获取图片信息
for (const j in classes.rows) {
const classs = classes.rows[j];
p_class_images[j] = ctx.classModel.CourseImages.one({ where: { type: 2, type_id: classs.id, is_video: 0 } });
}
const class_images = await Promise.all(p_class_images).then(result => { // 等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
// 格式化课程信息
const ret = [];
for (const i in classes.rows) {
const classs = classes.rows[i];
classs.dataValues.image = class_images[i] ? class_images[i].image_url : '';
classs.dataValues.price_text = classs.price ? classs.price : '现场咨询';
classs.dataValues.class_period = classs.class_period > 0 ? classs.class_period : '';
ret.push(classs);
} }
async getInstitutionAreas(input) { return { page: classes.page, count: classes.count, rows: ret };
const { ctx } = this; }
const attributes = ['id', 'institution_id', 'name', 'address', 'phone', 'lat', 'lng'];
const { institution_id, page, limit } = input;
const where = { institution_id };
const areas = await ctx.classModel.CourseArea.list({ attributes, page, limit, where });
return areas; async getInstitutionAreas(input) {
} const { ctx } = this;
const attributes = [ 'id', 'institution_id', 'name', 'address', 'phone', 'lat', 'lng' ];
const { institution_id, page, limit } = input;
const where = { institution_id };
const areas = await ctx.classModel.CourseArea.list({ attributes, page, limit, where });
//机构列表 并有多校区 {id:1,..., course_areas:[{},{}] return areas;
async getInstitutionAreaList(institutions) {
const { ctx } = this; }
if (!Array.isArray(institutions) || institutions.length === 0) { // 机构列表 并有多校区 {id:1,..., course_areas:[{},{}]
return []; async getInstitutionAreaList(institutions) {
}
const ret = []; const { ctx } = this;
for (let i in institutions) {
let institution = institutions[i];
if (!institution.course_areas || institution.course_areas.length === 0) continue;
const course_areas = institution.course_areas;
for (let j in course_areas) {
const course_area = course_areas[j];
ret.push({
id: institution.id,
name: institution.name,
type: institution.type,
image: institution.image,
establishment_time: institution.establishment_time,
class_type: institution.class_type,
teacher_count: institution.teacher_count,
teacher_experience: institution.teacher_experience,
corner: institution.corner,
min_age: institution.min_age,
max_age: institution.max_age,
price: institution.price,
characteristic: institution.characteristic,
area_id: course_area.id,
area_name: course_area.name,
area_address: course_area.address,
lat: course_area.lat,
lng: course_area.lng,
});
}
}
return ret; if (!Array.isArray(institutions) || institutions.length === 0) {
return [];
} }
/** const ret = [];
for (const i in institutions) {
const institution = institutions[i];
if (!institution.course_areas || institution.course_areas.length === 0) continue;
const course_areas = institution.course_areas;
for (const j in course_areas) {
const course_area = course_areas[j];
ret.push({
id: institution.id,
name: institution.name,
type: institution.type,
image: institution.image,
establishment_time: institution.establishment_time,
class_type: institution.class_type,
teacher_count: institution.teacher_count,
teacher_experience: institution.teacher_experience,
corner: institution.corner,
min_age: institution.min_age,
max_age: institution.max_age,
price: institution.price,
characteristic: institution.characteristic,
area_id: course_area.id,
area_name: course_area.name,
area_address: course_area.address,
lat: course_area.lat,
lng: course_area.lng,
});
}
}
return ret;
}
/**
* 起点()到多个终点([{ lng: 120.212997, lat: 30.29133 }];) 计算距离 distance=3km * 起点()到多个终点([{ lng: 120.212997, lat: 30.29133 }];) 计算距离 distance=3km
* @param {*} lbs_array [{ lng: 120.212997, lat: 30.29133 }] * @param {*} lbs_array [{ lng: 120.212997, lat: 30.29133 }]
* @param {*} from_gps { lng: 120.069206, lat: 30.291121 } * @param {*} from_gps { lng: 120.069206, lat: 30.291121 }
* @param {*} distance 3 * @param {*} distance 3
*/ */
async computeDistance(lbs_array, from_gps, distance = 3) { async computeDistance(lbs_array, from_gps, distance = 3) {
const { ctx } = this; const { ctx } = this;
if (!Array.isArray(lbs_array) || lbs_array.length === 0) { if (!Array.isArray(lbs_array) || lbs_array.length === 0) {
return []; return [];
} }
const from = from_gps; const from = from_gps;
const lat = from.lat; const lat = from.lat;
const lng = from.lng; const lng = from.lng;
// console.info({ lat, lng }); // console.info({ lat, lng });
//计算距离 // 计算距离
const driving_results = await ctx.service.course.lbs.getLBSDistance('driving', { lat, lng }, lbs_array); const driving_results = await ctx.service.course.lbs.getLBSDistance('driving', { lat, lng }, lbs_array);
const walking_results = await ctx.service.course.lbs.getLBSDistance('walking', { lat, lng }, lbs_array); const walking_results = await ctx.service.course.lbs.getLBSDistance('walking', { lat, lng }, lbs_array);
if (!walking_results.results && !driving_results.results) { if (!walking_results.results && !driving_results.results) {
return []; return [];
} }
//处理距离结果 // 处理距离结果
const drivings = driving_results.results.map(item => { const drivings = driving_results.results.map(item => {
const distance = (item.distance / 1000).toFixed(1); const distance = (item.distance / 1000).toFixed(1);
const duration = Math.ceil(item.duration / 60); const duration = Math.ceil(item.duration / 60);
return { distance: distance, duration: duration } return { distance, duration };
}); });
const walkings = walking_results.results.map(item => { const walkings = walking_results.results.map(item => {
const distance = (item.distance / 1000).toFixed(2); const distance = (item.distance / 1000).toFixed(2);
const duration = Math.ceil(item.distance / 80); const duration = Math.ceil(item.distance / 80);
return { distance: distance, duration: duration } return { distance, duration };
}); });
// 格式化 判断步行或驾车
const results = [];
for (const i in lbs_array) {
const lbs = lbs_array[i];
const driving = (drivings[i] && drivings[i].distance !== -1) ? drivings[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 travel_method = driving.distance > distance ? 'driving' : 'walking';
results.push({
lat: lbs.lat,
lng: lbs.lng,
distance: lbs_distance.distance,
duration: lbs_distance.duration,
travel_method,
});
}
//格式化 判断步行或驾车 return results;
const results = [];
for (let i in lbs_array) { }
let lbs = lbs_array[i];
const driving = (drivings[i] && drivings[i].distance !== -1) ? drivings[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 travel_method = driving.distance > distance ? 'driving' : 'walking';
results.push({
lat: lbs.lat,
lng: lbs.lng,
distance: lbs_distance.distance,
duration: lbs_distance.duration,
travel_method,
});
}
return results; // 先本地用公式计算距离,然后分页,取对应的再去调腾讯接口
async calcDistance(lbs_array, from_gps, page = 1, distance = 0) {
const { ctx } = this;
if (!Array.isArray(lbs_array) || lbs_array.length === 0) {
return { count: 0, rows: [] };
} }
/** const calcHandle = [];
* for (const v of lbs_array) {
* @param {*} institution_areas 校区列表 calcHandle.push(ctx.service.course.lbs.getDistance(v, from_gps));
* @param {*} areas_list 校区距离列表 }
*/ const result = await Promise.all(calcHandle).then(result => {
async findShortestDistanceAreas(institution_areas, areas_list) { return result;
}).catch(error => {
const { ctx } = this; ctx.failed(error);
});
let ret = [];
// const institution_lbs = await this.computeDistance(areas_list); let ret = [];
for (const i in result) {
const institution_lbs = areas_list; const tmp = lbs_array[i];
for (let i in institution_areas) { tmp.distance = result[i];
if (distance === 0 || (distance > 0 && tmp.distance <= distance)) {
let institution_area = institution_areas[i]; ret.push(tmp);
//TODO 校验经纬度 }
const lbs = i < institution_lbs.length ? institution_lbs[i] : { distance: 0, duration: 0, travel_method: '' }; }
const area_name = institution_area.area_name;
const distance = lbs.distance;
const duration = lbs.duration;
let travel_tips = `${area_name},距我${distance}km,开车${duration}分钟`;
if (lbs.travel_method === 'walking') {
travel_tips = `${area_name},距我${distance}km,步行${duration}分钟`;
}
if (distance === 0 && duration === 0) {
travel_tips = '暂无法计算出距离';
}
// area.distance = distance;
// area.duration = duration;
// area.travel_tips = travel_tips;
institution_area.distance = distance;
institution_area.duration = duration;
institution_area.travel_tips = travel_tips;
ret[i] = institution_area;
}
const results = []; const sort = function(a, b) {
ret = _.orderBy(ret, ['distance'], ['asc']); return a.distance - b.distance;
for (let j in ret) { };
const val = ret[j];
if (!results[val.id]) {
results[val.id] = val;
}
}
return results; ret = R.sort(sort)(ret);
}
async formatInstitutions(institutions) { const institutions = [];
for (const v of ret) {
if (!institutions[v.id] && !ctx.isEmpty(v)) {
institutions[v.id] = v;
}
}
const { ctx } = this; let results = [];
if (!Array.isArray(institutions) || institutions.length === 0) { for (const v of institutions) {
return []; if (!ctx.isEmpty(v)) {
} results.push(v);
}
}
//处理机构图片 results = R.sort(sort)(results);
const p_institution_images = [];
for (let j in institutions) {
const institution = institutions[j];
p_institution_images[j] = ctx.classModel.CourseImages.one({ where: { type: 1, type_id: institution.id, is_cover: 1, is_video: 0 } });
}
const institution_images = await Promise.all(p_institution_images).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
const ret = []; if (results.length <= (page - 1) * 10) {
for (let i in institutions) { return { count: 0, rows: [] };
const institution = institutions[i]; }
// const course_areas = institution.course_areas; const end = page * 10 > results.length ? results.length : page * 10;
// if (!course_areas || course_areas.length === 0) continue; return {
const age_tag = institution.min_age + '-' + institution.max_age + '岁'; count: results.length,
const build_time = moment().format('YYYY') - institution.establishment_time; rows: R.slice((page - 1) * 10, end)(results),
const tags = []; };
if (institution.max_age) { }
tags.push(age_tag);
} /**
if (institution.class_type) { *
tags.push(institution.class_type); * @param {*} institution_areas 校区列表
} * @param {*} areas_list 校区距离列表
if (Number(institution.establishment_time)) { */
tags.push('成立' + build_time + '年'); async findShortestDistanceAreas(institution_areas, areas_list) {
}
const image = institution_images[i] ? institution_images[i].image_url : ''; const { ctx } = this;
ret.push({ let ret = [];
id: institution.id, // const institution_lbs = await this.computeDistance(areas_list);
name: institution.name,
image, const institution_lbs = areas_list;
establishment_time: institution.establishment_time, for (const i in institution_areas) {
class_type: institution.class_type,
teacher_count: institution.teacher_count ? institution.teacher_count : 0, const institution_area = institution_areas[i];
teacher_experience: institution.teacher_experience ? institution.teacher_experience : 0, // TODO 校验经纬度
corner: institution.corner ? institution.corner : '', const lbs = i < institution_lbs.length ? institution_lbs[i] : { distance: 0, duration: 0, travel_method: '' };
min_age: institution.min_age,
max_age: institution.max_age, const area_name = institution_area.area_name;
price: institution.price ? institution.price : 0, const distance = lbs.distance;
tags, const duration = lbs.duration;
area_id: institution.area_id,//校区id TODO let travel_tips = `${area_name},距我${distance}km,开车${duration}分钟`;
travel_tips: institution.travel_tips, //TODO if (lbs.travel_method === 'walking') {
characteristic: institution.characteristic ? institution.characteristic : '', travel_tips = `${area_name},距我${distance}km,步行${duration}分钟`;
}); }
} if (Number(distance) === 0 && Number(duration) === 0) {
travel_tips = '暂无法计算出距离';
}
// area.distance = distance;
// area.duration = duration;
// area.travel_tips = travel_tips;
institution_area.distance = Number(distance) === 0 ? 999999999.0 : parseFloat(distance);
institution_area.duration = duration;
institution_area.travel_tips = travel_tips;
ret[i] = institution_area;
}
return ret; const results = [];
ret = _.orderBy(ret, [ 'distance' ], [ 'asc' ]);
for (const j in ret) {
const val = ret[j];
if (!results[val.id]) {
results[val.id] = val;
}
} }
return results;
}
async formatInstitutions(institutions, distance = 0) {
const { ctx } = this;
if (!Array.isArray(institutions) || institutions.length === 0) {
return [];
}
// 处理机构图片
const p_institution_images = [];
for (const j in institutions) {
const institution = institutions[j];
p_institution_images[j] = ctx.classModel.CourseImages.one({ where: { type: 1, type_id: institution.id, is_cover: 1, is_video: 0 } });
}
const institution_images = await Promise.all(p_institution_images).then(result => { // 等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
const userCollect = await ctx.classModel.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0 } });
const ids = R.pluck('institution_id', userCollect);
let ret = [];
for (const i in institutions) {
const institution = institutions[i];
if (distance > 0 && distance < institution.distance * 1000) {
continue;
}
// const course_areas = institution.course_areas;
// if (!course_areas || course_areas.length === 0) continue;
const age_tag = institution.min_age + '-' + institution.max_age + '岁';
const build_time = moment().format('YYYY') - institution.establishment_time;
const tags = [];
if (institution.max_age) {
tags.push(age_tag);
}
if (institution.class_type) {
tags.push(institution.class_type);
}
if (Number(institution.establishment_time)) {
tags.push('成立' + build_time + '年');
}
let image = institution_images[i] ? institution_images[i].image_url : '';
// 取不到封面图就从详情图列表里选一张
if (ctx.isEmpty(image)) {
const tmpImage = await ctx.classModel.CourseImages.one({ where: { type: 1, type_id: institution.id, is_cover: 0, is_video: 0 } });
image = ctx.isEmpty(tmpImage) ? '' : tmpImage.image_url;
}
ret.push({
id: institution.id,
name: institution.name,
image,
establishment_time: institution.establishment_time,
class_type: institution.class_type,
teacher_count: institution.teacher_count ? institution.teacher_count : 0,
teacher_experience: institution.teacher_experience ? institution.teacher_experience : 0,
corner: institution.corner ? institution.corner : '',
min_age: institution.min_age,
max_age: institution.max_age,
price: institution.price ? institution.price : 0,
tags,
area_id: institution.area_id, // 校区id TODO
travel_tips: institution.travel_tips, // TODO
characteristic: institution.characteristic ? institution.characteristic : '',
distance: institution.distance,
is_collected: ids.includes(institution.id) ? 1 : 0,
});
}
ret = _.orderBy(ret, [ 'distance' ], [ 'asc' ]);
return ret;
}
} }
......
...@@ -4,66 +4,76 @@ ...@@ -4,66 +4,76 @@
const Service = require('egg').Service; const Service = require('egg').Service;
const AGE_CATS = [ const AGE_CATS = [
{ id: -2, name: '全部', value: 0 }, { id: -2, name: '全部', value: 0 },
{ id: -3, name: '3岁以下', value: 3 }, { id: -3, name: '3岁以下', value: 3 },
{ id: -4, name: '4岁', value: 4 }, { id: -4, name: '4岁', value: 4 },
{ id: -5, name: '5岁', value: 5 }, { id: -5, name: '5岁', value: 5 },
{ id: -6, name: '6岁', value: 6 }, { id: -6, name: '6岁', value: 6 },
{ id: -7, name: '7岁', value: 7 }, { id: -7, name: '7岁', value: 7 },
{ id: -8, name: '8岁', value: 8 }, { id: -8, name: '8岁', value: 8 },
{ id: -9, name: '9岁', value: 9 }, { id: -9, name: '9岁', value: 9 },
{ id: -10, name: '10岁', value: 10 }, { id: -10, name: '10岁', value: 10 },
{ id: -11, name: '11岁', value: 11 }, { id: -11, name: '11岁', value: 11 },
{ id: -12, name: '12岁', value: 12 }, { id: -12, name: '12岁', value: 12 },
{ id: -13, name: '12岁以上', value: 13 }, { id: -13, name: '12岁以上', value: 13 },
]; ];
const INSTITUTION_TYPE = [ const INSTITUTION_TYPE = [
{ id: -14, name: '全部', value: '' }, { id: -14, name: '全部', value: '' },
{ id: -15, name: '品牌', value: '品牌' }, { id: -15, name: '品牌', value: '品牌' },
];
const DISTANCES = [
{ id: -16, name: '全部', value: 0 },
{ id: -17, name: '500米以内', value: 500 },
{ id: -18, name: '1公里以内', value: 1000 },
{ id: -19, name: '2公里以内', value: 2000 },
{ id: -20, name: '3公里以内', value: 3000 },
{ id: -21, name: '5公里以内', value: 5000 },
]; ];
class OptionService extends Service { class OptionService extends Service {
/** /**
* 我的信用首页 * 我的信用首页
*/ */
async getOptions() { async getOptions() {
const { ctx } = this; const { ctx } = this;
const cats = await ctx.classModel.CourseCat.all({ where: { status: 1, is_deleted: 0 } }); const cats = await ctx.classModel.CourseCat.all({ where: { status: 1, is_deleted: 0 } });
const tree_cats = this.getTrees(cats, 0); const tree_cats = this.getTrees(cats, 0);
const options = { const options = {
cats: tree_cats, cats: tree_cats,
ages: AGE_CATS, ages: AGE_CATS,
institutions: INSTITUTION_TYPE, institutions: INSTITUTION_TYPE,
} distances: DISTANCES,
return options; };
} return options;
}
getTrees(data, rootId) { getTrees(data, rootId) {
const ret = []; const ret = [];
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const node = data[i]; const node = data[i];
if (node.parent_id == rootId) { if (node.parent_id == rootId) {
const newNode = {}; const newNode = {};
// if (node.parent_id == 0) newNode._child.push({ id: 0, name: '全部', value: '' }); // if (node.parent_id == 0) newNode._child.push({ id: 0, name: '全部', value: '' });
newNode.id = node.id; newNode.id = node.id;
newNode.name = node.name; newNode.name = node.name;
newNode.tips = node.tips; newNode.tips = node.tips;
newNode.image = node.image; newNode.image = node.image;
newNode.color = node.color; newNode.color = node.color;
newNode.level = node.level; newNode.level = node.level;
newNode.value = node.id; newNode.value = node.id;
newNode._child = this.getTrees(data, node.id); newNode._child = this.getTrees(data, node.id);
if (newNode._child.length !== 0) newNode._child.unshift({ id: 0, name: '全部', value: 0 }); if (newNode._child.length !== 0) newNode._child.unshift({ id: 0, name: '全部', value: node.id });
ret.push(newNode); ret.push(newNode);
} }
}
return ret;
} }
return ret;
}
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -58,20 +58,29 @@ class ApplyService extends Service { ...@@ -58,20 +58,29 @@ class ApplyService extends Service {
return ret; return ret;
} }
/**
* 进入个人通话查询页面
*/
async callriskInit() { async callriskInit() {
const { ctx } = this; const { ctx } = this;
if (!ctx.userId) {
ctx.failed('登录异常');
}
let ret = { let ret = {
have_be_pay_order: false, have_be_pay_order: false,
order_id: null, order_id: null,
phone: '',
placeholder: { placeholder: {
name: '', name: '',
id_card: '' id_card: '',
} }
} }
let bePayOrder = await ctx.service.credit.order.getBePayOrder('callrisk'); let bePayOrder = await ctx.service.credit.order.getBePayOrder('callrisk');
if (bePayOrder.length !== 0) { if (bePayOrder.length !== 0) {
ret.have_be_pay_order = true; ret.have_be_pay_order = true;
ret.order_id = bePayOrder[0].id; ret.order_id = bePayOrder[0].id;
ret.phone = bePayOrder[0].phone.substring(0, 3) + '****' + bePayOrder[0].phone.substring(7, 11)
} }
//第一次查询成功的订单,反显姓名和身份证 //第一次查询成功的订单,反显姓名和身份证
...@@ -159,7 +168,7 @@ class ApplyService extends Service { ...@@ -159,7 +168,7 @@ class ApplyService extends Service {
} }
times++; times++;
if (times >= 11) { if (times >= 11) {
ctx.failed('今日获取验证码次数过多,请明日再试'); // ctx.failed('今日获取验证码次数过多,请明日再试');
} }
let pexpire = new Date(moment().add(1, 'days').format('YYYY-MM-DD 00:00:00')).getTime(); let pexpire = new Date(moment().add(1, 'days').format('YYYY-MM-DD 00:00:00')).getTime();
let validTime = Number(pexpire) - Number(moment().format('x')); let validTime = Number(pexpire) - Number(moment().format('x'));
...@@ -171,6 +180,7 @@ class ApplyService extends Service { ...@@ -171,6 +180,7 @@ class ApplyService extends Service {
code = Math.round(Math.random() * 9999).toString(); code = Math.round(Math.random() * 9999).toString();
let len = code.length; let len = code.length;
if ((4 - len) > 0) { if ((4 - len) > 0) {
ß
for (var i = 0; i < 4 - len; i++) { for (var i = 0; i < 4 - len; i++) {
code = '0' + code; code = '0' + code;
} }
...@@ -276,10 +286,7 @@ class ApplyService extends Service { ...@@ -276,10 +286,7 @@ class ApplyService extends Service {
ctx.logger.info(params); ctx.logger.info(params);
let url = this.config.BLACKLIST_APPLY_URL; let url = this.config.BLACKLIST_APPLY_URL;
let result = await ctx.helper.send_request(url, params, { method: 'POST' }); let result = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info(result); ctx.logger.info('blacklist:apply:result:' + JSON.stringify(result));
ctx.logger.info(result.data);
ctx.logger.info(result.data.data.blackList);
if (result.status != 200) { if (result.status != 200) {
ctx.failed('数据获取接口异常'); ctx.failed('数据获取接口异常');
} }
...@@ -332,7 +339,7 @@ class ApplyService extends Service { ...@@ -332,7 +339,7 @@ class ApplyService extends Service {
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, net } = input;
const user_id = ctx.userId; const user_id = ctx.userId;
const app_type_id = ctx.appTypeId; const app_type_id = ctx.appTypeId;
const app_user_id = ctx.appUserId; const app_user_id = ctx.appUserId;
...@@ -340,7 +347,7 @@ class ApplyService extends Service { ...@@ -340,7 +347,7 @@ class ApplyService extends Service {
const type = TypeConfig['callrisk'];//个人通话类型 const type = TypeConfig['callrisk'];//个人通话类型
let report_id = null; let report_id = null;
//数盒魔方三要素校验 //数盒魔方三要素校验
// await ctx.service.credit.callrisk.checkThreeElements(input); await ctx.service.credit.callrisk.checkThreeElements(input);
// await ctx.service.credit.common.shuhemofangCheck('callrisk', input); // await ctx.service.credit.common.shuhemofangCheck('callrisk', input);
//判断用户当前三要素是否是二次查询未支付订单 //判断用户当前三要素是否是二次查询未支付订单
...@@ -355,12 +362,12 @@ class ApplyService extends Service { ...@@ -355,12 +362,12 @@ class ApplyService extends Service {
const order_id = order.id; const order_id = order.id;
//创建yys-order apply 记录 //创建yys-order apply 记录
const apply = await this.createYysApply({ name, phone, id_card, password, order_id }); const apply = await this.createYysApply({ name, phone, id_card, password, net, order_id });
const order_sn = apply.r_order_id; const order_sn = apply.r_order_id;
//第一次调用运营商获取验证码接口 //第一次调用运营商获取验证码接口
const input_params = { const input_params = {
phone,name, phone, name,
ID: id_card, ID: id_card,
password: apply.service_code, password: apply.service_code,
}; };
...@@ -376,7 +383,7 @@ class ApplyService extends Service { ...@@ -376,7 +383,7 @@ class ApplyService extends Service {
// get_code_params.data.phoneCode = ''; // get_code_params.data.phoneCode = '';
const yys_get_code = await ctx.service.credit.yys.getCode(get_code_params); const yys_get_code = await ctx.service.credit.yys.getCode(get_code_params);
if (yys_get_code.code !== 0) { if (yys_get_code.code !== 0) {
ctx.failed('getCode error msg:' + yys_get_code.msg); ctx.failed(yys_get_code.msg);
} }
const order_no = await ctx.service.credit.common.getOrdertNo('callrisk', order_id); const order_no = await ctx.service.credit.common.getOrdertNo('callrisk', order_id);
await ctx.prometheusModel.CreditOrder.update({ order_no, apply_id: apply.id }, { where: { id: order_id } }); await ctx.prometheusModel.CreditOrder.update({ order_no, apply_id: apply.id }, { where: { id: order_id } });
...@@ -394,10 +401,10 @@ class ApplyService extends Service { ...@@ -394,10 +401,10 @@ class ApplyService extends Service {
const app_type_id = ctx.appTypeId; const app_type_id = ctx.appTypeId;
const app_user_id = ctx.appUserId; const app_user_id = ctx.appUserId;
const app_id = ctx.appId; const app_id = ctx.appId;
const { name, phone, id_card, password, order_id } = input; const { name, phone, id_card, password, net, order_id } = input;
//运营商API.创建订单号 //运营商API.创建订单号
const order_sn_info = await ctx.service.credit.yys.getOrderSn(phone); const order_sn_info = await ctx.service.credit.yys.getOrderSn({ phone, net });
if (order_sn_info.code !== 0) { if (order_sn_info.code !== 0) {
ctx.failed('getOrderSn error msg:' + order_sn_info.msg); ctx.failed('getOrderSn error msg:' + order_sn_info.msg);
} }
...@@ -432,14 +439,14 @@ class ApplyService extends Service { ...@@ -432,14 +439,14 @@ class ApplyService extends Service {
let orderFilter = { let orderFilter = {
arrtibutes: ['id', 'name', 'id_card'], arrtibutes: ['id', 'name', 'id_card'],
where: { where: {
user_id: ctx.userId, user_id: user_id,
state: '已支付', state: '已支付',
type: 2, type: type,
valid: 1 valid: 1
} }
} }
let orderInfo = await ctx.prometheusModel.CreditOrder.findOne(orderFilter); let orderInfo = await ctx.prometheusModel.CreditOrder.findOne(orderFilter);
if (orderInfo !== null && (inputParams.name !== orderInfo.name || inputParams.id_card !== orderInfo.id_card)) { if (orderInfo !== null && (name !== orderInfo.name || id_card !== orderInfo.id_card)) {
ctx.failed('仅供本人查询使用,无法查询其他人信息'); ctx.failed('仅供本人查询使用,无法查询其他人信息');
} }
......
...@@ -372,7 +372,8 @@ class BlacklistService extends Service { ...@@ -372,7 +372,8 @@ class BlacklistService extends Service {
let birth = parseInt(inputParams.id_card.substring(6, 10)); let birth = parseInt(inputParams.id_card.substring(6, 10));
let age = parseInt(moment().format('YYYY')) - birth; let age = parseInt(moment().format('YYYY')) - birth;
let city = await ctx.service.credit.common.getIdCardCity(inputParams.id_card); // let city = await ctx.service.credit.common.getIdCardCity(inputParams.id_card);
let city = await ctx.helper.getPhoneCity(inputParams.phone);//2019-10-14 20:36:00 lisk 改为获取手机号归属地
let reportData = { let reportData = {
name: inputParams.name, name: inputParams.name,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
const Service = require('egg').Service; const Service = require('egg').Service;
const moment = require('moment'); const moment = require('moment');
const R = require('ramda');
class CallriskService extends Service { class CallriskService extends Service {
...@@ -70,19 +71,34 @@ class CallriskService extends Service { ...@@ -70,19 +71,34 @@ class CallriskService extends Service {
const { ctx } = this; const { ctx } = this;
const basics = await ctx.prometheusModel.CreditCallriskReport.one({ where: { id: report_id } }); let basics = await ctx.prometheusModel.CreditCallriskReport.one({ where: { id: report_id, user_id: ctx.userId } });
if (!basics || !basics.id) { if (!basics || !basics.id) {
ctx.failed('error report_id'); ctx.failed('error report_id');
} }
const call_overview = await this.getCallOverview(report_id); const call_overview = await this.getCallOverview(report_id);
const call_type = await this.getCallType(report_id); const call_type = await this.getCallType(report_id);
const call_active = await this.getCallActive(report_id); let call_active = await this.getCallActive(report_id);
const call_behavior = await this.getCallBehavior(report_id); const call_behavior = await this.getCallBehavior(report_id);
//订单是否在有效期内 //订单是否在有效期内
const net_time = basics.net_time;
const months = parseInt(net_time / 30);
const days = net_time % 30;
basics.net_time = months + '月' + (days ? days + '天' : '');
basics.mobile = basics.mobile.substring(0, 3) + '****' + basics.mobile.substring(7, 11);//手机号(只展示前三位和后四位)
basics.dataValues.report_time = moment(basics.created_at).format('YYYY-MM-DD');
delete basics.created_at;
const diff = function (a, b) { return b.call_count - a.call_count };
const city_active = R.sort(diff)(call_active.city_active).slice(0, 3);
call_active.city_active = JSON.stringify(city_active);
call_behavior.silence_time_3day = call_behavior.silence_time_3day * 24 * 60;//转为分钟
call_behavior.call_rank.maximum_active_call_number = call_behavior.call_rank.maximum_active_call_number ? call_behavior.call_rank.maximum_active_call_number.substring(0, 3) + '****' + call_behavior.call_rank.maximum_active_call_number.substring(7, 11) : '';//手机号(只展示前三位和后四位)
call_behavior.call_rank.maximum_passive_call_number = call_behavior.call_rank.maximum_passive_call_number ? call_behavior.call_rank.maximum_passive_call_number.substring(0, 3) + '****' + call_behavior.call_rank.maximum_passive_call_number.substring(7, 11) : '';//手机号(只展示前三位和后四位)
call_behavior.call_rank.maximum_call_time_number = call_behavior.call_rank.maximum_call_time_number ? call_behavior.call_rank.maximum_call_time_number.substring(0, 3) + '****' + call_behavior.call_rank.maximum_call_time_number.substring(7, 11) : '';//手机号(只展示前三位和后四位)
const report_valid = await ctx.service.credit.order.getReportValid('callrisk', report_id); const report_valid = await ctx.service.credit.order.getReportValid('callrisk', report_id);
const report = { let report = {
basics: { data: basics }, basics: { data: basics },
call_overview: { data: call_overview }, call_overview: { data: call_overview },
call_type: { data: call_type }, call_type: { data: call_type },
...@@ -90,8 +106,9 @@ class CallriskService extends Service { ...@@ -90,8 +106,9 @@ class CallriskService extends Service {
call_behavior: { data: call_behavior }, call_behavior: { data: call_behavior },
report_valid, report_valid,
}; };
report.basics.data.call_result_assessment = await this.getEvaluationLevel(report);
const ret = this.formatHeadExplainMsg(report); const ret = await this.formatHeadExplainMsg(report);
return ret; return ret;
} }
...@@ -129,7 +146,6 @@ class CallriskService extends Service { ...@@ -129,7 +146,6 @@ class CallriskService extends Service {
const { ctx } = this; const { ctx } = this;
const call_active = await ctx.prometheusModel.CreditCallriskCallActive.one({ where: { report_id } }); const call_active = await ctx.prometheusModel.CreditCallriskCallActive.one({ where: { report_id } });
return call_active; return call_active;
} }
...@@ -137,10 +153,31 @@ class CallriskService extends Service { ...@@ -137,10 +153,31 @@ class CallriskService extends Service {
const { ctx } = this; const { ctx } = this;
const call_behavior = await ctx.prometheusModel.CreditCallriskCallBehavior.one({ where: { report_id } }); const call_behavior = await ctx.prometheusModel.CreditCallriskCallBehavior.one({ where: { report_id } });
const call_behavior_silence_cycles = await ctx.prometheusModel.CreditCallriskSilenceCycle.all({ where: { report_id } }); const call_behavior_silence_cycles = await ctx.prometheusModel.CreditCallriskSilenceCycle.list({ where: { report_id }, order: [['silence_end_time', 'desc']] });
call_behavior.silence_cycle = call_behavior ? [] : call_behavior_silence_cycles; const ret = {
silence_count_3day: call_behavior.silence_count_3day,
silence_time_3day: call_behavior.silence_time_3day,
silence_time_rate_3day: call_behavior.silence_time_rate_3day,
silence_cycle: call_behavior_silence_cycles.rows,
call_each_other: {
active_call_count: call_behavior.active_call_count,
passive_call_count: call_behavior.passive_call_count,
each_call_count: call_behavior.each_call_count,
},
call_rank: {
maximum_active_call_count: call_behavior.maximum_active_call_count,
maximum_active_call_number: call_behavior.maximum_active_call_number,
maximum_active_call_city: call_behavior.maximum_active_call_city,
maximum_passive_call_count: call_behavior.maximum_passive_call_count,
maximum_passive_call_number: call_behavior.maximum_passive_call_number,
maximum_passive_call_city: call_behavior.maximum_passive_call_city,
maximum_call_time: call_behavior.maximum_call_time,
maximum_call_time_number: call_behavior.maximum_call_time_number,
maximum_call_time_city: call_behavior.maximum_call_time_city,
},
};
return call_behavior; return ret;
} }
async formatReport() { async formatReport() {
...@@ -338,8 +375,8 @@ class CallriskService extends Service { ...@@ -338,8 +375,8 @@ class CallriskService extends Service {
const { ctx } = this; const { ctx } = this;
const basics = report.basics.data; const basics = report.basics.data;
const call_overview = report.call_overview.data; const call_overview = report.call_overview.data;
// const call_type = report.call_type.data; const call_type = report.call_type.data;
// const call_active = report.call_active.data; const call_active = report.call_active.data;
const call_behavior = report.call_behavior.data; const call_behavior = report.call_behavior.data;
//入网时长分数计算 //入网时长分数计算
...@@ -357,11 +394,11 @@ class CallriskService extends Service { ...@@ -357,11 +394,11 @@ class CallriskService extends Service {
//话费分数计算 //话费分数计算
let month_fee_sum = 0; let month_fee_sum = 0;
for (let i in call_overview.data) { for (let i in call_overview) {
const month_call_overview = call_overview.data[i]; const month_call_overview = call_overview[i];
month_fee_sum += month_call_overview.call_fee_month; month_fee_sum += month_call_overview.call_fee_month;
} }
const fee_avg = month_fee_sum / call_overview.data.length;//平均月话费 const fee_avg = month_fee_sum / call_overview.length;//平均月话费
let fee_avg_score = 0; let fee_avg_score = 0;
if (fee_avg < 20) { if (fee_avg < 20) {
fee_avg_score = 20; fee_avg_score = 20;
...@@ -370,29 +407,38 @@ class CallriskService extends Service { ...@@ -370,29 +407,38 @@ class CallriskService extends Service {
} }
//通话类型分数计算 //通话类型分数计算
const loan_call_count = call_type.loan_call_count;
const bank_call_count = call_type.bank_call_count;
const court_call_count = call_type.court_call_count;
const collection_call_count = call_type.collection_call_count;
const laywer_call_count = call_type.laywer_call_count;
const macao_call_count = call_type.macao_call_count;
let call_type_score = 0; let call_type_score = 0;
if (loan_call_count >= 1) { if (loan_call_count >= 1) {
call_type_score += 7; call_type_score += loan_call_count * 7;
} }
if (bank_call_count >= 1) { if (bank_call_count >= 1) {
call_type_score += 2; call_type_score += bank_call_count * 2;
} }
if (court_call_count >= 1) { if (court_call_count >= 1) {
call_type_score += 5; call_type_score += court_call_count * 5;
}
if(call_type_score > 30){
call_type_score = 30;
} }
if (collection_call_count >= 1) { if (collection_call_count >= 1) {
call_type_score += 10; call_type_score += collection_call_count * 10;
} }
if (laywer_call_count >= 1) { if (laywer_call_count >= 1) {
call_type_score += 4; call_type_score += call_type_score * 4;
} }
if (macao_call_count >= 1) { if (macao_call_count >= 1) {
call_type_score += 4; call_type_score += macao_call_count * 4;
} }
//通话活跃分数计算 //通话活跃分数计算
const call_time_percent = night_call_time / routine_call_time; const call_time_percent = call_active.routine_call_time ? (call_active.night_call_time / call_active.routine_call_time).toFixed(2) : 0;
const call_count_percent = night_call_count / routine_call_count; const call_count_percent = call_active.routine_call_count ? (call_active.night_call_count / call_active.routine_call_count).toFixed(2) : 0;
let call_time_score = 0; let call_time_score = 0;
let call_count_score = 0; let call_count_score = 0;
if (call_time_percent >= 0.2) { if (call_time_percent >= 0.2) {
...@@ -413,7 +459,7 @@ class CallriskService extends Service { ...@@ -413,7 +459,7 @@ class CallriskService extends Service {
} else if (call_count_percent > 0.03) { } else if (call_count_percent > 0.03) {
call_count_score = 10; call_count_score = 10;
} }
const call_active_score = call_time_score < call_count_score ? call_time_score : call_count_score; const call_active_score = call_time_score < call_count_score ? call_count_score : call_time_score;
//通话行为分数计算 //通话行为分数计算
let call_behavior_socre = 0; let call_behavior_socre = 0;
...@@ -426,6 +472,7 @@ class CallriskService extends Service { ...@@ -426,6 +472,7 @@ class CallriskService extends Service {
call_behavior_socre = 10; call_behavior_socre = 10;
} }
console.info(net_time_score, fee_avg_score, call_type_score, call_active_score, call_behavior_socre);
const sum_score = net_time_score + fee_avg_score + call_type_score + call_active_score + call_behavior_socre; const sum_score = net_time_score + fee_avg_score + call_type_score + call_active_score + call_behavior_socre;
let call_result_assessment = '优质'; let call_result_assessment = '优质';
...@@ -448,6 +495,7 @@ class CallriskService extends Service { ...@@ -448,6 +495,7 @@ class CallriskService extends Service {
const call_type = report.call_type.data; const call_type = report.call_type.data;
const call_active = report.call_active.data; const call_active = report.call_active.data;
const call_behavior = report.call_behavior.data; const call_behavior = report.call_behavior.data;
const basics_msg = `我们将依据您授权的运营商通话认证,对您的通话行为进行多维度的分析和评估,帮助您更清楚的了解目前的贷款风险点。`; const basics_msg = `我们将依据您授权的运营商通话认证,对您的通话行为进行多维度的分析和评估,帮助您更清楚的了解目前的贷款风险点。`;
...@@ -480,7 +528,7 @@ class CallriskService extends Service { ...@@ -480,7 +528,7 @@ class CallriskService extends Service {
illegal_text = '高'; illegal_text = '高';
advantage_text = '不利于'; advantage_text = '不利于';
} }
const call_type_msg = `解读:近6个月,贷款类通话累计为【${loan_call_count}次】,金融业务通话【${loan_call_status}】您在短期内可能的申请贷款次数较正常,有利于贷款机构对您的评估;近6个月来,您的疑似风险通话次数较【${risk_call_status}】,您与违法违规事件关联度较【${illegal_text}】,【${advantage_text}】贷款机构对您的评估`; const call_type_msg = `解读:近6个月,贷款类通话累计为【${loan_call_count}次】,金融业务通话【${loan_call_status}您在短期内可能的申请贷款次数较正常,有利于贷款机构对您的评估;近6个月来,您的疑似风险通话次数较【${risk_call_status}】,您与违法违规事件关联度较【${illegal_text}】,【${advantage_text}】贷款机构对您的评估`;
//通话活跃度解析 //通话活跃度解析
...@@ -491,16 +539,16 @@ class CallriskService extends Service { ...@@ -491,16 +539,16 @@ class CallriskService extends Service {
} }
//TODO 计算近6个月每个月通话的城市有几个。 //TODO 计算近6个月每个月通话的城市有几个。
const call_most_city = call_active.city_active.slice(0, 3); const call_most_city = call_active.city_active.slice(0, 3);
let total_time = 0; const total_time = parseInt(call_active.routine_call_time) + parseInt(call_active.night_call_time);
let top_three_city_total_time = 0; let top_three_city_total_time = 0;
for (let i in call_most_city) { for (let i in call_most_city) {
const call_city = call_most_city[i]; const call_city = call_most_city[i];
top_three_city_total_time += call_city.call_time; top_three_city_total_time += parseInt(call_city.call_time);
}
for (let j in call_active.city_active) {
const call = call_active.city_active[j];
total_time += call.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); const percent = (top_three_city_total_time / total_time).toFixed(2);
let call_active_text = ['变化不大', '较好', '有利于']; let call_active_text = ['变化不大', '较好', '有利于'];
if (percent <= 0.6) { if (percent <= 0.6) {
...@@ -511,7 +559,7 @@ class CallriskService extends Service { ...@@ -511,7 +559,7 @@ class CallriskService extends Service {
//通话行为解析 //通话行为解析
let call_behavior_array = ['较少', '稳定', '有利于',]; let call_behavior_array = ['较少', '稳定', '有利于',];
if (call_behavior.silence_count_3day > 3) { if (call_behavior.silence_count_3day > 3) {
call_behavior_array = ['较少', '稳定', '有利于',]; call_behavior_array = ['较多', '较大', '不利于',];
} }
const call_behavior_msg = `您的静默时长、静默次数以及周期,占整体比例【${call_behavior_array[0]}】,通话活跃变动幅度【${call_behavior_array[1]}】,【${call_behavior_array[2]}】贷款机构对您的放贷评估`; const call_behavior_msg = `您的静默时长、静默次数以及周期,占整体比例【${call_behavior_array[0]}】,通话活跃变动幅度【${call_behavior_array[1]}】,【${call_behavior_array[2]}】贷款机构对您的放贷评估`;
...@@ -637,10 +685,10 @@ class CallriskService extends Service { ...@@ -637,10 +685,10 @@ class CallriskService extends Service {
const user_brief = yys_report_data.data.user_brief; const user_brief = yys_report_data.data.user_brief;
const report = { const report = {
report_no: '', report_no: '',
user_id: 12, user_id: user_id || -51,
app_type_id: 12, app_type_id: app_type_id || -51,
app_user_id: 12, app_user_id: app_user_id || -51,
app_id: 12, app_id: app_id || -51,
mobile: user_brief.mobile, mobile: user_brief.mobile,
operator: user_brief.operator, operator: user_brief.operator,
net_time: user_brief.net_time, net_time: user_brief.net_time,
...@@ -703,22 +751,22 @@ class CallriskService extends Service { ...@@ -703,22 +751,22 @@ class CallriskService extends Service {
const call_behavior = yys_report_data.data.call_behavior_analysis; const call_behavior = yys_report_data.data.call_behavior_analysis;
const call_behavior_report = { const call_behavior_report = {
report_id, report_id,
// active_call_count: call_behavior.active_call_count, active_call_count: call_behavior.active_call_number_count,
// passive_call_count: call_behavior.passive_call_count, passive_call_count: call_behavior.passive_call_number_count,
// each_call_count: call_behavior.each_call_count, each_call_count: call_behavior.mutual_call_number_count,
silence_count_3day: call_behavior.silence_count_3day, silence_count_3day: call_behavior.silence_count_3day,
silence_time_3day: call_behavior.silence_time_3day, silence_time_3day: call_behavior.silence_time_3day,
silence_time_rate_3day: call_behavior.silence_time_rate_3day, silence_time_rate_3day: call_behavior.silence_time_rate_3day,
maximum_active_call_count: call_behavior.maximum_active_call_count, maximum_active_call_count: call_behavior.maximum_active_call_count,
maximum_active_call_number: call_behavior.maximum_active_call_number, maximum_active_call_number: call_behavior.maximum_active_call_number,
// maximum_active_call_city: call_behavior.maximum_active_call_city, maximum_active_call_city: call_behavior.maximum_active_call_location,
maximum_passive_call_count: call_behavior.maximum_passive_call_count, maximum_passive_call_count: call_behavior.maximum_passive_call_count,
maximum_passive_call_number: call_behavior.maximum_passive_call_number, maximum_passive_call_number: call_behavior.maximum_passive_call_number,
// maximum_passive_call_city: call_behavior.maximum_passive_call_city, maximum_passive_call_city: call_behavior.maximum_passive_call_location,
maximum_call_time: call_behavior.maximum_call_time, maximum_call_time: call_behavior.maximum_call_time,
maximum_call_time_number: call_behavior.maximum_call_time_number, maximum_call_time_number: call_behavior.maximum_call_time_number,
// maximum_call_time_city: call_behavior.maximum_call_time_city, maximum_call_time_city: call_behavior.maximum_call_time_location,
} }
const call_behavior_id = await ctx.prometheusModel.CreditCallriskCallBehavior.add(call_behavior_report); const call_behavior_id = await ctx.prometheusModel.CreditCallriskCallBehavior.add(call_behavior_report);
......
...@@ -214,6 +214,7 @@ class CommonService extends Service { ...@@ -214,6 +214,7 @@ class CommonService extends Service {
await ctx.prometheusModel.CreditPay.edit({ where: { id: pay_info.id }, params: { pay_result: JSON.stringify(result), transaction_id: sign_data.transaction_id, status: 1 } }); await ctx.prometheusModel.CreditPay.edit({ where: { id: pay_info.id }, params: { pay_result: JSON.stringify(result), transaction_id: sign_data.transaction_id, status: 1 } });
await ctx.service.credit.order.logOrder(order.id); await ctx.service.credit.order.logOrder(order.id);
await ctx.prometheusModel.CreditOrder.update({ state: '已支付', state_time: state_time, pay_status: 1 }, { where: { id: order.id } }); await ctx.prometheusModel.CreditOrder.update({ state: '已支付', state_time: state_time, pay_status: 1 }, { where: { id: order.id } });
await ctx.service.credit.order.updateOrderStateToCancel(order);//更新其他同姓名和身份证号的订单状态
return true; return true;
} }
} }
...@@ -314,13 +315,13 @@ class CommonService extends Service { ...@@ -314,13 +315,13 @@ class CommonService extends Service {
async noticeShuhemofang(status) { async noticeShuhemofang(status) {
const { ctx } = this; const { ctx } = this;
//异常情况 //异常情况
if (status === '2') { if (status == '2') {
ctx.failed('手机号已实名,身份证姓名均不匹配,请重新输入'); ctx.failed('手机号已实名,身份证姓名均不匹配,请重新输入');
} }
if (status === '3') { if (status == '3') {
ctx.failed('手机号已实名,姓名不匹配,请重新输入'); ctx.failed('手机号已实名,姓名不匹配,请重新输入');
} }
if (status === '4') { if (status == '4') {
ctx.failed('手机号已实名,身份证不匹配,请重新输入'); ctx.failed('手机号已实名,身份证不匹配,请重新输入');
} }
//未知情况 //未知情况
...@@ -361,7 +362,7 @@ class CommonService extends Service { ...@@ -361,7 +362,7 @@ class CommonService extends Service {
} }
} }
if (history.in) { if (history.in) {
await this.noticeShuhemofang(Number(history.detail.status)); await this.noticeShuhemofang(history.detail.status);
} else { } else {
if (shmfList.length >= 5) { if (shmfList.length >= 5) {
ctx.failed('您输入的想要检测人数已超过最大限制,仅可检测输入过的检测信息'); ctx.failed('您输入的想要检测人数已超过最大限制,仅可检测输入过的检测信息');
......
...@@ -122,12 +122,14 @@ class OrderService extends Service { ...@@ -122,12 +122,14 @@ class OrderService extends Service {
const slag = TypeConfigFlip[type]; const slag = TypeConfigFlip[type];
const preferential = await ctx.service.credit.preferential.getPreferential(slag); const preferential = await ctx.service.credit.preferential.getPreferential(slag);
let preferential_price = 0; let preferential_price = 0;
let preferential_id = 0;
if (preferential && preferential.id) { if (preferential && preferential.id) {
preferential_price = preferential.price; preferential_price = preferential.price;
preferential_id = preferential.id;
} }
const price = (order.price - preferential_price).toFixed(2); const price = (order.price - preferential_price).toFixed(2);
await ctx.prometheusModel.CreditOrder.update({ final_price: price, preferential_price, preferential_id: preferential.id }, { where: { id, pay_status: 0 } }); await ctx.prometheusModel.CreditOrder.update({ final_price: price, preferential_price, preferential_id: preferential_id }, { where: { id, pay_status: 0 } });
return price; return price;
...@@ -253,6 +255,7 @@ class OrderService extends Service { ...@@ -253,6 +255,7 @@ class OrderService extends Service {
const state_time = moment().format('YYYY-MM-DD HH:mm:ss'); const state_time = moment().format('YYYY-MM-DD HH:mm:ss');
await this.logOrder(order.id); await this.logOrder(order.id);
await ctx.prometheusModel.CreditOrder.update({ state: '已支付', state_time, pay_status: 1 }, { where: { id: order.id, pay_status: 0 } }) await ctx.prometheusModel.CreditOrder.update({ state: '已支付', state_time, pay_status: 1 }, { where: { id: order.id, pay_status: 0 } })
await this.updateOrderStateToCancel(order);//更新其他同姓名和身份证号的订单状态
return true; return true;
} }
} }
...@@ -335,7 +338,7 @@ class OrderService extends Service { ...@@ -335,7 +338,7 @@ class OrderService extends Service {
client_ip: ctx.helper.getClientIP(), client_ip: ctx.helper.getClientIP(),
}; };
await this.addCreditPay(pay_data);//添加下单记录 await this.addCreditPay(pay_data);//添加下单记录
await this.updateOrderStateToCancel(order);//更新其他同姓名和身份证号的订单状态 // await this.updateOrderStateToCancel(order);//更新其他同姓名和身份证号的订单状态//2019-10-14 14:52:23 移动到支付完成时通知那里
await this.updateOrderPrice(order);//更新金额 await this.updateOrderPrice(order);//更新金额
await this.logOrder(order.id);//订单状态变化日志记录 await this.logOrder(order.id);//订单状态变化日志记录
const state_time = moment().format('YYYY-MM-DD HH:mm:ss'); const state_time = moment().format('YYYY-MM-DD HH:mm:ss');
......
...@@ -12,16 +12,17 @@ class YysService extends Service { ...@@ -12,16 +12,17 @@ class YysService extends Service {
* 创建订单号 * 创建订单号
* @param {*} * @param {*}
*/ */
async getOrderSn(phone) { async getOrderSn({ phone, net }) {
const { ctx } = this; const { ctx } = this;
let params = { let params = {
phone: phone phone: phone,
net: Number(net),
} }
let url = this.config.NODE_BASE_URL + '/yys_api/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', timeout: 30000 });
ctx.logger.info(JSON.stringify({ yys_getorderSn_params: params, yys_getorderSn_result: resp })); ctx.logger.info(JSON.stringify({ yys_getorderSn_params: params, yys_getorderSn_result: resp }));
if (resp.data.code === undefined || resp.data.code !== 0) { if (resp.data.code === undefined || resp.data.code !== 0) {
ctx.failed('getorderSn error:' + resp.data.msg); ctx.failed(resp.data.msg);
} }
let order_sn = resp.data.data.orderSn; let order_sn = resp.data.data.orderSn;
await this.addCreditLogYys(order_sn, '/yys_api/getorderSn', params, resp.data); await this.addCreditLogYys(order_sn, '/yys_api/getorderSn', params, resp.data);
...@@ -43,7 +44,7 @@ class YysService extends Service { ...@@ -43,7 +44,7 @@ class YysService extends Service {
// } // }
// } // }
let url = this.config.NODE_BASE_URL + '/yys_api/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', timeout: 30000 });
ctx.logger.info(JSON.stringify({ yys_getCode_params: params, yys_getCode_result: resp })); ctx.logger.info(JSON.stringify({ yys_getCode_params: params, yys_getCode_result: resp }));
await this.addCreditLogYys(params.orderSn, '/yys_api/getCode', params, resp.data); await this.addCreditLogYys(params.orderSn, '/yys_api/getCode', params, resp.data);
// console.info(resp); // console.info(resp);
...@@ -65,7 +66,7 @@ class YysService extends Service { ...@@ -65,7 +66,7 @@ class YysService extends Service {
// } // }
// } // }
const url = this.config.NODE_BASE_URL + '/yys_api/commit' + '?appKey=' + this.config.YYS_APP_KEY; const url = this.config.NODE_BASE_URL + '/yys_api/commit' + '?appKey=' + this.config.YYS_APP_KEY;
const resp = await ctx.helper.send_request(url, params, { method: 'POST' }); const resp = await ctx.helper.send_request(url, params, { method: 'POST', timeout: 30000 });
ctx.logger.info(JSON.stringify({ yys_commit_params: params, yys_commit_result: resp })); ctx.logger.info(JSON.stringify({ yys_commit_params: params, yys_commit_result: resp }));
await this.addCreditLogYys(params.orderSn, '/yys_api/commit', params, resp.data); await this.addCreditLogYys(params.orderSn, '/yys_api/commit', params, resp.data);
return resp.data; return resp.data;
...@@ -81,7 +82,7 @@ class YysService extends Service { ...@@ -81,7 +82,7 @@ class YysService extends Service {
orderSn: orderSn, orderSn: orderSn,
} }
let url = this.config.NODE_BASE_URL + '/yys_api/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', timeout: 30000 });
ctx.logger.info(JSON.stringify({ yys_query_params: params, yys_query_result: resp })); ctx.logger.info(JSON.stringify({ yys_query_params: params, yys_query_result: resp }));
await this.addCreditLogYys(orderSn, '/yys_api/query', params, resp.data); await this.addCreditLogYys(orderSn, '/yys_api/query', params, resp.data);
return resp.data; return resp.data;
...@@ -106,7 +107,7 @@ class YysService extends Service { ...@@ -106,7 +107,7 @@ class YysService extends Service {
} }
params.sign = await ctx.service.credit.common.sign(params.signParams, this.config.YYS_REPORT_APPSECRET); params.sign = await ctx.service.credit.common.sign(params.signParams, this.config.YYS_REPORT_APPSECRET);
const url = this.config.YYS_REPORT_URL; const url = this.config.YYS_REPORT_URL;
const result = await ctx.helper.send_request(url, params, { method: 'POST' }); const result = await ctx.helper.send_request(url, params, { method: 'POST', timeout: 30000 });
ctx.logger.info(JSON.stringify({ thxdReport_parmas: params, thxdReport_result: result })); ctx.logger.info(JSON.stringify({ thxdReport_parmas: params, thxdReport_result: result }));
return result.data; return result.data;
......
'use strict';
const Service = require('egg').Service;
class WechatService extends Service {
async oauthLogin() {
const { ctx } = this;
const result = {};
ctx.success(result);
}
}
module.exports = WechatService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
const _ = require('lodash');
class AbroadHouseService extends Service {
/**
* 海外房列表
*/
async abroadHouseList(condition) {
const { ctx } = this;
let page = Number(condition.page) || 1;
let pageSize = Number(condition.page_size) || 10;
let filter = {
page: page,
limit: pageSize,
where: {
valid: 1,
status: 'online',
},
order: [['order', 'asc']]
}
if (condition.name) {//关键词搜索 模糊查询
//增加搜索历史
let addHistory = {
type: 4,
key_word: condition.name
};
await ctx.service.house.v2.searchHistory.addSearchHistory(addHistory);
filter.where.name = { $like: '%' + condition.name + '%' }
}
let abroadList = await ctx.realestateModel.AbroadHouse.list(filter);
let list = abroadList.rows;
let data = [];
for (let i in list) {
data[i] = {
id: list[i].id,
name: list[i].name || '',
images: list[i].images ? JSON.parse(list[i].images) : [],
tags: list[i].tags ? JSON.parse(list[i].tags) : [],
total_price: list[i].total_price === '0.00' ? '--' : list[i].total_price,
url: list[i].url || '',
}
}
let ret = {
results: data,
count: abroadList.count
};
return ret;
}
}
module.exports = AbroadHouseService;
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
'use strict'; 'use strict';
const Service = require('egg').Service; const Service = require('egg').Service;
const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
const ConfigType = {
1: 'new_house',
2: 'rental_house',
4: 'abroad_house',
}
class FootPrintService extends Service { class FootPrintService extends Service {
...@@ -29,8 +35,7 @@ class FootPrintService extends Service { ...@@ -29,8 +35,7 @@ class FootPrintService extends Service {
state: 1, state: 1,
remark: inputParams.remark || '', remark: inputParams.remark || '',
} }
let ret = await ctx.realestateModel.FootPrint.add(data); let ret = await ctx.realestateModel.FootPrint.create(data);
return { id: ret.id }; return { id: ret.id };
} }
...@@ -57,7 +62,6 @@ class FootPrintService extends Service { ...@@ -57,7 +62,6 @@ class FootPrintService extends Service {
limit: 50, limit: 50,
where: { where: {
user_id: user_id, user_id: user_id,
// app_type_id: app_type_id,
state: 1, state: 1,
created_at: { $gt: endDate }, created_at: { $gt: endDate },
}, },
...@@ -69,10 +73,13 @@ class FootPrintService extends Service { ...@@ -69,10 +73,13 @@ class FootPrintService extends Service {
for (let i in foot_prints) { for (let i in foot_prints) {
let foot_print = foot_prints[i]; let foot_print = foot_prints[i];
if (foot_print.house_style === 1) {//获取房源信息 if (foot_print.house_style === 1) {//获取房源信息
p_houses[i] = ctx.realestateModel.NewHouse.one({ where: { id: foot_print.connect_id } }); p_houses[i] = ctx.realestateModel.NewHouse.one({ attributes: ['id', 'name', 'status', 'valid'], where: { id: foot_print.connect_id } });
} else if (foot_print.house_style === 2) { } else if (foot_print.house_style === 2) {
p_houses[i] = ctx.realestateModel.RentalHouse.one({ where: { id: foot_print.connect_id } }); p_houses[i] = ctx.realestateModel.RentalHouse.one({ attributes: ['id', 'name', 'status', 'valid'], where: { id: foot_print.connect_id } });
} else if (foot_print.house_style === 4) {
p_houses[i] = ctx.realestateModel.AbroadHouse.findOne({ attributes: ['id', 'name', 'url', 'status', 'valid'], where: { id: foot_print.connect_id } });
} }
} }
const houses = await Promise.all(p_houses).then(result => {//等待所有异步内容获取完成 const houses = await Promise.all(p_houses).then(result => {//等待所有异步内容获取完成
return result; return result;
...@@ -84,12 +91,12 @@ class FootPrintService extends Service { ...@@ -84,12 +91,12 @@ class FootPrintService extends Service {
//处理足迹数据 //处理足迹数据
const foot_print_records = []; const foot_print_records = [];
for (let j in houses) { for (let j in houses) {
if (houses[j].status === 'offline' || Number(houses[j].valid) === 0) { if (houses[j] === null || houses[j].status === 'offline' || Number(houses[j].valid) === 0) {
continue; continue;
} }
const house = houses[j]; const house = houses[j];
const foot_print = foot_prints[j]; const foot_print = foot_prints[j];
const type = foot_print.house_style === 1 ? 'new_house' : 'rental_house'; const type = ConfigType[foot_print.house_style];
const create_time = moment(foot_print.created_at).format('X'); const create_time = moment(foot_print.created_at).format('X');
let time = moment(foot_print.created_at).format('YYYY-MM-DD'); let time = moment(foot_print.created_at).format('YYYY-MM-DD');
const du_time = now_time - create_time; const du_time = now_time - create_time;
...@@ -105,10 +112,11 @@ class FootPrintService extends Service { ...@@ -105,10 +112,11 @@ class FootPrintService extends Service {
name: house.name, name: house.name,
time: time, time: time,
type: type, type: type,
url: type === 'abroad_house' ? house.url : '',
}); });
} }
return { results: foot_print_records, count: foot_prints_rows.count }; return { results: foot_print_records, count: foot_print_records.length };
} }
...@@ -122,7 +130,6 @@ class FootPrintService extends Service { ...@@ -122,7 +130,6 @@ class FootPrintService extends Service {
} }
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss'); let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
const filter = { const filter = {
page: 1,
limit: 50, limit: 50,
attributes: ['connect_id', 'house_style'], attributes: ['connect_id', 'house_style'],
where: { where: {
...@@ -135,29 +142,55 @@ class FootPrintService extends Service { ...@@ -135,29 +142,55 @@ class FootPrintService extends Service {
const list = await ctx.realestateModel.FootPrint.findAll(filter); const list = await ctx.realestateModel.FootPrint.findAll(filter);
let count = 0; let count = 0;
if (list.length > 0) { if (list.length > 0) {
let taskList = []; let newIds = [];
let rentalIds = [];
let abroadIds = [];
for (let i in list) { for (let i in list) {
let taskFilter = {
attributes: ['id'],
where: {
status: 'online',
valid: 1,
id: list[i].connect_id
}
}
if (Number(list[i].house_style) === 1) { if (Number(list[i].house_style) === 1) {
taskList[i] = ctx.realestateModel.NewHouse.one(taskFilter); newIds.push(list[i].connect_id);
} }
if (Number(list[i].house_style) === 2) { if (Number(list[i].house_style) === 2) {
taskList[i] = ctx.realestateModel.RentalHouse.one(taskFilter); rentalIds.push(list[i].connect_id);
}
if (Number(list[i].house_style) === 4) {
abroadIds.push(list[i].connect_id);
} }
} }
let newTaskFilter = {
attributes: ['id'], where: { status: 'online', valid: 1, id: { $in: newIds } }
}
let rentalTaskFilter = {
attributes: ['id'], where: { status: 'online', valid: 1, id: { $in: rentalIds } }
}
let abroadTaskFilter = {
attributes: ['id'], where: { status: 'online', valid: 1, id: { $in: abroadIds } }
}
let taskList = [
ctx.realestateModel.NewHouse.findAll(newTaskFilter),
ctx.realestateModel.RentalHouse.findAll(rentalTaskFilter),
ctx.realestateModel.AbroadHouse.findAll(abroadTaskFilter),
];
const retList = await Promise.all(taskList).then(result => { const retList = await Promise.all(taskList).then(result => {
return result; return result;
}).catch(error => { }).catch(error => {
ctx.failed(error); ctx.failed(error);
}); });
count = Number(retList.length);
let validNewIds = _.map(retList[0], 'id');
let validRentalIds = _.map(retList[1], 'id');
let validAbroadIds = _.map(retList[2], 'id');
for (let i in list) {
if (Number(list[i].house_style) === 1 && validNewIds.includes(Number(list[i].connect_id))) {
count++;
}
if (Number(list[i].house_style) === 2 && validRentalIds.includes(Number(list[i].connect_id))) {
count++;
}
if (Number(list[i].house_style) === 4 && validAbroadIds.includes(Number(list[i].connect_id))) {
count++;
}
}
} }
let ret = { let ret = {
count: count count: count
......
...@@ -194,8 +194,8 @@ class NewHouseService extends Service { ...@@ -194,8 +194,8 @@ class NewHouseService extends Service {
description: data.description || '',//描述 description: data.description || '',//描述
tags: data.tags ? eval(data.tags) : [],//项目特色 tags: data.tags ? eval(data.tags) : [],//项目特色
favourable_info: data.favourable_info || '',//优惠 favourable_info: data.favourable_info || '',//优惠
reference_avg_price: data.reference_avg_price === 0 ? '--' : Number(data.reference_avg_price),//均价 reference_avg_price: Number(data.reference_avg_price) === 0 ? '--' : Number(data.reference_avg_price),//均价
reference_total_price: data.reference_total_price === 0 ? '--' : Number(data.reference_total_price),//总价 reference_total_price: Number(data.reference_total_price) === 0 ? '--' : Number(data.reference_total_price),//总价
property_type: data.house_type.split(',').slice(0, 2),//物业类型 property_type: data.house_type.split(',').slice(0, 2),//物业类型
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
'use strict'; 'use strict';
const Service = require('egg').Service; const Service = require('egg').Service;
const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
class searchHistoryService extends Service { class searchHistoryService extends Service {
...@@ -50,7 +51,9 @@ class searchHistoryService extends Service { ...@@ -50,7 +51,9 @@ class searchHistoryService extends Service {
} }
}; };
//不管有没有登录获取城市相关的热门搜索 //不管有没有登录获取城市相关的热门搜索
ret.hot_search.results = await ctx.service.house.v2.hotSearch.getHotSearch(condition); if (condition.type && [1, 2].includes(condition.type)) {
ret.hot_search.results = await ctx.service.house.v2.hotSearch.getHotSearch(condition);
}
if (!ctx.appUserId || !ctx.userId) { if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就返回 //如果没有登录就返回
...@@ -124,14 +127,7 @@ class searchHistoryService extends Service { ...@@ -124,14 +127,7 @@ class searchHistoryService extends Service {
order: [['created_at', 'desc']], order: [['created_at', 'desc']],
} }
let searchHistoryList = await ctx.realestateModel.SearchHistory.findAll(filter); let searchHistoryList = await ctx.realestateModel.SearchHistory.findAll(filter);
let list = []; let list = _.uniq(_.map(searchHistoryList, 'key_word'));
if (searchHistoryList.length > 0) {
for (let i in searchHistoryList) {
if (list.indexOf(searchHistoryList[i].key_word) === -1) {
list.push(searchHistoryList[i].key_word);
}
}
}
ret = { ret = {
results: list, results: list,
count: list.length count: list.length
......
...@@ -90,7 +90,7 @@ module.exports = appInfo => { ...@@ -90,7 +90,7 @@ module.exports = appInfo => {
// other sequelize configurations // other sequelize configurations
dialect: 'mysql', dialect: 'mysql',
host: 'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com', host: 'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com',
database: 'prometheus_dev', database: 'prometheus_uat',
username: 'prometheus', username: 'prometheus',
password: 'q9t8Ay4qIUW4sw3s25K28', password: 'q9t8Ay4qIUW4sw3s25K28',
port: 3306, port: 3306,
...@@ -103,7 +103,7 @@ module.exports = appInfo => { ...@@ -103,7 +103,7 @@ module.exports = appInfo => {
// other sequelize configurations // other sequelize configurations
dialect: 'mysql', dialect: 'mysql',
host: 'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com', host: 'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com',
database: 'class_dev', database: 'class_uat',
username: 'class_testing', username: 'class_testing',
password: 'WV862L32451I6KD58tU9K', password: 'WV862L32451I6KD58tU9K',
port: 3306, port: 3306,
...@@ -139,8 +139,8 @@ module.exports = appInfo => { ...@@ -139,8 +139,8 @@ module.exports = appInfo => {
}; };
config.PHP_URL = 'https://kaifa.jianbing.com'; config.PHP_URL = 'https://kaifa.jianbing.com';
config.NODE_URL = 'https://uat-nginx.jianbing.com/user_api/v1'; config.NODE_URL = 'https://dev-nginx.jianbing.com/user_api/v1';
config.NODE_BASE_URL = 'https://uat-nginx.jianbing.com'; config.NODE_BASE_URL = 'https://dev-nginx.jianbing.com';
config.HOUSE_SERVICE_API = 'https://uat-nginx.jianbing.com/house-service'; config.HOUSE_SERVICE_API = 'https://uat-nginx.jianbing.com/house-service';
config.CDN_BASE_URL = 'https://r.51gjj.com/image/'; config.CDN_BASE_URL = 'https://r.51gjj.com/image/';
......
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