Commit 93906451 authored by 李尚科's avatar 李尚科

house tool fix

parent 7fa44a98
Pipeline #6432 passed with stage
in 2 seconds
......@@ -189,19 +189,30 @@ class ToolController extends Controller {
direction_str: { type: 'string', required: true },
floor: { type: 'string', required: true },
total_floor: { type: 'string', required: true },
area_code: { type: 'string', required: true },
};
ctx.validate(rule, input_params);
const city = await ctx.blockModel.City.one({ where: { code: input_params.area_code } });
if (!city || !city.pinyin || Object.keys(city).length === 0) {
ctx.failed('暂不支持城市');
}
const city_pinyin_array = city.pinyin.split(' ');
let city_pinyin = '';
for (let i=0; i < city_pinyin_array.length - 1; i++) {
const pinyin = city_pinyin_array[i];
city_pinyin += pinyin;
};
// ctx.validate(rule, input_params);
const residential_id = input_params.residential_id;
const residential_name = input_params.residential_name;
const area = input_params.area;
const direction_str = input_params.direction_str;
const floor = input_params.floor;
const total_floor = input_params.total_floor;
const qfang_url_area = 'https://hangzhou.qfang.com/fangjia/area';
const qfang_url_area = `https://${city_pinyin}.qfang.com/fangjia/area`;
// const query_string = encodeURIComponent(`userName=&gardenId=&gardenInternalID=${residential_id}&name=${residential_name}&area=${area}&floor=${floor}&totlaFloor=${total_floor}&directionStr=${direction_str}&buildingId=&building=&roomNoId=&roomNo=&subQueryType=quick`);
// const qfang_url_chaxun = 'https://hangzhou.qfang.com/fangjia/chaxun?userName=&gardenId=&gardenInternalID=1f552c71-2747-4539-aeaa-0fc37a6dcd10&name=%E4%B8%87%E9%83%BD%E6%99%B6%E5%BA%A7&area=12&floor=2&totlaFloor=10&directionStr=SOUTHEAST&buildingId=&building=&roomNoId=&roomNo=&subQueryType=quick';
const qfang_url_chaxun = `https://hangzhou.qfang.com/fangjia/chaxun?userName=&gardenId=&gardenInternalID=${residential_id}&name=${encodeURIComponent(residential_name)}&area=${area}&floor=${floor}&totlaFloor=${total_floor}&directionStr=${direction_str}&buildingId=&building=&roomNoId=&roomNo=&subQueryType=quick`;
console.info(qfang_url_chaxun);
const qfang_url_chaxun = `https://${city_pinyin}.qfang.com/fangjia/chaxun?userName=&gardenId=&gardenInternalID=${residential_id}&name=${encodeURIComponent(residential_name)}&area=${area}&floor=${floor}&totlaFloor=${total_floor}&directionStr=${direction_str}&buildingId=&building=&roomNoId=&roomNo=&subQueryType=quick`;
// console.info(qfang_url_chaxun);
// const data = {
// userName: '',
// gardenId: '',
......@@ -221,6 +232,10 @@ class ToolController extends Controller {
// await this.httprequest(qfang_url_chaxun, data);
// return;
const ret1 = await ctx.curl(qfang_url_area, { method: 'POST' });
if(ret1.status !== 200){
ctx.failed('暂不支持该城市');
}
// ctx.success(ret1); return;
const headers = ret1.headers;
const cookies = headers['set-cookie'];
let cookie = '';
......@@ -335,13 +350,26 @@ class ToolController extends Controller {
const input_parmas = ctx.query;
const rule = {
keyword: { type: 'string', required: true },
area_code: { type: 'string', required: true },
}
ctx.validate(rule, input_parmas);
const qfang_url = 'https://hangzhou.qfang.com/fangjia/getGarden';
const city = await ctx.blockModel.City.one({ where: { code: input_parmas.area_code } });
if (!city || !city.pinyin || Object.keys(city).length === 0) {
ctx.failed('暂不支持城市');
}
const city_pinyin_array = city.pinyin.split(' ');
let city_pinyin = '';
for (let i=0; i < city_pinyin_array.length - 1; i++) {
const pinyin = city_pinyin_array[i];
city_pinyin += pinyin;
};
const qfang_url = `https://${city_pinyin}.qfang.com/fangjia/getGarden`;
const keyword = encodeURIComponent(input_parmas.keyword);
const result = await ctx.helper.send_request(qfang_url + '?keyword=' + keyword, {}, { dataType: 'json' });
let ret = [];
if(result.status !== 200){
ctx.failed('暂不支持该城市');
}
if (result.status === 200 && result.data && result.data.items) {
const residential_items = result.data.items;
for (let i in residential_items) {
......
......@@ -13,6 +13,7 @@ module.exports = app => {
code: INTEGER,
level: INTEGER,
parent: INTEGER,
pinyin: STRING,
fword: STRING,
hot: INTEGER,
}, {
......
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