Commit 10249826 authored by 方斌's avatar 方斌

z

parent 05a9ea11
Pipeline #16070 passed with stage
in 6 seconds
......@@ -16,6 +16,7 @@ class ProductController extends Controller {
let common_loans = [];
let common_credits = [];
let credit_cards = [];
if (type === 'loan') {
suit_options = await ctx.service.gjj.product.getLoanChannelSuitOptions();
if (suit_options) {
......
......@@ -181,6 +181,31 @@ module.exports = {
return { lng: 0, lat: 0 };
},
//根据IP地址来处理业务的展示与否
async parseIp() {
let ip = this.getClientIP();
//
ip = '122.224.130.226';
if (!ip) {
return '';
}
let data = {
ak: '3TBenWOhPygtFFazaR5kSibU',
output: 'json',
ip,
};
const { ctx } = this;
const resp = await ctx.curl('https://api.map.baidu.com/location/ip', { timeout: 3000, dataType: 'json', method: 'GET', data: data });
const ret = resp.data;
if (ret.status != 0) {
return {};
}
return ret;
},
async check_submit_frequent(redis_key, expire = 5) {
const { ctx, app } = this;
const redis_value = await app.memcache.get(redis_key);
......
......@@ -128,15 +128,18 @@ class ProductService extends Service {
// 1 授信贷;2 信用卡;3 普通信用卡;4 普通贷款
async getAllProductsByType(type) {
const { ctx } = this;
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: 'DE78A9AC-0407-4998-AE4D-B7F5A64EAC19' }, { method: 'GET' });
// ctx.logger.info(JSON.stringify({ url, products_results }));
let products = [];
console.log(products_results)
if (products_results.status !== 200 || !products_results.data || !products_results.data.ret) {
return products;
}
products = products_results.data.ret;
const sort = function(a, b) {
if (a.recommend_sorter === b.recommend_sorter) {
......@@ -145,7 +148,7 @@ class ProductService extends Service {
return a.recommend_sorter - b.recommend_sorter;
};
products = R.sort(sort)(products);
products = await this.formatProducts(products);
products = await this.formatProducts(products, type);
return products;
}
......@@ -470,12 +473,23 @@ class ProductService extends Service {
return ret;
}
async formatProducts(products) {
async formatProducts(products, type) {
const { ctx } = this;
const ret = [];
const channel = ctx.channel;
let location = 'loan_channel';
let city = '';
if(type == 4) {
let city_res = await ctx.helper.parseIp();
if(city_res && city_res.content && city_res.content.address_detail && city_res.content.address_detail.city) {
city = city_res.content.address_detail.city.replace('市', '');
}
}
var in_city = false;
for (const v of products) {
in_city = false;
if (Number(v.type) === 2 || Number(v.type) === 3) {
v.rate = '';
v.rate_title = '';
......@@ -490,6 +504,13 @@ class ProductService extends Service {
url = url.includes('?') ? url + '&from=51gjj_loan_channel' : url + '?from=51gjj_loan_channel';
}
url = this.config.PHP_URL + '/app/track/url?url=' + encodeURI(url) + '&source=51gjj&location=' + location;
if(v.cities && v.cities.length > 0 && city != '' && v.cities.indexOf(city)) {
in_city = true;
}
if(!in_city) continue;//如果不在该城市,继续循环
const tmp = {
type: v.type,
business_id: v.business_id,
......
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