Commit 840217e4 authored by 肖爱江's avatar 肖爱江

嗨钱包处理

parent 37f590af
Pipeline #31185 passed with stage
...@@ -14,3 +14,4 @@ typings/ ...@@ -14,3 +14,4 @@ typings/
.nyc_output/ .nyc_output/
.travis.yml .travis.yml
appveyor.yml appveyor.yml
.vscode
\ No newline at end of file
'use strict'; "use strict";
const Service = require('egg').Service; const Service = require("egg").Service;
const R = require('ramda'); const R = require("ramda");
const moment = require('moment'); const moment = require("moment");
class ProductService extends Service { class ProductService extends Service {
// 通过 type=loan/credit 频道 option_ids 筛选项数组 all_product_ids // 通过 type=loan/credit 频道 option_ids 筛选项数组 all_product_ids
// async getProductsByOptions(option_ids, all_product_ids = []) { // async getProductsByOptions(option_ids, all_product_ids = []) {
...@@ -28,34 +26,56 @@ class ProductService extends Service { ...@@ -28,34 +26,56 @@ class ProductService extends Service {
// 获取筛选项列表 带 product_id // 获取筛选项列表 带 product_id
// return : [{"id":3,"title":"银行分类","description":"信用卡银行分类","_children":[{"id":12,"title":"招商银行","quality":["1"],"normal":["1"]},{"id":16,"title":"广发银行","quality":[],"normal":[]}]},{"id":4,"title":"主题分类","description":"信用卡主题分类","_children":[]},{"id":5,"title":"信用卡筛选项","description":"信用卡筛选项","_children":[]}] // return : [{"id":3,"title":"银行分类","description":"信用卡银行分类","_children":[{"id":12,"title":"招商银行","quality":["1"],"normal":["1"]},{"id":16,"title":"广发银行","quality":[],"normal":[]}]},{"id":4,"title":"主题分类","description":"信用卡主题分类","_children":[]},{"id":5,"title":"信用卡筛选项","description":"信用卡筛选项","_children":[]}]
async getRecommendOptions(type = 'credit', keys = []) { async getRecommendOptions(type = "credit", keys = []) {
const { ctx } = this; const { ctx } = this;
// const type = 'credit'; // const type = 'credit';
// keys = ['loan_organization', 'loan_filter', 'credit_bank', 'credit_theme', 'credit_filter']; // keys = ['loan_organization', 'loan_filter', 'credit_bank', 'credit_theme', 'credit_filter'];
// console.info(keys); // console.info(keys);
let classifies = await ctx.blockModel.RecommendChannelClassify.findAll({ where: { type, valid: 1, key: { $in: keys } }, order: [['sort', 'asc']] }); let classifies = await ctx.blockModel.RecommendChannelClassify.findAll({
where: { type, valid: 1, key: { $in: keys } },
order: [["sort", "asc"]],
});
// return classifies; // return classifies;
classifies = R.project(['id', 'key', 'title', 'description'])(classifies); classifies = R.project(["id", "key", "title", "description"])(classifies);
const classify_ids = R.pluck('id', classifies); const classify_ids = R.pluck("id", classifies);
let options = await ctx.blockModel.RecommendChannelOption.all({ where: { classify_id: { $in: classify_ids }, status: 'online', valid: 1 }, order: [['order', 'asc']] }); let options = await ctx.blockModel.RecommendChannelOption.all({
options = R.project(['id', 'title', 'classify_id'])(options); where: { classify_id: { $in: classify_ids }, status: "online", valid: 1 },
const option_ids = R.pluck('id', options); order: [["order", "asc"]],
let option_products = await ctx.blockModel.RecommendChannelProduct.all({ where: { option_id: { $in: option_ids }, valid: 1 }, order: [['order', 'asc']] }); });
option_products = R.project(['option_id', 'product_id', 'type'])(option_products); options = R.project(["id", "title", "classify_id"])(options);
const option_ids = R.pluck("id", options);
let option_products = await ctx.blockModel.RecommendChannelProduct.all({
where: { option_id: { $in: option_ids }, valid: 1 },
order: [["order", "asc"]],
});
option_products = R.project(["option_id", "product_id", "type"])(
option_products
);
const ret = []; const ret = [];
for (const i in classifies) { for (const i in classifies) {
const classify = classifies[i]; const classify = classifies[i];
const classify_id = classify.id; const classify_id = classify.id;
let temp_options = options.filter(option => parseInt(option.classify_id) === parseInt(classify_id)); let temp_options = options.filter(
temp_options = R.project(['id', 'title'])(temp_options); (option) => parseInt(option.classify_id) === parseInt(classify_id)
);
temp_options = R.project(["id", "title"])(temp_options);
for (const j in temp_options) { for (const j in temp_options) {
const temp_option = temp_options[j]; const temp_option = temp_options[j];
const temp_option_id = temp_option.id; const temp_option_id = temp_option.id;
let temp_option_products = option_products.filter(v => parseInt(v.option_id) === parseInt(temp_option_id)); let temp_option_products = option_products.filter(
temp_option_products = R.groupBy(v => { return v.type === 'quality' ? 'quality' : 'normal'; })(temp_option_products); (v) => parseInt(v.option_id) === parseInt(temp_option_id)
const quality_product_ids = R.pluck('product_id', temp_option_products.quality ? temp_option_products.quality : []); );
const normal_product_ids = R.pluck('product_id', temp_option_products.normal ? temp_option_products.normal : []); temp_option_products = R.groupBy((v) => {
return v.type === "quality" ? "quality" : "normal";
})(temp_option_products);
const quality_product_ids = R.pluck(
"product_id",
temp_option_products.quality ? temp_option_products.quality : []
);
const normal_product_ids = R.pluck(
"product_id",
temp_option_products.normal ? temp_option_products.normal : []
);
temp_options[j].quality = quality_product_ids; temp_options[j].quality = quality_product_ids;
temp_options[j].normal = normal_product_ids; temp_options[j].normal = normal_product_ids;
} }
...@@ -74,35 +94,46 @@ class ProductService extends Service { ...@@ -74,35 +94,46 @@ class ProductService extends Service {
const app_user_id = ctx.appUserId; const app_user_id = ctx.appUserId;
const credit_loans = await this.getAllProductsByType(1); const credit_loans = await this.getAllProductsByType(1);
const common_loans = await this.getAllProductsByType(4); const common_loans = await this.getAllProductsByType(4);
const credit_loans_ids = R.pluck('business_id', credit_loans); const credit_loans_ids = R.pluck("business_id", credit_loans);
const common_loans_ids = R.pluck('business_id', common_loans); const common_loans_ids = R.pluck("business_id", common_loans);
const default_options = { const default_options = {
id: -1, id: -1,
key: 'loan_all', key: "loan_all",
title: '全部', title: "全部",
description: '全部', description: "全部",
_children: [], _children: [],
}; };
const children = [{ id: -2, title: '全部', quality: credit_loans_ids, normal: common_loans_ids }]; const children = [
{
id: -2,
title: "全部",
quality: credit_loans_ids,
normal: common_loans_ids,
},
];
if (app_user_id) { if (app_user_id) {
const userGjj = await ctx.helper.send_request(this.config.NODE_BASE_URL + '/cassandra-server/gjj/list/' + user_id, {}, { method: 'GET' }); const userGjj = await ctx.helper.send_request(
this.config.NODE_BASE_URL + "/cassandra-server/gjj/list/" + user_id,
{},
{ method: "GET" }
);
if (userGjj.status === 200 && !ctx.isEmpty(userGjj.data.ret)) { if (userGjj.status === 200 && !ctx.isEmpty(userGjj.data.ret)) {
children.push({ children.push({
id: -3, id: -3,
title: '最适合您的', title: "最适合您的",
quality: await this.getSuitLoans(), quality: await this.getSuitLoans(),
normal: [], normal: [],
}); });
} else { } else {
children.push({ children.push({
id: -4, id: -4,
title: '51公积金贷', title: "51公积金贷",
quality: credit_loans_ids, quality: credit_loans_ids,
normal: common_loans_ids, normal: common_loans_ids,
}); });
children.push({ children.push({
id: -5, id: -5,
title: '普通贷', title: "普通贷",
quality: [], quality: [],
normal: common_loans_ids, normal: common_loans_ids,
}); });
...@@ -110,13 +141,13 @@ class ProductService extends Service { ...@@ -110,13 +141,13 @@ class ProductService extends Service {
} else { } else {
children.push({ children.push({
id: -4, id: -4,
title: '51公积金贷', title: "51公积金贷",
quality: credit_loans_ids, quality: credit_loans_ids,
normal: common_loans_ids, normal: common_loans_ids,
}); });
children.push({ children.push({
id: -5, id: -5,
title: '普通贷', title: "普通贷",
quality: [], quality: [],
normal: common_loans_ids, normal: common_loans_ids,
}); });
...@@ -128,14 +159,21 @@ class ProductService extends Service { ...@@ -128,14 +159,21 @@ class ProductService extends Service {
// 1 授信贷;2 信用卡;3 普通信用卡;4 普通贷款 // 1 授信贷;2 信用卡;3 普通信用卡;4 普通贷款
async getAllProductsByType(type) { async getAllProductsByType(type) {
const { ctx } = this; const { ctx } = this;
const url = this.config.NODE_BASE_URL + '/cassandra-server/bu_basic/list'; const url = this.config.NODE_BASE_URL + "/cassandra-server/bu_basic/list";
const products_results = await ctx.helper.send_request(url, { type, app_id: ctx.appId }, { method: 'GET' }); const products_results = await ctx.helper.send_request(
url,
{ type, app_id: ctx.appId },
{ method: "GET" }
);
// ctx.logger.info(JSON.stringify({ url, products_results })); // ctx.logger.info(JSON.stringify({ url, products_results }));
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;
} }
...@@ -155,15 +193,17 @@ class ProductService extends Service { ...@@ -155,15 +193,17 @@ class ProductService extends Service {
// 最适合您的(推荐)贷款 // 最适合您的(推荐)贷款
async getSuitLoans() { async getSuitLoans() {
const results = await this.getBusinessRecommendList(9999); const results = await this.getBusinessRecommendList(9999);
const ret = R.pluck('business_id', results); const ret = R.pluck("business_id", results);
return ret; return ret;
} }
// 贷款频道首页热门推荐 // 贷款频道首页热门推荐
async getLoanHomeList() { async getLoanHomeList() {
let ret = await this.getBusinessRecommendList(6, 'home'); let ret = await this.getBusinessRecommendList(6, "home");
if (ret.length < 6) { if (ret.length < 6) {
const creditLoan = R.take(6 - ret.length)(await this.getAllProductsByType(4)); const creditLoan = R.take(6 - ret.length)(
await this.getAllProductsByType(4)
);
ret = R.insertAll(ret.length, creditLoan)(ret); ret = R.insertAll(ret.length, creditLoan)(ret);
} }
return ret; return ret;
...@@ -174,11 +214,13 @@ class ProductService extends Service { ...@@ -174,11 +214,13 @@ class ProductService extends Service {
const { ctx } = this; const { ctx } = this;
const userId = ctx.userId; const userId = ctx.userId;
const appUserId = ctx.appUserId; 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, app_id: ctx.appId }; const param = { uid: userId, app_uid: appUserId, app_id: ctx.appId };
const resp = await ctx.helper.send_request(url, param, { method: 'GET' }); const resp = await ctx.helper.send_request(url, param, { method: "GET" });
if (resp.status !== 200) { if (resp.status !== 200) {
ctx.failed('[bu_class]内部接口错误'); ctx.failed("[bu_class]内部接口错误");
} }
return resp.data.ret; return resp.data.ret;
} }
...@@ -188,17 +230,23 @@ class ProductService extends Service { ...@@ -188,17 +230,23 @@ class ProductService extends Service {
const { ctx } = this; const { ctx } = this;
const userId = ctx.userId; const userId = ctx.userId;
const appUserId = ctx.appUserId; const appUserId = ctx.appUserId;
const url = ctx.app.config.NODE_BASE_URL + '/cassandra-server/loan_list/recommend_sort/list'; const url =
const param = { uid: userId, app_uid: appUserId, business_arr: businessList }; ctx.app.config.NODE_BASE_URL +
"/cassandra-server/loan_list/recommend_sort/list";
const param = {
uid: userId,
app_uid: appUserId,
business_arr: businessList,
};
// 判断列表是否为空 // 判断列表是否为空
if (businessList.length === 0) { if (businessList.length === 0) {
return []; return [];
} }
const resp = await ctx.helper.send_request(url, param, { method: 'POST' }); const resp = await ctx.helper.send_request(url, param, { method: "POST" });
if (resp.status !== 201) { if (resp.status !== 201) {
ctx.failed('[recommend_sort]内部接口错误'); ctx.failed("[recommend_sort]内部接口错误");
} }
return resp.data.ret; return resp.data.ret;
...@@ -211,10 +259,10 @@ class ProductService extends Service { ...@@ -211,10 +259,10 @@ class ProductService extends Service {
} }
// 获取推荐列表,按照ABC分组顺序推荐 // 获取推荐列表,按照ABC分组顺序推荐
async getBusinessRecommendList(limit, location = 'list') { async getBusinessRecommendList(limit, location = "list") {
const { ctx } = this; const { ctx } = this;
const userId = ctx.userId; const userId = ctx.userId;
const R = require('ramda'); const R = require("ramda");
const recommendSort = function (a, b) { const recommendSort = function (a, b) {
if (a.recommend_sorter === b.recommend_sorter) { if (a.recommend_sorter === b.recommend_sorter) {
return b.business_id - a.business_id; return b.business_id - a.business_id;
...@@ -228,7 +276,11 @@ class ProductService extends Service { ...@@ -228,7 +276,11 @@ class ProductService extends Service {
const loanList = await this.getAllProductsByType(1); const loanList = await this.getAllProductsByType(1);
ret = R.take(limit)(loanList); ret = R.take(limit)(loanList);
} else { } else {
const userGjj = await ctx.helper.send_request(this.config.NODE_BASE_URL + '/cassandra-server/gjj/list/' + userId, {}, { method: 'GET' }); const userGjj = await ctx.helper.send_request(
this.config.NODE_BASE_URL + "/cassandra-server/gjj/list/" + userId,
{},
{ method: "GET" }
);
if (userGjj.status !== 200 || ctx.isEmpty(userGjj.data.ret)) { if (userGjj.status !== 200 || ctx.isEmpty(userGjj.data.ret)) {
const loanList = await this.getAllProductsByType(1); const loanList = await this.getAllProductsByType(1);
ret = R.take(limit)(loanList); ret = R.take(limit)(loanList);
...@@ -241,21 +293,26 @@ class ProductService extends Service { ...@@ -241,21 +293,26 @@ class ProductService extends Service {
type: 2, type: 2,
need_smart_recommend: 0, need_smart_recommend: 0,
is_smart_recommend: 0, is_smart_recommend: 0,
pass_rate_list: '', pass_rate_list: "",
business_list: '', business_list: "",
c_class_list: '', c_class_list: "",
common_loan_list: '', common_loan_list: "",
page_type: location === 'list' ? 2 : 1, page_type: location === "list" ? 2 : 1,
is_run_pass_rate: 0, is_run_pass_rate: 0,
created_time: moment().format('YYYY-MM-DD HH:mm:ss'), created_time: moment().format("YYYY-MM-DD HH:mm:ss"),
}; };
// 先获取分组 // 先获取分组
const classList = await this.getBusinessClassList(); const classList = await this.getBusinessClassList();
// 获取开关状态,判断是自动推荐or手动推荐orABTest // 获取开关状态,判断是自动推荐or手动推荐orABTest
const keyword = location === 'list' ? 'config_list_smart_recommend' : 'config_loan_smart_recommend'; const keyword =
const ruleSetting = await this.app.huodongModel.Setting.findOne({ where: { 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); const rule = Number(ruleSetting.value);
// 是否需要计算模型 // 是否需要计算模型
let isNeedCalc = false; let isNeedCalc = false;
...@@ -268,7 +325,7 @@ class ProductService extends Service { ...@@ -268,7 +325,7 @@ class ProductService extends Service {
case 2: case 2:
isNeedCalc = false; isNeedCalc = false;
classList.class_C = R.map(function (e) { classList.class_C = R.map(function (e) {
e.class = 'C'; e.class = "C";
e.rule = rule; e.rule = rule;
e.hasPassRate = 0; e.hasPassRate = 0;
e.needCalc = 0; e.needCalc = 0;
...@@ -279,15 +336,24 @@ class ProductService extends Service { ...@@ -279,15 +336,24 @@ class ProductService extends Service {
// 获取不到手机号则默认使用手动推荐 // 获取不到手机号则默认使用手动推荐
isNeedCalc = false; isNeedCalc = false;
// 获取用户手机号,根据手机号末尾判断是否自动推荐 // 获取用户手机号,根据手机号末尾判断是否自动推荐
userResult = await ctx.helper.send_request(this.config.USER_CENTER_API_URI + '/v1/appusers/' + ctx.appUserId, {}, { userResult = await ctx.helper.send_request(
method: 'GET', this.config.USER_CENTER_API_URI + "/v1/appusers/" + ctx.appUserId,
}); {},
{
method: "GET",
}
);
userInfo = userResult.status === 200 ? userResult.data : {}; userInfo = userResult.status === 200 ? userResult.data : {};
if (!ctx.isEmpty(userInfo) && !ctx.isEmpty(userInfo.user) && !ctx.isEmpty(userInfo.user.phone) && (Number(userInfo.user.phone) % 2 === 0)) { if (
!ctx.isEmpty(userInfo) &&
!ctx.isEmpty(userInfo.user) &&
!ctx.isEmpty(userInfo.user.phone) &&
Number(userInfo.user.phone) % 2 === 0
) {
isNeedCalc = true; isNeedCalc = true;
} else { } else {
classList.class_C = R.map(function (e) { classList.class_C = R.map(function (e) {
e.class = 'C'; e.class = "C";
e.rule = rule; e.rule = rule;
e.hasPassRate = 0; e.hasPassRate = 0;
e.needCalc = 0; e.needCalc = 0;
...@@ -303,19 +369,27 @@ class ProductService extends Service { ...@@ -303,19 +369,27 @@ class ProductService extends Service {
let result = []; let result = [];
// 先取A // 先取A
if (classList.hasOwnProperty('class_A') && !ctx.isEmpty(classList.class_A)) { if (
classList.hasOwnProperty("class_A") &&
!ctx.isEmpty(classList.class_A)
) {
result = R.take(limit)(R.sort(recommendSort)(classList.class_A)); result = R.take(limit)(R.sort(recommendSort)(classList.class_A));
result = R.map(function (e) { result = R.map(function (e) {
e.class = 'A'; e.class = "A";
e.rule = 2; e.rule = 2;
return e; return e;
})(result); })(result);
} }
// 再取B // 再取B
if (classList.hasOwnProperty('class_B') && !ctx.isEmpty(classList.class_B)) { if (
let classB = R.take(limit - result.length)(R.sort(recommendSort)(classList.class_B)); classList.hasOwnProperty("class_B") &&
!ctx.isEmpty(classList.class_B)
) {
let classB = R.take(limit - result.length)(
R.sort(recommendSort)(classList.class_B)
);
classB = R.map(function (e) { classB = R.map(function (e) {
e.class = 'B'; e.class = "B";
e.rule = 2; e.rule = 2;
return e; return e;
})(classB); })(classB);
...@@ -325,24 +399,30 @@ class ProductService extends Service { ...@@ -325,24 +399,30 @@ class ProductService extends Service {
// 如果数量不够,再取C // 如果数量不够,再取C
if (result.length < limit) { if (result.length < limit) {
// 判断C组是否有值 // 判断C组是否有值
if (classList.hasOwnProperty('class_C') && !ctx.isEmpty(classList.class_C)) { if (
classList.hasOwnProperty("class_C") &&
!ctx.isEmpty(classList.class_C)
) {
if (isNeedCalc || rule === 3) { if (isNeedCalc || rule === 3) {
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)) {
classList.class_C = R.map(function (e) { classList.class_C = R.map(function (e) {
e.class = 'C'; e.class = "C";
e.rule = rule; e.rule = rule;
e.hasPassRate = 0; e.hasPassRate = 0;
e.needCalc = (isNeedCalc || (isNeedCalc && rule === 3)) ? 1 : 0; e.needCalc = isNeedCalc || (isNeedCalc && rule === 3) ? 1 : 0;
e.pass_rate = 0; e.pass_rate = 0;
return e; return e;
})(classList.class_C); })(classList.class_C);
for (const v of passRateList) { for (const v of passRateList) {
for (let i = 0; i < classList.class_C.length; i++) { for (let i = 0; i < classList.class_C.length; i++) {
if (Number(classList.class_C[i].business_id) === Number(v.business_id)) { if (
Number(classList.class_C[i].business_id) ===
Number(v.business_id)
) {
classList.class_C[i].pass_rate = v.pass_rate; classList.class_C[i].pass_rate = v.pass_rate;
classList.class_C[i].hasPassRate = 1;// 是否有通过率返回值 classList.class_C[i].hasPassRate = 1; // 是否有通过率返回值
break; break;
} }
} }
...@@ -350,7 +430,9 @@ class ProductService extends Service { ...@@ -350,7 +430,9 @@ class ProductService extends Service {
// 根据通过率降序排序 // 根据通过率降序排序
const passRateSort = function (a, b) { const passRateSort = function (a, b) {
if (a.pass_rate === b.pass_rate) { if (a.pass_rate === b.pass_rate) {
return Number(a.recommend_sorter) - Number(b.recommend_sorter); return (
Number(a.recommend_sorter) - Number(b.recommend_sorter)
);
} }
return b.pass_rate - a.pass_rate; return b.pass_rate - a.pass_rate;
}; };
...@@ -361,34 +443,43 @@ class ProductService extends Service { ...@@ -361,34 +443,43 @@ class ProductService extends Service {
} else { } else {
classList.class_C = R.sort(recommendSort)(classList.class_C); classList.class_C = R.sort(recommendSort)(classList.class_C);
} }
log.c_class_list = R.pluck('business_id')(classList.class_C).join(','); log.c_class_list = R.pluck("business_id")(classList.class_C).join(
","
);
log.is_run_pass_rate = 1; log.is_run_pass_rate = 1;
log.pass_rate_list = JSON.stringify(passRateList); log.pass_rate_list = JSON.stringify(passRateList);
} else { } else {
// 模型计算参数不够,仍然采用手动推荐 // 模型计算参数不够,仍然采用手动推荐
classList.class_C = R.sort(recommendSort)(classList.class_C); classList.class_C = R.sort(recommendSort)(classList.class_C);
classList.class_C = R.map(function (e) { classList.class_C = R.map(function (e) {
e.class = 'C'; e.class = "C";
e.rule = rule; e.rule = rule;
e.hasPassRate = 0; e.hasPassRate = 0;
e.needCalc = (isNeedCalc || (isNeedCalc && rule === 3)) ? 1 : 0; e.needCalc = isNeedCalc || (isNeedCalc && rule === 3) ? 1 : 0;
return e; return e;
})(classList.class_C); })(classList.class_C);
log.c_class_list = R.pluck('business_id')(classList.class_C).join(','); log.c_class_list = R.pluck("business_id")(classList.class_C).join(
","
);
} }
} else { } else {
classList.class_C = R.sort(recommendSort)(classList.class_C); classList.class_C = R.sort(recommendSort)(classList.class_C);
log.c_class_list = R.pluck('business_id')(classList.class_C).join(','); log.c_class_list = R.pluck("business_id")(classList.class_C).join(
","
);
} }
} }
} }
result = R.insertAll(result.length, R.take(limit - result.length)(classList.class_C))(result); result = R.insertAll(
result.length,
R.take(limit - result.length)(classList.class_C)
)(result);
ret = await this.formatLoanList(result); ret = await this.formatLoanList(result);
// 处理log // 处理log
log.need_smart_recommend = isNeedCalc ? 1 : 0; log.need_smart_recommend = isNeedCalc ? 1 : 0;
log.business_list = R.pluck('business_id')(result).join(','); log.business_list = R.pluck("business_id")(result).join(",");
await this.app.huodongModel.LogLoanRecommend.create(log); await this.app.huodongModel.LogLoanRecommend.create(log);
} }
...@@ -396,12 +487,13 @@ class ProductService extends Service { ...@@ -396,12 +487,13 @@ class ProductService extends Service {
} }
async formatLoanList(loanList) { async formatLoanList(loanList) {
// 以下代码是为了处理渠道包下不展示特殊的4个业务 // 以下代码是为了处理渠道包下不展示特殊的4个业务
// start // start
const { ctx } = this; const { ctx } = this;
const channel = ctx.cookies.get('channel', { signed: false }); const channel = ctx.cookies.get("channel", { signed: false });
const user_sid = isNaN(ctx.oldUserId) ? ctx.helper.decodeUserSid(ctx.oldUserId) : ctx.oldUserId; const user_sid = isNaN(ctx.oldUserId)
? ctx.helper.decodeUserSid(ctx.oldUserId)
: ctx.oldUserId;
let filter = { where: { sid: user_sid } }; let filter = { where: { sid: user_sid } };
let userInfo = {}; let userInfo = {};
if (ctx.helper.toInt(user_sid) > 50000000) { if (ctx.helper.toInt(user_sid) > 50000000) {
...@@ -410,13 +502,18 @@ class ProductService extends Service { ...@@ -410,13 +502,18 @@ class ProductService extends Service {
userInfo = await ctx.gjjModel.SysGuest.one(filter); userInfo = await ctx.gjjModel.SysGuest.one(filter);
} }
ctx.logger.info('get_phone_by_user_sid:' + JSON.stringify(userInfo)); ctx.logger.info("get_phone_by_user_sid:" + JSON.stringify(userInfo));
let place_cid = 0; let place_cid = 0;
if (userInfo !== null) { if (userInfo !== null) {
place_cid = userInfo.place_cid; place_cid = userInfo.place_cid;
} else { } else {
let jianbing_guest_customer_id = ctx.cookies.get('jianbing_guest_customer_id', { signed: false }); let jianbing_guest_customer_id = ctx.cookies.get(
jianbing_guest_customer_id = isNaN(jianbing_guest_customer_id) ? ctx.helper.decodeUserSid(jianbing_guest_customer_id) : jianbing_guest_customer_id; "jianbing_guest_customer_id",
{ signed: false }
);
jianbing_guest_customer_id = isNaN(jianbing_guest_customer_id)
? ctx.helper.decodeUserSid(jianbing_guest_customer_id)
: jianbing_guest_customer_id;
filter = { where: { sid: jianbing_guest_customer_id } }; filter = { where: { sid: jianbing_guest_customer_id } };
// const userInfo = await ctx.gjjModel.SysGuest.one(filter); // const userInfo = await ctx.gjjModel.SysGuest.one(filter);
if (ctx.helper.toInt(jianbing_guest_customer_id) > 50000000) { if (ctx.helper.toInt(jianbing_guest_customer_id) > 50000000) {
...@@ -425,18 +522,17 @@ class ProductService extends Service { ...@@ -425,18 +522,17 @@ class ProductService extends Service {
userInfo = await ctx.gjjModel.SysGuest.one(filter); userInfo = await ctx.gjjModel.SysGuest.one(filter);
} }
ctx.logger.info('jianbing_guest_customer_id:' + JSON.stringify(userInfo)); ctx.logger.info("jianbing_guest_customer_id:" + JSON.stringify(userInfo));
if (userInfo !== null) { if (userInfo !== null) {
place_cid = userInfo.place_cid; place_cid = userInfo.place_cid;
} }
} }
if (channel == 'n_1_10000_tencent1') { if (channel == "n_1_10000_tencent1") {
place_cid = 5492; place_cid = 5492;
} else if (channel == 'n_1_10000_51gjjyyb') { } else if (channel == "n_1_10000_51gjjyyb") {
place_cid = 5719; place_cid = 5719;
} }
ctx.logger.info('get_phone_by_user_place:' + place_cid); ctx.logger.info("get_phone_by_user_place:" + place_cid);
// end // end
const ret = []; const ret = [];
...@@ -445,27 +541,43 @@ class ProductService extends Service { ...@@ -445,27 +541,43 @@ class ProductService extends Service {
// start // start
const sepecial_business_ids = [109]; const sepecial_business_ids = [109];
// const place_cids = [ 6046 ]; // const place_cids = [ 6046 ];
const channelList = ['n_1_10000_14038']; const channelList = ["n_1_10000_14038"];
// if (ctx.helper.toInt(place_cid) > 0 && place_cids.includes(ctx.helper.toInt(place_cid)) && sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))) { // if (ctx.helper.toInt(place_cid) > 0 && place_cids.includes(ctx.helper.toInt(place_cid)) && sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))) {
// ctx.logger.info('get_phone_by_user_place_business:' + place_cid + '--business_id--' + v.business_id); // ctx.logger.info('get_phone_by_user_place_business:' + place_cid + '--business_id--' + v.business_id);
// continue; // continue;
// } // }
if (!ctx.isEmpty(channel) && channelList.includes(channel) && sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))) { if (
ctx.logger.info('filter_channel_business: ' + channel + '--business_id--' + v.business_id); !ctx.isEmpty(channel) &&
channelList.includes(channel) &&
sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))
) {
ctx.logger.info(
"filter_channel_business: " +
channel +
"--business_id--" +
v.business_id
);
continue; continue;
} }
// end // end
// 处理C组 // 处理C组
let url = v.url; let url = v.url;
if (v.hasOwnProperty('class')) { if (v.hasOwnProperty("class")) {
if (url.includes('?')) { if (url.includes("?")) {
url = url + '&class=' + v.class + '&rule=' + String(v.rule); url = url + "&class=" + v.class + "&rule=" + String(v.rule);
} else { } else {
url = url + '?class=' + v.class + '&rule=' + String(v.rule); url = url + "?class=" + v.class + "&rule=" + String(v.rule);
} }
if (v.class === 'C') { if (v.class === "C") {
url = url + '&hasPassRate=' + String(v.hasPassRate) + '&needCalc=' + String(v.needCalc) + '&passRate=' + String(v.pass_rate); url =
url +
"&hasPassRate=" +
String(v.hasPassRate) +
"&needCalc=" +
String(v.needCalc) +
"&passRate=" +
String(v.pass_rate);
} }
} }
const tmp = { const tmp = {
...@@ -486,7 +598,7 @@ class ProductService extends Service { ...@@ -486,7 +598,7 @@ class ProductService extends Service {
abridge_desc: v.abridge_desc, abridge_desc: v.abridge_desc,
front_image: v.front_image, front_image: v.front_image,
back_image: v.back_image, back_image: v.back_image,
percent: v.percent ? v.percent : '0', percent: v.percent ? v.percent : "0",
}; };
if (!ctx.isEmpty(v.partner_alias)) { if (!ctx.isEmpty(v.partner_alias)) {
tmp.partner = v.partner_alias; tmp.partner = v.partner_alias;
...@@ -500,13 +612,15 @@ class ProductService extends Service { ...@@ -500,13 +612,15 @@ class ProductService extends Service {
async formatProducts(products, type) { async formatProducts(products, type) {
const { ctx } = this; const { ctx } = this;
const ret = []; const ret = [];
const channel = ctx.cookies.get('channel', { signed: false }); const channel = ctx.cookies.get("channel", { signed: false });
let location = 'loan_channel'; let location = "loan_channel";
let city = ''; let city = "";
// 以下代码是为了处理渠道包下不展示特殊的4个业务 // 以下代码是为了处理渠道包下不展示特殊的4个业务
// start // start
const user_sid = isNaN(ctx.oldUserId) ? ctx.helper.decodeUserSid(ctx.oldUserId) : ctx.oldUserId; const user_sid = isNaN(ctx.oldUserId)
? ctx.helper.decodeUserSid(ctx.oldUserId)
: ctx.oldUserId;
let filter = { where: { sid: user_sid } }; let filter = { where: { sid: user_sid } };
let userInfo = {}; let userInfo = {};
if (ctx.helper.toInt(user_sid) > 500000) { if (ctx.helper.toInt(user_sid) > 500000) {
...@@ -515,13 +629,18 @@ class ProductService extends Service { ...@@ -515,13 +629,18 @@ class ProductService extends Service {
userInfo = await ctx.gjjModel.SysGuest.one(filter); userInfo = await ctx.gjjModel.SysGuest.one(filter);
} }
ctx.logger.info('get_phone_by_user_sid:' + JSON.stringify(userInfo)); ctx.logger.info("get_phone_by_user_sid:" + JSON.stringify(userInfo));
let place_cid = 0; let place_cid = 0;
if (userInfo !== null) { if (userInfo !== null) {
place_cid = userInfo.place_cid; place_cid = userInfo.place_cid;
} else { } else {
let jianbing_guest_customer_id = ctx.cookies.get('jianbing_guest_customer_id', { signed: false }); let jianbing_guest_customer_id = ctx.cookies.get(
jianbing_guest_customer_id = isNaN(jianbing_guest_customer_id) ? ctx.helper.decodeUserSid(jianbing_guest_customer_id) : jianbing_guest_customer_id; "jianbing_guest_customer_id",
{ signed: false }
);
jianbing_guest_customer_id = isNaN(jianbing_guest_customer_id)
? ctx.helper.decodeUserSid(jianbing_guest_customer_id)
: jianbing_guest_customer_id;
filter = { where: { sid: jianbing_guest_customer_id } }; filter = { where: { sid: jianbing_guest_customer_id } };
if (ctx.helper.toInt(jianbing_guest_customer_id) > 50000000) { if (ctx.helper.toInt(jianbing_guest_customer_id) > 50000000) {
userInfo = await ctx.gjjModel.SysUser.one(filter); userInfo = await ctx.gjjModel.SysUser.one(filter);
...@@ -529,29 +648,33 @@ class ProductService extends Service { ...@@ -529,29 +648,33 @@ class ProductService extends Service {
userInfo = await ctx.gjjModel.SysGuest.one(filter); userInfo = await ctx.gjjModel.SysGuest.one(filter);
} }
ctx.logger.info('jianbing_guest_customer_id:' + JSON.stringify(userInfo)); ctx.logger.info("jianbing_guest_customer_id:" + JSON.stringify(userInfo));
if (userInfo !== null) { if (userInfo !== null) {
place_cid = userInfo.place_cid; place_cid = userInfo.place_cid;
} }
} }
if (channel == 'n_1_10000_tencent1') { if (channel == "n_1_10000_tencent1") {
place_cid = 5492; place_cid = 5492;
} else if (channel == 'n_1_10000_51gjjyyb') { } else if (channel == "n_1_10000_51gjjyyb") {
place_cid = 5719; place_cid = 5719;
} }
ctx.logger.info('get_phone_by_user_place:' + place_cid); ctx.logger.info("get_phone_by_user_place:" + place_cid);
// end // end
if (type == 4) { if (type == 4) {
const city_res = await ctx.helper.parseIp(); const city_res = await ctx.helper.parseIp();
if (city_res && city_res.content && city_res.content.address_detail && city_res.content.address_detail.city) { if (
city = city_res.content.address_detail.city.replace('市', ''); city_res &&
city_res.content &&
city_res.content.address_detail &&
city_res.content.address_detail.city
) {
city = city_res.content.address_detail.city.replace("市", "");
} }
ctx.logger.info(JSON.stringify(city_res)); ctx.logger.info(JSON.stringify(city_res));
} }
ctx.logger.info('check loan city:' + city); ctx.logger.info("check loan city:" + city);
for (const v of products) { for (const v of products) {
// ctx.logger.info('imh------begin----------') // ctx.logger.info('imh------begin----------')
...@@ -559,36 +682,61 @@ class ProductService extends Service { ...@@ -559,36 +682,61 @@ class ProductService extends Service {
// start // start
const sepecial_business_ids = [109]; const sepecial_business_ids = [109];
// const place_cids = [ 6046 ]; // const place_cids = [ 6046 ];
const channelList = ['n_1_10000_14038']; const channelList = ["n_1_10000_14038"];
// if (ctx.helper.toInt(place_cid) > 0 && place_cids.includes(ctx.helper.toInt(place_cid)) && sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))) { // if (ctx.helper.toInt(place_cid) > 0 && place_cids.includes(ctx.helper.toInt(place_cid)) && sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))) {
// ctx.logger.info('get_phone_by_user_place_business:' + place_cid + '--business_id--' + v.business_id); // ctx.logger.info('get_phone_by_user_place_business:' + place_cid + '--business_id--' + v.business_id);
// continue; // continue;
// } // }
if (!ctx.isEmpty(channel) && channelList.includes(channel) && sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))) { if (
ctx.logger.info('filter_channel_business: ' + channel + '--business_id--' + v.business_id); !ctx.isEmpty(channel) &&
channelList.includes(channel) &&
sepecial_business_ids.includes(ctx.helper.toInt(v.business_id))
) {
ctx.logger.info(
"filter_channel_business: " +
channel +
"--business_id--" +
v.business_id
);
continue; continue;
} }
// end // end
if (Number(v.type) === 2 || Number(v.type) === 3) { if (Number(v.type) === 2 || Number(v.type) === 3) {
v.rate = ''; v.rate = "";
v.rate_title = ''; v.rate_title = "";
location = 'credit_channel'; location = "credit_channel";
} }
const channels = ctx.isEmpty(v.channel_rate_id) ? [] : v.channel_rate_id.split(','); const channels = ctx.isEmpty(v.channel_rate_id)
? []
: v.channel_rate_id.split(",");
// const rate = channels.includes(channel) ? (v.channel_rate.includes('元') || v.channel_rate.includes('%') ? v.channel_rate : v.channel_rate + '%') : (!ctx.isEmpty(v.rate) ? (v.rate.includes('元') || v.rate.includes('%') ? v.rate : v.rate + '%') : ''); // const rate = channels.includes(channel) ? (v.channel_rate.includes('元') || v.channel_rate.includes('%') ? v.channel_rate : v.channel_rate + '%') : (!ctx.isEmpty(v.rate) ? (v.rate.includes('元') || v.rate.includes('%') ? v.rate : v.rate + '%') : '');
const rate = channels.includes(channel) ? v.channel_rate : v.rate; const rate = channels.includes(channel) ? v.channel_rate : v.rate;
const rateTitle = channels.includes(channel) ? v.channel_rate_title : v.rate_title; 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 && !url.includes('51yhdai')) { if (Number(v.type) === 4 && !url.includes("51yhdai")) {
url = url.includes('?') ? url + '&from=51gjj_loan_channel' : url + '?from=51gjj_loan_channel'; if (!url.includes("www.huaguxin.com")) {
url = url.includes("?")
? url + "&from=51gjj_loan_channel"
: url + "?from=51gjj_loan_channel";
}
} }
url = this.config.PHP_URL + '/app/track/url?url=' + encodeURIComponent(url) + '&source=51gjj&location=' + location; url =
this.config.PHP_URL +
"/app/track/url?url=" +
encodeURIComponent(url) +
"&source=51gjj&location=" +
location;
// ctx.logger.info(v.cities) // ctx.logger.info(v.cities)
// ctx.logger.info(city) // ctx.logger.info(city)
if (v.cities && v.cities.length > 0 && city != '') { if (v.cities && v.cities.length > 0 && city != "") {
// ctx.logger.info('imh------222----------') // ctx.logger.info('imh------222----------')
if ((v.cities.includes(city) && Number(v.city_state) === 1) || (!v.cities.includes(city) && Number(v.city_state) === 0)) { if (
(v.cities.includes(city) && Number(v.city_state) === 1) ||
(!v.cities.includes(city) && Number(v.city_state) === 0)
) {
// ctx.logger.info('imh----------------') // ctx.logger.info('imh----------------')
const tmp = { const tmp = {
type: v.type, type: v.type,
...@@ -608,16 +756,18 @@ class ProductService extends Service { ...@@ -608,16 +756,18 @@ class ProductService extends Service {
abridge_desc: v.abridge_desc, abridge_desc: v.abridge_desc,
front_image: v.front_image, front_image: v.front_image,
back_image: v.back_image, back_image: v.back_image,
percent: v.percent ? v.percent : '0', percent: v.percent ? v.percent : "0",
}; };
if (!ctx.isEmpty(v.partner_alias)) { if (!ctx.isEmpty(v.partner_alias)) {
tmp.partner = v.partner_alias; tmp.partner = v.partner_alias;
} }
ret.push(tmp); ret.push(tmp);
} }
} else if (
} else if (city === '' && Number(v.type) === 4 && url.includes('51yhdai')) { city === "" &&
Number(v.type) === 4 &&
url.includes("51yhdai")
) {
} else { } else {
const tmp = { const tmp = {
type: v.type, type: v.type,
...@@ -637,7 +787,7 @@ class ProductService extends Service { ...@@ -637,7 +787,7 @@ class ProductService extends Service {
abridge_desc: v.abridge_desc, abridge_desc: v.abridge_desc,
front_image: v.front_image, front_image: v.front_image,
back_image: v.back_image, back_image: v.back_image,
percent: v.percent ? v.percent : '0', percent: v.percent ? v.percent : "0",
}; };
if (!ctx.isEmpty(v.partner_alias)) { if (!ctx.isEmpty(v.partner_alias)) {
tmp.partner = v.partner_alias; tmp.partner = v.partner_alias;
...@@ -645,7 +795,7 @@ class ProductService extends Service { ...@@ -645,7 +795,7 @@ class ProductService extends Service {
ret.push(tmp); ret.push(tmp);
} }
} }
ctx.logger.info('check city end'); ctx.logger.info("check city end");
return ret; return ret;
} }
......
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