Commit ccaa41c6 authored by 任国军's avatar 任国军

add loan_home recommend

parent beb64607
...@@ -30,5 +30,13 @@ class ProductController extends Controller { ...@@ -30,5 +30,13 @@ class ProductController extends Controller {
ctx.success({ results, credit_loans, common_loans, common_credits, credit_cards }); ctx.success({ results, credit_loans, common_loans, common_credits, credit_cards });
} }
// 贷款频道首页热门推荐
async getLoanHomeRecommendList() {
const { ctx } = this;
const ret = await ctx.service.gjj.product.getLoanHomeList();
ctx.success({ results: ret, count: ret.length });
}
} }
module.exports = ProductController; module.exports = ProductController;
...@@ -4,6 +4,7 @@ module.exports = app => { ...@@ -4,6 +4,7 @@ module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/product'); const router = app.router.namespace(app.config.projectRootPath + '/product');
router.get('third_options', '/recommend/channel/options/:type', 'gjj.product.getOptionProducts');// router.get('third_options', '/recommend/channel/options/:type', 'gjj.product.getOptionProducts');// 筛选项
router.get('third_options', '/recommend/channel/home', 'gjj.product.getLoanHomeRecommendList'); // 贷款频道首页
}; };
...@@ -88,7 +88,7 @@ class ProductService extends Service { ...@@ -88,7 +88,7 @@ class ProductService extends Service {
children.push({ children.push({
id: -3, id: -3,
title: '最适合您的', title: '最适合您的',
quality: [ 7, 8, 29 ], // TODO quality: await this.getSuitLoans(),
normal: [], normal: [],
}); });
...@@ -117,30 +117,37 @@ class ProductService extends Service { ...@@ -117,30 +117,37 @@ class ProductService extends Service {
const { ctx } = this; const { ctx } = this;
const url = this.config.NODE_BASE_URL + '/cassandra-server/bu_basic/list?type=' + type; const url = this.config.NODE_BASE_URL + '/cassandra-server/bu_basic/list?type=' + type;
const products_results = await ctx.helper.send_request(url, {}, { method: 'GET' }); const products_results = await ctx.helper.send_request(url, {}, { method: 'GET' });
//ctx.logger.info(JSON.stringify({ url, products_results })); // ctx.logger.info(JSON.stringify({ url, products_results }));
if (type !== 1) {
console.log(products_results.data.ret);
}
let products = []; let products = [];
if (products_results.status !== 200 || !products_results.data || !products_results.data.ret) { if (products_results.status !== 200 || !products_results.data || !products_results.data.ret) {
return products; return products;
} }
products = products_results.data.ret; products = await this.formatProducts(products_results.data.ret);
return products; return products;
} }
// 最适合您的(推荐)贷款 // 最适合您的(推荐)贷款
async getSuitLoans() { async getSuitLoans() {
const ret = await this.getBusinessRecommendList(); const ret = await this.getBusinessRecommendList(9999);
return ret;
}
// 贷款频道首页热门推荐
async getLoanHomeList() {
let ret = await this.getBusinessRecommendList(6, 'home');
if (ret.length < 6) {
const creditLoan = R.take(6 - ret.length)(await this.getAllProductsByType(1));
ret = R.insertAll(ret.length, creditLoan)(ret);
}
return ret; return ret;
} }
// 获取用户贷款分组 // 获取用户贷款分组
async getBusinessClassList() { async getBusinessClassList() {
const { ctx } = this; const { ctx } = this;
const userId = '58f1af6b-9018-4d69-b839-a26aaa368445'; const userId = ctx.userId;
const appUserId = '9CEB848A-2F87-4C5F-A50A-D65882C04CA6'; const appUserId = ctx.appUserId;
const url = ctx.app.config.NODE_BASE_URL + '/cassandra-server/loan_list/bu_class/list'; const url = ctx.app.config.NODE_BASE_URL + '/cassandra-server/loan_list/bu_class/list';
const param = { uid: userId, app_uid: appUserId }; const param = { uid: userId, app_uid: appUserId };
const resp = await ctx.helper.send_request(url, param, { method: 'GET' }); const resp = await ctx.helper.send_request(url, param, { method: 'GET' });
...@@ -153,8 +160,8 @@ class ProductService extends Service { ...@@ -153,8 +160,8 @@ class ProductService extends Service {
// 获取用户贷款通过率 // 获取用户贷款通过率
async getBusinessPassRate(businessList) { async getBusinessPassRate(businessList) {
const { ctx } = this; const { ctx } = this;
const userId = '58f1af6b-9018-4d69-b839-a26aaa368445'; const userId = ctx.userId;
const appUserId = '9CEB848A-2F87-4C5F-A50A-D65882C04CA6'; const appUserId = ctx.appUserId;
const url = ctx.app.config.NODE_BASE_URL + '/cassandra-server/loan_list/recommend_sort/list'; const url = ctx.app.config.NODE_BASE_URL + '/cassandra-server/loan_list/recommend_sort/list';
const param = { uid: userId, app_uid: appUserId, business_arr: businessList }; const param = { uid: userId, app_uid: appUserId, business_arr: businessList };
...@@ -185,11 +192,10 @@ class ProductService extends Service { ...@@ -185,11 +192,10 @@ class ProductService extends Service {
} }
// 获取推荐列表,按照ABC分组顺序推荐 // 获取推荐列表,按照ABC分组顺序推荐
async getBusinessRecommendList() { async getBusinessRecommendList(limit, location = 'list') {
const { ctx, service } = this; const { ctx, service } = this;
const userId = ctx.userId; const userId = ctx.userId;
const R = require('ramda'); const R = require('ramda');
const limit = 10;
const recommendSort = function(a, b) { const recommendSort = function(a, b) {
return a.recommend_sorter - b.recommend_sorter; return a.recommend_sorter - b.recommend_sorter;
}; };
...@@ -226,7 +232,10 @@ class ProductService extends Service { ...@@ -226,7 +232,10 @@ class ProductService extends Service {
// 判断C组是否有值 // 判断C组是否有值
if (classList.hasOwnProperty('class_C') && !ctx.isEmpty(classList.class_C)) { if (classList.hasOwnProperty('class_C') && !ctx.isEmpty(classList.class_C)) {
// 获取开关状态,判断是自动推荐or手动推荐orABTest // 获取开关状态,判断是自动推荐or手动推荐orABTest
const rule = 1; const keyword = location === 'list' ? 'config_list_smart_recommend' : 'config_loan_smart_recommend';
const ruleSetting = await this.app.huodongModel.Setting.findOne({ where: { keyword } });
const rule = Number(ruleSetting.value);
console.log('rule: ' + String(rule));
// 是否需要计算模型 // 是否需要计算模型
let isNeedCalc = false; let isNeedCalc = false;
let userInfo = {}; let userInfo = {};
...@@ -265,7 +274,7 @@ class ProductService extends Service { ...@@ -265,7 +274,7 @@ class ProductService extends Service {
break; break;
} }
if (isNeedCalc) { if (isNeedCalc || rule) {
const businessArr = R.pluck('business_id')(classList.class_C); const businessArr = R.pluck('business_id')(classList.class_C);
const passRateList = await this.getBusinessPassRate(businessArr); const passRateList = await this.getBusinessPassRate(businessArr);
if (!ctx.isEmpty(passRateList)) { if (!ctx.isEmpty(passRateList)) {
...@@ -357,10 +366,13 @@ class ProductService extends Service { ...@@ -357,10 +366,13 @@ class ProductService extends Service {
} }
async formatProducts(products) { async formatProducts(products) {
const { ctx } = this;
const ret = []; const ret = [];
const channel = ctx.channel;
for (const v of products) { for (const v of products) {
const rate = v.rate.includes('元') ? v.rate : v.rate + '%'; const channels = ctx.isEmpty(v.channel_rate_id) ? [] : v.channel_rate_id.split(',');
const channel_rate = v.channel_rate.includes('元') ? v.channel_rate : v.channel_rate + '%'; const rate = channels.includes(channel) ? (v.channel_rate.includes('元') ? v.channel_rate : v.channel_rate + '%') : (v.rate.includes('元') ? v.rate : v.rate + '%');
const rateTitle = channels.includes(channel) ? v.channel_rate_title : v.rate_title;
let url = v.url; let url = v.url;
if (Number(v.type) === 4) { if (Number(v.type) === 4) {
url = url.includes('?') ? url + '&from=51gjj_loan_channel' : url + '?from=51gjj_loan_channel'; url = url.includes('?') ? url + '&from=51gjj_loan_channel' : url + '?from=51gjj_loan_channel';
...@@ -372,8 +384,8 @@ class ProductService extends Service { ...@@ -372,8 +384,8 @@ class ProductService extends Service {
name: v.name, name: v.name,
logo: v.logo, logo: v.logo,
alias: v.alias, alias: v.alias,
rate_title: v.rate_title, rate_title: rateTitle,
rate: v.rate, rate,
min_amount: v.min_amount, min_amount: v.min_amount,
max_amount: v.max_amount, max_amount: v.max_amount,
sort: v.recommend_sorter, sort: v.recommend_sorter,
......
...@@ -66,6 +66,19 @@ module.exports = appInfo => { ...@@ -66,6 +66,19 @@ module.exports = appInfo => {
password: 'ppD1sDSutHG83T2s1Ue3k', password: 'ppD1sDSutHG83T2s1Ue3k',
port: 3306, port: 3306,
}, },
{
// 东八时区
timezone: '+08:00',
delegate: 'huodongModel',
baseDir: 'model/huodong',
// other sequelize configurations
dialect: 'mysql',
host: 'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com',
database: 'devhuodong',
username: 'devhuodong',
password: 'jianbing2014GG',
port: 3306,
},
], ],
}; };
...@@ -90,13 +103,13 @@ module.exports = appInfo => { ...@@ -90,13 +103,13 @@ 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/';
config.USER_CENTER_API_URI = 'https://uat-nginx.jianbing.com/usercenter-service'; config.USER_CENTER_API_URI = 'https://dev-nginx.jianbing.com/usercenter-service';
return config; return config;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment