Commit 75bcbe6a authored by 李尚科's avatar 李尚科

house tool f

parent 93906451
Pipeline #6448 passed with stage
in 5 seconds
...@@ -189,19 +189,20 @@ class ToolController extends Controller { ...@@ -189,19 +189,20 @@ class ToolController extends Controller {
direction_str: { type: 'string', required: true }, direction_str: { type: 'string', required: true },
floor: { type: 'string', required: true }, floor: { type: 'string', required: true },
total_floor: { type: 'string', required: true }, total_floor: { type: 'string', required: true },
area_code: { type: 'string', required: true }, city_py: { type: 'string', required: true },
}; };
ctx.validate(rule, input_params); ctx.validate(rule, input_params);
const city = await ctx.blockModel.City.one({ where: { code: input_params.area_code } }); // const city = await ctx.blockModel.City.one({ where: { code: input_params.area_code } });
if (!city || !city.pinyin || Object.keys(city).length === 0) { // if (!city || !city.pinyin || Object.keys(city).length === 0) {
ctx.failed('暂不支持城市'); // ctx.failed('暂不支持城市');
} // }
const city_pinyin_array = city.pinyin.split(' '); // const city_pinyin_array = city.pinyin.split(' ');
let city_pinyin = ''; // let city_pinyin = '';
for (let i=0; i < city_pinyin_array.length - 1; i++) { // for (let i = 0; i < city_pinyin_array.length - 1; i++) {
const pinyin = city_pinyin_array[i]; // const pinyin = city_pinyin_array[i];
city_pinyin += pinyin; // city_pinyin += pinyin;
}; // };
const city_pinyin = input_params.city_py;
const residential_id = input_params.residential_id; const residential_id = input_params.residential_id;
const residential_name = input_params.residential_name; const residential_name = input_params.residential_name;
const area = input_params.area; const area = input_params.area;
...@@ -231,10 +232,13 @@ class ToolController extends Controller { ...@@ -231,10 +232,13 @@ class ToolController extends Controller {
// await this.httprequest(qfang_url_chaxun, data); // await this.httprequest(qfang_url_chaxun, data);
// return; // return;
const ret1 = await ctx.curl(qfang_url_area, { method: 'POST' }); let ret1;
if(ret1.status !== 200){ try {
ret1 = await ctx.curl(qfang_url_area, { method: 'POST' });
} catch (error) {
ctx.failed('暂不支持该城市'); ctx.failed('暂不支持该城市');
} }
// ctx.success(ret1); return; // ctx.success(ret1); return;
const headers = ret1.headers; const headers = ret1.headers;
const cookies = headers['set-cookie']; const cookies = headers['set-cookie'];
...@@ -350,24 +354,31 @@ class ToolController extends Controller { ...@@ -350,24 +354,31 @@ class ToolController extends Controller {
const input_parmas = ctx.query; const input_parmas = ctx.query;
const rule = { const rule = {
keyword: { type: 'string', required: true }, keyword: { type: 'string', required: true },
area_code: { type: 'string', required: true }, city_py: { type: 'string', required: true },
} }
ctx.validate(rule, input_parmas); ctx.validate(rule, input_parmas);
const city = await ctx.blockModel.City.one({ where: { code: input_parmas.area_code } }); // const city = await ctx.blockModel.City.one({ where: { code: input_parmas.area_code } });
if (!city || !city.pinyin || Object.keys(city).length === 0) { // if (!city || !city.pinyin || Object.keys(city).length === 0) {
ctx.failed('暂不支持城市'); // ctx.failed('暂不支持城市');
} // }
const city_pinyin_array = city.pinyin.split(' '); // const city_pinyin_array = city.pinyin.split(' ');
let city_pinyin = ''; // let city_pinyin = '';
for (let i=0; i < city_pinyin_array.length - 1; i++) { // for (let i = 0; i < city_pinyin_array.length - 1; i++) {
const pinyin = city_pinyin_array[i]; // const pinyin = city_pinyin_array[i];
city_pinyin += pinyin; // city_pinyin += pinyin;
}; // };
const city_pinyin = input_parmas.city_py;
const qfang_url = `https://${city_pinyin}.qfang.com/fangjia/getGarden`; const qfang_url = `https://${city_pinyin}.qfang.com/fangjia/getGarden`;
const keyword = encodeURIComponent(input_parmas.keyword); const keyword = encodeURIComponent(input_parmas.keyword);
const result = await ctx.helper.send_request(qfang_url + '?keyword=' + keyword, {}, { dataType: 'json' }); let result;
try {
result = await ctx.helper.send_request(qfang_url + '?keyword=' + keyword, {}, { dataType: 'json' });
} catch (error) {
ctx.failed('暂不支持该城市');
}
let ret = []; let ret = [];
if(result.status !== 200){ if (result.status !== 200) {
ctx.failed('暂不支持该城市'); ctx.failed('暂不支持该城市');
} }
if (result.status === 200 && result.data && result.data.items) { if (result.status === 200 && result.data && result.data.items) {
......
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