Commit 6229da14 authored by 任国军's avatar 任国军
parents 202b066b d65e6c79
...@@ -15,9 +15,11 @@ class HomeController extends Controller { ...@@ -15,9 +15,11 @@ class HomeController extends Controller {
async test() { async test() {
const { ctx } = this; const { ctx } = this;
const stream1 = await ctx.getFileStream(); 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); // await pump(stream, writeStream);
ctx.success(stream1); ctx.success(yys_report_data);
} }
} }
......
'use strict'; 'use strict';
const Controller = require('egg').Controller; 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 = '';
const WECHAT_SECRET = '';
const NO_GJJ_PAGE = 'https://www.baidu.com';
const GJJ_DETAIL_PAGE = 'https:www.jianbing.com';
class WechatController extends Controller { class WechatController extends Controller {
async oauthLogin() { async oauthLogin() {
const { ctx } = this; const { ctx } = this;
const result = {}; const code = ctx.query.code;
ctx.success(result); const channel_id = ctx.query.channel_id;
if (!code || code.length === 0) {
const target_url = WECHAT_CODE_URL + `?appid=${WECHAT_APPID}&redirect_uri=${encodeURIComponent(`https://p.jianbing.com/51ucenter/api/user/oauth?&channel_id=${channel_id}`)}&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`;
ctx.redirect(target_url);
}
const url = `${WECHAT_AUTH}?appid=${WECHAT_APPID}&secret=${WECHAT_SECRET}&code=${code}&grant_type=authorization_code`
const result = await ctx.helper.send_request(url, {}, { method: 'GET' });
if (result.status !== 200) {
ctx.failed('获取openid失败');
}
const wx_ret = result.data;
if (!wx_ret.openid) {
ctx.failed('获取openid失败');
}
const openid = wx_ret.openid;
//判断是否已绑定手机号
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, {}, { method: 'GET' });
if (bind_phone_result.status !== 200) {
ctx.redirect(NO_GJJ_PAGE); return;
}
const user_exist_ret = bind_phone_result.data;
if (user_exist_ret.result != 'true') {//未绑定的手机号时
ctx.redirect(NO_GJJ_PAGE); return;
}
const user_id = user_exist_ret.uid;
//判断是否有导入公积金
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' });
if (gjj_exist_result.status !== 200) {
ctx.redirect(NO_GJJ_PAGE); return;
}
const gjj_exist_ret = gjj_exist_result.data;
if (!gjj_exist_ret.ret || gjj_exist_ret.ret.length === 0) {//没有导入公积金时
ctx.redirect(NO_GJJ_PAGE); return;
}
await this.user_login({ code, openid, channel_id });//用户直接登录
ctx.redirect(GJJ_DETAIL_PAGE); return;
} }
async checkLogin() { async checkLogin() {
...@@ -20,9 +65,94 @@ class WechatController extends Controller { ...@@ -20,9 +65,94 @@ class WechatController extends Controller {
if (user_id) { if (user_id) {
is_login = true; is_login = true;
} }
const phone = await ctx.helper.getPhoneCity('15968762898');
ctx.success({ result: is_login }); ctx.success({ result: is_login, phone });
} }
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.poseidonModel.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: input_params.app_user_id || '',//app用户ID token登陆时传的参数 可空
code: code || '',//第三方授权登录时的code 可空
device_info: {},//设备信息
openid: openid || '' //例如微信公众号的appid(不传默认是51查个税)
};
const result_user_login = await ctx.helper.send_request(this.config.NODE_URL + '/login/user', user_login_params, { method: 'POST' });//用户登录
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; module.exports = WechatController;
...@@ -5,12 +5,14 @@ const Controller = require('egg').Controller; ...@@ -5,12 +5,14 @@ const Controller = require('egg').Controller;
class AbroadHouseController extends Controller { class AbroadHouseController extends Controller {
/** /**
* 获取海外房列表 * 海外房列表
*/ */
async list() { async list() {
const { ctx } = this; const { ctx } = this;
let inputParams = ctx.request.body; let inputParams = ctx.request.body;
const rule = { const rule = {
page: { type: 'int', required: false },
page_size: { type: 'int', required: false },
name: { type: 'string', required: false }, name: { type: 'string', required: false },
}; };
ctx.validate(rule, inputParams); ctx.validate(rule, inputParams);
......
...@@ -44,6 +44,7 @@ class searchHistoryController extends Controller { ...@@ -44,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: {
......
...@@ -70,6 +70,66 @@ module.exports = app => { ...@@ -70,6 +70,66 @@ module.exports = app => {
tableName: 'abroad_house', 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; return AbroadHouse;
......
...@@ -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');//首页
//我的信用-黑名单报告 //我的信用-黑名单报告
......
...@@ -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'],
......
...@@ -71,7 +71,7 @@ class CallriskService extends Service { ...@@ -71,7 +71,7 @@ class CallriskService extends Service {
const { ctx } = this; const { ctx } = this;
let 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');
} }
......
...@@ -12,7 +12,11 @@ class AbroadHouseService extends Service { ...@@ -12,7 +12,11 @@ class AbroadHouseService extends Service {
*/ */
async abroadHouseList(condition) { async abroadHouseList(condition) {
const { ctx } = this; const { ctx } = this;
let page = Number(condition.page) || 1;
let pageSize = Number(condition.page_size) || 10;
let filter = { let filter = {
page: page,
limit: pageSize,
where: { where: {
valid: 1, valid: 1,
status: 'online', status: 'online',
...@@ -28,7 +32,8 @@ class AbroadHouseService extends Service { ...@@ -28,7 +32,8 @@ class AbroadHouseService extends Service {
await ctx.service.house.v2.searchHistory.addSearchHistory(addHistory); await ctx.service.house.v2.searchHistory.addSearchHistory(addHistory);
filter.where.name = { $like: '%' + condition.name + '%' } filter.where.name = { $like: '%' + condition.name + '%' }
} }
let list = await ctx.realestateModel.AbroadHouse.findAll(filter); let abroadList = await ctx.realestateModel.AbroadHouse.list(filter);
let list = abroadList.rows;
let data = []; let data = [];
for (let i in list) { for (let i in list) {
data[i] = { data[i] = {
...@@ -42,7 +47,7 @@ class AbroadHouseService extends Service { ...@@ -42,7 +47,7 @@ class AbroadHouseService extends Service {
} }
let ret = { let ret = {
results: data, results: data,
count: data.length count: abroadList.count
}; };
return ret; return ret;
} }
......
...@@ -91,7 +91,7 @@ class FootPrintService extends Service { ...@@ -91,7 +91,7 @@ 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];
......
...@@ -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,
......
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