Commit b484e465 authored by 任国军's avatar 任国军
parents 60584193 c6b105ba
Pipeline #10180 passed with stage
in 5 seconds
......@@ -13,9 +13,9 @@ class HomeController extends Controller {
const {ctx} = this;
const expire = 7200 * 1000;
const date = new Date();
ctx.cookies.set('auth_token', '0f42a68d19ef161a7c7665488e625ba8', { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/' });
ctx.cookies.set('jianbing_customer_id', '815209', { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/' });
ctx.success(ctx.cookies);
// ctx.cookies.set('auth_token', '0f42a68d19ef161a7c7665488e625ba8', { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/' });
// ctx.cookies.set('jianbing_customer_id', '815209', { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/' });
ctx.success(ctx.header.cookie);
}
}
......
'use strict';
const Controller = require('egg').Controller;
const moment = require('moment');
class Export20190425 extends Controller {
//新房 包含了对应的新房户型和小区信息
async moveNewHouse() {
const { ctx } = this;
let data = {
pageIndex: 1,
pageSize: 999,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const retList = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhouse/list', data, { method: 'POST' });
if (retList.status !== 200) {
ctx.failed('error');
}
let newHouseList = retList.data;
let ret = {
new_org_count: newHouseList.rowCount,
new_data: [],
type_data: [],
};
if (newHouseList.rowCount > 0) {
let list = newHouseList.results;
let newHouseData = [];
for (let i in list) {
const houseType = { 1: '住宅', 2: '公寓', 3: '别墅', 4: '商业', 5: '写字', 6: '底商' };
newHouseData[i] = {
id: list[i].id,
name: list[i].name,
developer_id: 4,//暂时默认写个4
province: list[i].residential.province,
city: list[i].residential.city,
area: list[i].residential.county,
address: list[i].address,
sale_province: list[i].residential.province,
sale_city: list[i].residential.city,
sale_area: list[i].residential.county,
sale_address: list[i].saleAddress,
tags: list[i].tags.replace(/'/g, '"'),
sale_type: list[i].saleType,
house_type: houseType[list[i].houseType],
reference_avg_price: list[i].referenceAvgPrice,
reference_total_price: list[i].referenceTotalPrice,
image: list[i].image,
corner: list[i].cornerMarker,
discount: list[i].discount || null,
favourable_info: list[i].favourableInfo || null,
decoration_type: list[i].decorationType || null,
description: list[i].description || null,
open_date: list[i].openDate,
due_date: list[i].dueDate,
plan_rooms: list[i].planRooms,
plan_parks: list[i].planParks,
plan_near_by: list[i].planNearBy,
pre_sale_permit: list[i].preSalePermit,
pre_sale_permit_date: list[i].preSalePermitDate,
building_numbers: list[i].buildingNumbers,
selling_qualification: list[i].xxx,
remark: list[i].remark,
// is_reality: list[i].xxx,
order_id: list[i].orderNum === 9999 ? 0 : list[i].orderNum,
status: Number(list[i].state) === 0 ? 'offline' : 'online',
valid: 1,
created_at: list[i].createdAt,
updated_at: list[i].updatedAt || null,
// deleted_at: list[i].xxx,
option_city_code: list[i].residential.city,
option_district_code: list[i].residential.county,
option_bizicircle_code: list[i].residential.region,
residential_property_right_years: list[i].residential.propertyRightYears,
residential_property_fee: list[i].residential.propertyFee,
residential_property_company: list[i].residential.propertyCompany,
residential_heat_supply_type: list[i].residential.heatSupplyType,
residential_water_suppler_type: list[i].residential.waterSupplyType,
residential_power_suppler_type: list[i].residential.powerSupplyType,
residential_land_area: list[i].residential.landArea,
residential_house_area: list[i].residential.houseArea,
residential_area_ratio: list[i].residential.areaRatio,
residential_green_ratio: list[i].residential.greenRatio,
residential_arch_type: list[i].residential.archType,
residential_nearby: list[i].residential.nearBy,
}
//户型
if (list[i].newHouseType.length > 0) {
let newHouseType = list[i].newHouseType;
let newHouseDataTypeData = [];
for (let j in newHouseType) {
newHouseDataTypeData[j] = {
id: newHouseType[j].id,
new_house_id: newHouseType[j].newHouseId,
type: newHouseType[j].type,
image: newHouseType[j].image,
tags: newHouseType[j].tags.replace(/'/g, '"'),
apartment: newHouseType[j].apartment,
sale_type: newHouseType[j].saleType,
area: newHouseType[j].area,
orientation: newHouseType[j].orientation,
num: newHouseType[j].num,
price: newHouseType[j].price,
discount: newHouseType[j].discount,
status: Number(newHouseType[j].state) === 0 ? 'offline' : 'online',
remark: newHouseType[j].remark,
valid: 1,
created_at: newHouseType[j].created_at,
updated_at: newHouseType[j].updated_at || null,
// deleted_at: list.newHouseType[j].xxx,
}
}
let type_data = await ctx.realestateModel.NewHouseType.bulkCreate(newHouseDataTypeData, { ignoreDuplicates: true });
ret.type_data = ret.type_data.concat(type_data);
}
}
//房源信息和小区信息
let new_data = await ctx.realestateModel.NewHouse.bulkCreate(newHouseData, { ignoreDuplicates: true });
ret.new_data = ret.new_data.concat(new_data);
}
ret.new_count = ret.new_data.length;
ret.type_count = ret.type_data.length;
ctx.success(ret);
}
//收藏
async moveCollection() {
const { ctx } = this;
let ret = {
data: [],
};
let k = 0;
for (k = 1; k < 999; k++) {
let data = {
pageIndex: k,
pageSize: 500,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/collection/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
let res = result.data;
if (res.results.length === 0) {
break;
}
ret.org_count = res.rowCount;
let list = res.results;
let addData = [];
for (let i in list) {
addData[i] = {
user_id: list[i].userId,
app_user_id: list[i].appUserId,
house_style: list[i].houseStyle,
connect_id: list[i].connectId,
state: list[i].state,
remark: list[i].remark,
created_at: list[i].createdAt,
updated_at: list[i].updatedAt || null,
// deleted_at: list[i].xxx,
}
}
let addRes = await ctx.realestateModel.Collection.bulkCreate(addData, { ignoreDuplicates: true });
ret.data = ret.data.concat(addRes);
}
ret.count = ret.data.length;
ctx.success(ret);
}
//预约
async moveOrder() {
const { ctx } = this;
let ret = {
data: [],
};
let k = 0;
for (k = 1; k < 999; k++) {
let data = {
pageIndex: k,
pageSize: 500,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/order/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
let res = result.data;
if (res.results.length === 0) {
break;
}
ret.org_count = res.rowCount;
let list = res.results;
let addData = [];
for (let i in list) {
addData[i] = {
id: list[i].id,
user_id: list[i].userId,
app_user_id: list[i].appUserId,
house_style: list[i].houseStyle,
connect_id: list[i].connectId,
name: list[i].name,
phone: list[i].phone,
order_at: list[i].orderAt,
state: list[i].state,
remark: list[i].remark,
created_at: list[i].createdAt,
updated_at: list[i].updatedAt || null,
// deleted_at:list[i].xxx,
}
}
let addRes = await ctx.realestateModel.Order.bulkCreate(addData, { ignoreDuplicates: true });
ret.data = ret.data.concat(addRes);
}
ret.count = ret.data.length;
ctx.success(ret);
}
//搜索历史
async moveHistory() {
const { ctx } = this;
let ret = {
data: [],
};
let k = 0;
for (k = 1; k < 999; k++) {
let data = {
pageIndex: k,
pageSize: 500,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/searchhistory/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
let res = result.data;
if (res.results.length === 0) {
break;
}
ret.org_count = res.rowCount;
let list = res.results;
let addData = [];
for (let i in list) {
addData[i] = {
id: list[i].id,
user_id: list[i].userId,
app_user_id: list[i].appUserId,
key_word: list[i].keyWord,
house_style: list[i].houseStyle,
state: list[i].state,
created_at: list[i].createdAt,
// updated_at: list[i].xxx,
// deleted_at: list[i].xxx,
}
}
let addRes = await ctx.realestateModel.SearchHistory.bulkCreate(addData, { ignoreDuplicates: true });
ret.data = ret.data.concat(addRes);
}
ret.count = ret.data.length;
ctx.success(ret);
}
//足迹
async moveFoot() {
const { ctx } = this;
let ret = {
data: [],
};
let k = 0;
for (k = 1; k < 999; k++) {
let data = {
pageIndex: k,
pageSize: 500,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/footprint/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
let res = result.data;
if (res.results.length === 0) {
break;
}
ret.org_count = res.rowCount;
let list = res.results;
let addData = [];
for (let i in list) {
addData[i] = {
id: list[i].id,
user_id: list[i].userId,
// app_type_id:list[i].xxx,
app_user_id: list[i].appUserId,
house_style: list[i].xxx,
connect_id: list[i].connectId,
state: list[i].state,
remark: list[i].remark,
created_at: list[i].createdAt,
updated_at: list[i].updatedAt || null,
// deleted_at: list[i].xxx,
}
}
let addRes = await ctx.realestateModel.FootPrint.bulkCreate(addData, { ignoreDuplicates: true });
ret.data = ret.data.concat(addRes);
}
ret.count = ret.data.length;
ctx.success(ret);
}
//租房数据迁移
async moveRentalHouse() {
const { ctx } = this;
let data = {
pageIndex: 1,
pageSize: 999,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/rentalHouse/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
const now_time = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
const rental_houses = result.data.results;
const residential_developers = { 568: 1, 569: 1, 570: 2, 571: 2, 572: 2, 573: 3, 574: 3, 575: 4, 576: 5, 577: 2, 578: 2, 579: 2, 580: 2, 581: 2, 582: 2, 583: 2, 584: 2, 585: 2, 586: 2, 587: 3, 588: 3, 589: 3, 590: 6, 591: 7, 592: 8, 593: 8, 594: 9, 595: 9, 596: 9, 597: 9, 598: 9, 599: 9 };
const rental_house_type_data = [];
const rental_house_data = [];
for (const i in rental_houses) {
const rental_house = rental_houses[i];
const residential = rental_house.residential;
const rental_house_types = rental_house.rentalHouseType;
for (const j in rental_house_types) {
const rental_house_type = rental_house_types[j];
rental_house_type_data.push({
name: rental_house_type.name,
rental_house_id: rental_house_type.rentalHouseId,
type: rental_house_type.type,
price: rental_house_type.price,
discount: rental_house_type.discount,
area: rental_house_type.area,
remark: rental_house_type.remark,
status: rental_house_type.state ? 'online' : 'offline',
created_at: rental_house_type.createdAt,
updated_at: now_time,
});
}
const tmp = {
id: rental_house.id,
name: rental_house.name,
province: residential.province,
city: residential.city,
area: residential.county,
option_city_code: residential.city,
option_district_code: residential.county,
option_bizicircle_code: residential.region,
developer_id: residential_developers[residential.id],
rental_type: 1,
address: rental_house.address.replace('杭州市', '').replace('重庆市', '').replace('北京市', ''),
price: rental_house.price,
discount: rental_house.discount,
image: rental_house.image,
business_license: rental_house.businessLicense,
notice: rental_house.notice,
tags: rental_house.tags,
favourable_info: rental_house.favourableInfo,
limit_cities: rental_house.limitCities,
room_configuration: rental_house.roomConfiguration,
description: rental_house.description,
order_id: 0,
status: 'online',
valid: 1,
created_at: rental_house.createdAt,
updated_at: now_time,
}
rental_house_data.push(tmp);
}
const rental_house_ret = await ctx.realestateModel.RentalHouse.bulkCreate(rental_house_data);
const rental_house_type_ret = await ctx.realestateModel.RentalHouseType.bulkCreate(rental_house_type_data);
const ret = { rental_house_count: rental_house_ret.length, rental_house_ret, rental_house_type_count: rental_house_type_ret.length, rental_house_type_ret };
ctx.success(ret);
}
//开发商数据迁移
async moveDeveloper() {
const { ctx } = this;
let data = {
pageIndex: 1,
pageSize: 999,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/developer/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
const now_time = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
const developers = result.data.results;
const developer_data = [];
for (let i in developers) {
const developer = developers[i];
developer_data.push({
id: developer.id,
short_name: developer.shortName,
name: developer.name,
logo: developer.logo,
order_id: developer.orderNum,
description: developer.description,
status: 'online',
valid: 1,
created_at: developer.createdAt,
updated_at: now_time,
});
}
const developer_ret = await ctx.realestateModel.Developer.bulkCreate(developer_data);
const ret = { affect_count: developer_ret.length, developer_ret };
ctx.success(ret);
}
//
async moveHouseImage() {
const { ctx } = this;
let data = {
pageIndex: 1,
pageSize: 500,
orderConditions: [{
key: 'id',
orderSequence: 'asc',
}]
}
let house_image_data = [];
const now_time = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
for (let i = 1; i < 999; i++) {
data.pageIndex = i;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/houseimage/list', data, { method: 'POST' });
if (result.status !== 200) {
ctx.failed('error');
}
const house_images = result.data.results;
if (house_images.length === 0) break;
for (let j in house_images) {
const house_image = house_images[j];
if (house_image.state === 0) continue;
house_image_data.push({
// id: house_image.id,
path: house_image.path,
connect_id: house_image.connectId,
type: house_image.type,
description: house_image.description,
remark: house_image.remark,
status: 'online',
valid: 1,
created_at: house_image.createdAt,
updated_at: now_time
});
}
}
const house_image_ret = await ctx.realestateModel.HouseImage.bulkCreate(house_image_data);
const ret = { affect_count: house_image_ret.length, house_image_ret };
ctx.success(ret);
}
}
module.exports = Export20190425;
'use strict';
const Controller = require('egg').Controller;
const R = require('ramda');
class HouseAnalysisController extends Controller {
//购房解析列表
......@@ -40,6 +40,7 @@ class HouseAnalysisController extends Controller {
name: new_house.name,
image: new_house.image,
corner: new_house.corner,
can_gjj_loan: new_house.corner ? 1 : 0,
});
}
......@@ -74,6 +75,16 @@ class HouseAnalysisController extends Controller {
}
//上传户型解析的城市列表
async getHouseAnalysisSupportCity() {
const { ctx } = this;
const results = await ctx.blockModel.City.all({ where: { code: { $in: [110000, 310000, 330100, 440100, 440300, 500000] } } });
ctx.success({ results: R.project(['code', 'name'])(results) });
}
}
module.exports = HouseAnalysisController;
......@@ -155,6 +155,7 @@ class ToolController extends Controller {
ctx.success({ result });
}
//存钱罐 附件房源点位
async getHouseNearbyPoint() {
const { ctx } = this;
......@@ -177,11 +178,11 @@ class ToolController extends Controller {
const { ctx } = this;
const input_parmas = ctx.request.body;
const rule = {
area_code: { type: 'string', required: true },
area_name: { type: 'string', required: true },
city_code: { type: 'string', required: true },
area_code: { type: 'string', required: false },
total_price: { type: 'object', required: true },
down_payment: { type: 'string', required: true },
invest_payment: { type: 'string', required: true },
total_price: { type: 'string', required: true },
prepare_time: { type: 'string', required: true },
house_style: { type: 'string', required: false },
}
......@@ -189,72 +190,86 @@ class ToolController extends Controller {
if (!parseFloat(input_parmas.invest_payment)) {
ctx.failed('现有金额不能为0');
}
if (!parseFloat(input_parmas.total_price)) {
ctx.failed('面积不能为0');
}
// const target_house = await ctx.blockModel.HousePriceMap.one({ where: { id: input_parmas.area_code } });
const area_code = input_parmas.area_code;
const total_price = parseFloat(input_parmas.total_price);
const area_name = input_parmas.area_name;
const house_style = input_parmas.house_style ? input_parmas.house_style : 'new_house';
let filter = {
total_price: { min: total_price - 30, max: total_price + 30 },
area_code: { bizcircle_code: area_code },
const city_code = input_parmas.city_code;
const total_price = input_parmas.total_price;
if (!parseFloat(total_price.max) || !parseFloat(total_price.min)) {
ctx.failed('总价区间不能为0');
}
let recommend_houses = await ctx.service.house.v2.newHouse.getNewHouseList(filter);//推荐房源
let house_map;
let district_code;
if (recommend_houses.count === 0) {
// const house_style = input_parmas.house_style ? input_parmas.house_style : 'new_house';
if (house_style === 'new_house') {
house_map = await ctx.blockModel.HouseNewHousePriceMap2.one({ where: { id: area_code } });
} else if (house_style === 'used_house') {
house_map = await ctx.blockModel.HousePriceMap3.one({ where: { id: area_code } });
}
district_code = (house_map && house_map.pid) ? house_map.pid : '';
filter.area_code = { district_code: district_code }
recommend_houses = await ctx.service.house.newHouse.getNewHouseList(filter);//推荐房源
let where = {
reference_total_price: { $between: [parseFloat(total_price.min), parseFloat(total_price.max)] },
option_city_code: city_code,
option_district_code: area_code,
status: 'online',
valid: 1,
}
if (recommend_houses.count === 0) {
let city_code;
if (house_style === 'new_house') {
house_map = await ctx.blockModel.HouseNewHousePriceMap.one({ where: { id: district_code } });
} else if (house_style === 'used_house') {
house_map = await ctx.blockModel.HousePriceMap2.one({ where: { id: district_code } });
house_map = await ctx.blockModel.HousePriceMap.one({ where: { id: house_map.pid } });
}
city_code = (house_map && house_map.pid) ? house_map.pid : '';
filter.area_code = { city_code: city_code };
recommend_houses = await ctx.service.house.v2.newHouse.getNewHouseList(filter);//推荐房源
let recommend_houses = await ctx.realestateModel.NewHouse.list({ limit: 6, page: 1, where: where, order: [['order_id', 'desc']] });//推荐房源
if (recommend_houses.count < 6) {
delete where.option_district_code;
const out_house_ids = R.pluck('id', recommend_houses.rows);
where.id = { $notIn: out_house_ids };
const recommend_houses_supplement = await ctx.realestateModel.NewHouse.list({ limit: 6, page: 1, where: where, order: [['order_id', 'desc']] });//推荐房源
recommend_houses = [...recommend_houses.rows, ...recommend_houses_supplement.rows];
}
recommend_houses = recommend_houses.splice(0, 6);
const recommend_houses_formats = [];
for (let i in recommend_houses) {
const recommend_house = recommend_houses[i];
recommend_houses_formats.push(await ctx.service.house.v2.newHouse.formatNewHouseBasic(recommend_house));
}
recommend_houses = recommend_houses.results.splice(0, 4);
// const recommend_houses = [];//推荐房源
recommend_houses = recommend_houses_formats;
// recommend_houses = await ctx.service.house.v2.newHouse.formatNewHouseTypeList(recommend_houses);
const house_plan = await ctx.service.house.v2.tool.generateHousePlan(input_parmas);//计算购房能力 生成购房计划
let fine_houses = [];
if (house_plan.status !== 0) {
filter = {
name: area_name,
}
fine_houses = await ctx.service.house.v2.newHouse.getNewHouseList(filter);//推荐房源
fine_houses = fine_houses.results.splice(0, 1);
}
const ret = {
house_plan,
fine_houses,
recommend_houses,
}
ctx.success({ results: ret });
}
//购房计划城市区域列表
async planAreaList() {
const { ctx } = this;
const setting_ret = await ctx.blockModel.Setting.one({ where: { keyword: 'config_fangc_hot_city' } });
const setting_value = ctx.helper.JsonParse(setting_ret.value);
const city_list_ret = await ctx.blockModel.City.all({ where: { code: { $in: setting_value } } });
const city_list = [];
for (let i in city_list_ret) {
let city = city_list_ret[i];
if (city.name.indexOf('市辖区') !== -1) {
city = await ctx.blockModel.City.one({ where: { id: city.parent } });
if (!city || !city.id) {
continue;
}
}
city_list.push({
id: city.id,
name: city.name,
code: city.code,
letter: city.fword.toUpperCase(),
});
}
const cities_ids = R.pluck('code', city_list);
const districts = await ctx.blockModel.HouseDistrict.all({ where: { city_id: { $in: cities_ids } } });
const results = [];
for (let i in city_list) {
const city = city_list[i];
const children = districts.filter(item => { return (parseInt(item.city_id) === parseInt(city.code)) ? true : false });
city._children = children.map(item => { return { id: item.id, name: item.name, code: item.id } });
// city._children.unshift({ id: -1, name: '全部', code: 0 });
results.push(city);
}
ctx.success({ results });
}
//type类型;trend:房价走势图;increase:房价涨跌 ;question: 购房问题;supply:供需趋势图
async getHousePriceFeature() {
......@@ -315,7 +330,7 @@ class ToolController extends Controller {
}
const month = moment(new Date()).format('MM');
const ret = {
city_name: city.name,
name: city.name,
description: `${month}月参考均价`,
price: result.price,
unit: '元/平',
......@@ -325,10 +340,85 @@ class ToolController extends Controller {
}
//房产估价
//房价指数,搜索结果
async getHousePriceFeatureSearch() {
const { ctx } = this;
const input_parmas = ctx.request.body;
const keyword = input_parmas.keyword;
const city_code = input_parmas.city_code;
let results = [];
if (keyword && city_code) {
const month = moment(new Date()).format('MM');
const house_price_map_results = await ctx.blockModel.HousePriceMap.all({ where: { pid: city_code, name: { $like: `%${keyword}%` } } });
results = house_price_map_results.map(item => { return { name: item.name, description: `${month}月参考价`, price: item.price, unit: '元/平' } });
}
ctx.success({ results });
}
// 获取51shequ的oss签名
async getBusinessSignature() {
const { ctx } = this;
const region = 'oss-cn-hangzhou';
const bucket = '51shequ';
const id = 'LTAIubEuBfdUOJ5m';
const key = '83J27tCC2CxHhL2uQvTRcCbEZX2jGK';
const host = '//' + bucket + '.' + region + '.aliyuncs.com';
const url = "//r.51gjj.com/";
let now = Math.round(new Date().getTime() / 1000).toString();
const expire = 120;
let end = now + expire;
let expiration = new Date(new Date().valueOf() + expire * 1000).toISOString().replace(/\..+/, '') + 'Z';
let dir = 'images/house/house_analysis/';
//并无实际用途 只用于调试测试用
//最大文件大小.用户可以自己设置
let condition = new Array(3);
condition[0] = 'content-length-range';
condition[1] = 0;
condition[2] = 1048576000;
let start = new Array('starts-with', '$key', dir);
let conditions = new Array(condition, start);
let policy = { expiration: expiration, conditions: conditions };
let base64_policy = new Buffer(JSON.stringify(policy)).toString('base64');
let string_to_sign = base64_policy;
const crypto = require('crypto');
let signature = crypto.createHmac('sha1', key).update(string_to_sign).digest().toString('base64');;
// let config = {
// region,
// accessKeyId: id,
// accessKeySecret: key,
// bucket: bucket,
// }
let results = {
accessid: id,
static_host: url + dir,
host: host,
policy: base64_policy,
signature: signature,
expire: end,
expiration,
// config: config,
dir
};
ctx.success({ results });
}
//房产估价
}
module.exports = ToolController;
......@@ -115,7 +115,7 @@ module.exports = () => {
ctx.logger.info('user_auth_result: ' + JSON.stringify(result));
console.log(result);
if (result.status !== 201) {
ctx.failed('无效用户');
ctx.failed('token 已失效');
return;
}
......
......@@ -19,6 +19,14 @@ module.exports = app => {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
connect_id: {
type: INTEGER,
allowNull: true
......
......@@ -11,10 +11,6 @@ module.exports = app => {
primaryKey: true,
autoIncrement: true,
},
app_type_id: {
type: STRING,
allowNull: true,
},
user_id: {
type: STRING,
allowNull: true
......@@ -23,6 +19,14 @@ module.exports = app => {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
connect_id: {
type: INTEGER,
allowNull: true
......
......@@ -16,11 +16,19 @@ module.exports = app => {
type: STRING,
allowNull: false
},
residential_id: {
developer_id: {
type: INTEGER,
allowNull: true
},
developer_id: {
province: {
type: INTEGER,
allowNull: true
},
city: {
type: INTEGER,
allowNull: true
},
area: {
type: INTEGER,
allowNull: true
},
......@@ -28,6 +36,18 @@ module.exports = app => {
type: STRING,
allowNull: true
},
sale_province: {
type: INTEGER,
allowNull: true
},
sale_city: {
type: INTEGER,
allowNull: true
},
sale_area: {
type: INTEGER,
allowNull: true
},
sale_address: {
type: INTEGER,
allowNull: true
......@@ -92,22 +112,6 @@ module.exports = app => {
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
land_area: {
type: DECIMAL,
allowNull: true
},
house_area: {
type: DECIMAL,
allowNull: true
},
area_ratio: {
type: DECIMAL,
allowNull: true
},
green_ratio: {
type: DECIMAL,
allowNull: true
},
plan_rooms: {
type: INTEGER,
allowNull: true
......@@ -164,18 +168,6 @@ module.exports = app => {
type: INTEGER,
allowNull: true
},
province: {
type: INTEGER,
allowNull: true
},
city: {
type: INTEGER,
allowNull: true
},
area: {
type: INTEGER,
allowNull: true
},
residential_property_right_years: {
type: INTEGER,
allowNull: true
......@@ -224,18 +216,6 @@ module.exports = app => {
type: TEXT,
allowNull: true
},
sale_province: {
type: INTEGER,
allowNull: true
},
sale_city: {
type: INTEGER,
allowNull: true
},
sale_area: {
type: INTEGER,
allowNull: true
},
deleted_at: {
type: DATE,
allowNull: true,
......
......@@ -19,6 +19,14 @@ module.exports = app => {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
connect_id: {
type: INTEGER,
allowNull: true
......
......@@ -16,7 +16,35 @@ module.exports = app => {
type: STRING,
allowNull: false
},
residential_id: {
developer_id: {
type: INTEGER,
allowNull: true
},
province: {
type: INTEGER,
allowNull: true
},
city: {
type: INTEGER,
allowNull: true
},
area: {
type: INTEGER,
allowNull: true
},
option_city_code: {
type: INTEGER,
allowNull: true
},
option_district_code: {
type: INTEGER,
allowNull: true
},
option_bizicircle_code: {
type: INTEGER,
allowNull: true
},
rental_type: {
type: INTEGER,
allowNull: true
},
......@@ -46,7 +74,19 @@ module.exports = app => {
},
tags: {
type: STRING,
allowNull: true
allowNull: true,
field: 'tags',
get() {
const tags = this.getDataValue('tags');
if (tags) {
try {
return JSON.parse(tags);
} catch (error) {
return [];
}
}
return [];
},
},
favourable_info: {
type: STRING,
......@@ -58,7 +98,19 @@ module.exports = app => {
},
room_configuration: {
type: STRING,
allowNull: true
allowNull: true,
field: 'room_configuration',
get() {
const room_configuration = this.getDataValue('room_configuration');
if (room_configuration) {
try {
return JSON.parse(room_configuration);
} catch (error) {
return {};
}
}
return {};
},
},
description: {
type: STRING,
......
......@@ -19,6 +19,14 @@ module.exports = app => {
type: STRING,
allowNull: true
},
app_id: {
type: STRING,
allowNull: true
},
app_type_id: {
type: STRING,
allowNull: true
},
key_word: {
type: STRING,
allowNull: true
......
......@@ -7,7 +7,7 @@ module.exports = app => {
const { controller } = app;
const router = app.router.namespace(app.config.projectRootPath);
router.get('/', controller.home.index);
// router.get('/home/setCookie', controller.home.setCookie);
router.get('/home/setCookie', controller.home.setCookie);
require('./router/gjj')(app);
......
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/house/export');
// router.get('add', '/house_image', 'house.export20190425.exportHouseImages');//用户浏览记录列表
// router.get('add', '/residential', 'house.export20190425.exportResidential');//用户浏览记录列表
// router.get('/new_house', 'house.export20190425.moveNewHouse');
// router.get('/new_house_type', 'house.export20190425.moveNewHouseType');
//sqlserver迁移数据
router.get('third', '/new_house_related', 'house.v2.export190619.moveNewHouse');
router.get('third', '/collection', 'house.v2.export190619.moveCollection');
router.get('third', '/order', 'house.v2.export190619.moveOrder');
router.get('third', '/history', 'house.v2.export190619.moveHistory');
router.get('third', '/foot', 'house.v2.export190619.moveFoot');
router.get('third', '/rental_house_related', 'house.v2.export190619.moveRentalHouse');
router.get('third', '/developer', 'house.v2.export190619.moveDeveloper');
router.get('third', '/house_image', 'house.v2.export190619.moveHouseImage');
};
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/house/export20190425');
router.get('add', '/house_image', 'house.export20190425.exportHouseImages');//用户浏览记录列表
router.get('add', '/residential', 'house.export20190425.exportResidential');//用户浏览记录列表
router.get('/new_house', 'house.export20190425.moveNewHouse');
router.get('/new_house_type', 'house.export20190425.moveNewHouseType');
};
......@@ -4,6 +4,7 @@ module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/house');
const loginAuth = app.middleware.loginAuth({ type: 'new' });//登录中间件
/***********1.0接口关闭
router.get('/tool/:house_style/:area_code/:level', 'house.tool.getMapPoint');//购房计划地图点位
router.post('/tool/plan', 'house.tool.generateBuyHousePlan');//生成购房计划
router.get('/tool/:type/:area_code', 'house.tool.getHousePriceFeature');//房价指数 房价涨跌 购房资格、贷款额度问答
......@@ -43,21 +44,24 @@ module.exports = app => {
//我的
router.get('/mine', 'house.mine.getMineInfo');//获取用户的头像昵称和关注等信息
***********关闭1.0接口****************/
//房产v2
router.get('/v2/tool/:house_style/:area_code/:level', 'house.v2.tool.getMapPoint');//购房计划地图点位(存钱罐地图)(房价地图)
router.post('/v2/tool/plan', 'house.tool.generateBuyHousePlan');//生成购房计划
router.post('/v2/tool/plan', 'house.v2.tool.generateBuyHousePlan');//生成购房计划
router.get('/v2/tool/plan_area_list', 'house.v2.tool.planAreaList');//购房计划页面 区域列表接口
router.get('/v2/tool/:type/:area_code', 'house.v2.tool.getHousePriceFeature');//房价走势图 房价涨跌图 购房资格图、贷款额度问答、供需趋势图
router.post('/v2/tool/calculate_price', 'house.tool.calculateHousePrice');//房产估价
router.get('/v2/tool/qfang_area_list', 'house.tool.getQFangAreaList');//房产估价模糊匹配到的小区列表
router.get('/v2/tool/map_houses', 'house.tool.getMapHouses');//房产估价模糊匹配到的小区列表
router.get('/v2/tool/house_price_feature_city', 'house.v2.tool.getHousePriceFeatureCity');//房价指数 城市月参考价支持的城市
router.get('/v2/tool/house_price_city', 'house.v2.tool.getHousePriceCity');//房价指数 城市月参考价
router.post('/v2/tool/house_price_search', 'house.v2.tool.getHousePriceFeatureSearch');//房价指数 搜索结果
router.get('/v2/tool/house_point', 'house.v2.tool.getHousePoint');//点击房源信息跳到地图页 需要的经纬度信息。
router.post('/v2/tool/nearby_house_points', 'house.v2.tool.getHouseNearbyPoint');//点击房源信息跳到地图页 此房源周边信息。
router.get('/v2/tool/oss_signature', 'house.v2.tool.getBusinessSignature');//点击房源信息跳到地图页 此房源周边信息。
//租房列表
......@@ -103,6 +107,7 @@ module.exports = app => {
router.get('/v2/house_analysis/info/:house_analysis_id', 'house.v2.houseAnalysis.getHouseAnalysisInfo');//户型解析列表
router.post('/v2/house_analysis/', loginAuth, 'house.v2.houseAnalysis.uploadHouseAnalysis');//上传户型信息
router.get('/v2/house_analysis/mine', loginAuth, 'house.v2.houseAnalysis.getUserHouseAnalysis');//我的户型
router.get('/v2/house_analysis/city_list', 'house.v2.houseAnalysis.getHouseAnalysisSupportCity');//上传户型解析的城市列表
//提问
router.post('/v2/question', loginAuth, 'house.v2.question.addQuestion');//提问
......
......@@ -139,7 +139,9 @@ class ProductService extends Service {
if (products_results.status !== 200 || !products_results.data || !products_results.data.ret) {
return products;
}
products = await this.formatProducts(products_results.data.ret);
products = products_results.data.ret;
products.sort(function (x, y) { return x['recommend_sorter'] - y['recommend_sorter'] });
products = await this.formatProducts(products);
return products;
}
......
......@@ -12,6 +12,10 @@ class AnswerLikeService extends Service {
*/
async like(id) {
const { ctx } = this;
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就不做处理
return false;
}
let filter = {
where: {
answer_id: id,
......
......@@ -12,6 +12,10 @@ class CollectionService extends Service {
*/
async addCollection(inputParams) {
const { ctx } = this;
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就不做处理
return false;
}
let filter = {
where: {
......@@ -28,6 +32,8 @@ class CollectionService extends Service {
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
house_style: inputParams.type,
connect_id: inputParams.id,
state: 1,
......@@ -109,7 +115,7 @@ class CollectionService extends Service {
user_id: ctx.userId,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
order: [['id', 'desc']]
}
let list = [];
let collectionList = await ctx.realestateModel.Collection.all(filter);
......@@ -130,6 +136,9 @@ class CollectionService extends Service {
});
//数据整理
for (let j in retList) {
if (retList[j].status === 'offline' || Number(retList[j].valid) === 0) {
continue;
}
let type = collectionList[j].house_style;
let tmp = {
id: retList[j].id,
......@@ -137,7 +146,7 @@ class CollectionService extends Service {
address: retList[j].address,
tags: retList[j].tags ? eval(retList[j].tags) : [],
image: retList[j].image,
area: type === 1 ? Number(retList[j].house_area) : '',
area: type === 1 ? Number(retList[j].residential_house_area) : '',
price: type === 1 ? (['', 0].includes(Number(retList[j].reference_avg_price)) ? '--' : Number(retList[j].reference_avg_price)) : Number(retList[j].price),
type: type === 1 ? 'new_house' : 'rental_house',
corner: type === 1 ? retList[j].corner : '',
......@@ -165,16 +174,52 @@ class CollectionService extends Service {
let filter = {
page: 1,
limit: 50,
attributes: ['connect_id', 'house_style'],
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
order: [['id', 'desc']]
}
let list = await ctx.realestateModel.Collection.all(filter);
let count = 0;
if (list.length > 0) {
let newHouseId = [];
let rentalHouseId = [];
for (let i in list) {
if (Number(list[i].house_style) === 1) {
newHouseId.push(list[i].connect_id);
}
if (Number(list[i].house_style) === 2) {
rentalHouseId.push(list[i].connect_id);
}
}
let newHousefilter = {
where: {
status: 'online',
valid: 1,
id: { $in: newHouseId },
},
}
let newHouseCountTask = ctx.realestateModel.NewHouse.count(newHousefilter);
let rentalHousefilter = {
where: {
status: 'online',
valid: 1,
id: { $in: rentalHouseId },
},
}
let rentalHouseCountTask = ctx.realestateModel.RentalHouse.count(rentalHousefilter);
const retList = await Promise.all([newHouseCountTask, rentalHouseCountTask]).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
count = Number(retList[0]) + Number(retList[1]);
}
let collectionList = await ctx.realestateModel.Collection.all(filter);
let ret = {
count: collectionList.length
count: count
};
return ret;
}
......
......@@ -15,15 +15,15 @@ class FootPrintService extends Service {
const { ctx } = this;
const user_id = ctx.userId;
const app_user_id = ctx.appUserId;
const app_type_id = ctx.appTypeId;
if (!user_id || !app_user_id) {
return false;
}
const data = {
user_id: user_id,
app_type_id: app_type_id,
app_user_id: app_user_id,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
house_style: inputParams.type,
connect_id: inputParams.id,
state: 1,
......@@ -51,8 +51,19 @@ class FootPrintService extends Service {
count: 0
};
}
const foot_prints_rows = await ctx.realestateModel.FootPrint.list({ page: 1, limit: 50, where: { user_id: user_id, app_type_id: app_type_id, state: 1 }, order: [['id', 'desc']] });
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
const filter = {
page: 1,
limit: 50,
where: {
user_id: user_id,
app_type_id: app_type_id,
state: 1,
created_at: { $gt: endDate },
},
order: [['id', 'desc']]
};
const foot_prints_rows = await ctx.realestateModel.FootPrint.list(filter);
const foot_prints = foot_prints_rows.rows;
const p_houses = [];
for (let i in foot_prints) {
......@@ -73,6 +84,9 @@ class FootPrintService extends Service {
//处理足迹数据
const foot_print_records = [];
for (let j in houses) {
if (houses[j].status === 'offline' || Number(houses[j].valid) === 0) {
continue;
}
const house = houses[j];
const foot_print = foot_prints[j];
const type = foot_print.house_style === 1 ? 'new_house' : 'rental_house';
......@@ -106,19 +120,56 @@ class FootPrintService extends Service {
if (!ctx.userId) {
return { count: 0 };
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
const filter = {
page: 1,
limit: 50,
attributes: ['connect_id', 'house_style'],
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
}
const footPrintsResults = await ctx.realestateModel.FootPrint.all(filter);
const list = await ctx.realestateModel.FootPrint.all(filter);
let count = 0;
if (list.length > 0) {
let newHouseId = [];
let rentalHouseId = [];
for (let i in list) {
if (Number(list[i].house_style) === 1) {
newHouseId.push(list[i].connect_id);
}
if (Number(list[i].house_style) === 2) {
rentalHouseId.push(list[i].connect_id);
}
}
let newHousefilter = {
where: {
status: 'online',
valid: 1,
id: { $in: newHouseId },
},
}
let newHouseCountTask = ctx.realestateModel.NewHouse.count(newHousefilter);
let rentalHousefilter = {
where: {
status: 'online',
valid: 1,
id: { $in: rentalHouseId },
},
}
let rentalHouseCountTask = ctx.realestateModel.RentalHouse.count(rentalHousefilter);
const retList = await Promise.all([newHouseCountTask, rentalHouseCountTask]).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
count = Number(retList[0]) + Number(retList[1]);
}
let ret = {
count: footPrintsResults.length
count: count
};
return ret;
}
......
......@@ -12,6 +12,10 @@ class HotQuestionAnswerService extends Service {
*/
async addAnswer(inputParams) {
const { ctx } = this;
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就不做处理
return false;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
......
......@@ -12,6 +12,10 @@ class HotQuestionPutService extends Service {
*/
async addQuestion(inputParams) {
const { ctx } = this;
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就不做处理
return false;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
......@@ -67,15 +71,22 @@ class HotQuestionPutService extends Service {
*/
async questionDetail(condition) {
const { ctx } = this;
let ret = {
question: '--',
time: '--',
answerList: []
};
//问题内容
let filter = {
attributes: ['question', 'created_at'],
where: {
id: Number(condition.id),
status: "pass"
id: Number(condition.id)
}
}
let question = await ctx.realestateModel.HotQuestionPut.one(filter);
if (question === null || !question) {
return ret;
}
//回答的列表
let answerFliter = {
page: Number(condition.page) || 1,
......@@ -83,9 +94,9 @@ class HotQuestionPutService extends Service {
question_id: Number(condition.id),
}
let answerLsit = await ctx.service.house.v2.hotQuestionAnswer.answerList(answerFliter);
let ret = {
ret = {
question: question.question || '',
time: question.created_at ? moment().format("YYYY-MM-DD") : '',
time: question.created_at ? moment(question.created_at).format("YYYY-MM-DD") : '',
answerList: answerLsit
}
return ret;
......
......@@ -11,8 +11,9 @@ class HouseAnalysisService extends Service {
async getHouseAnalysisByFilter(condition) {
const { ctx } = this;
let { city_code, keyword, page } = condition;
let { city_code, keyword, page, page_size } = condition;
page = page ? page : 1;
page_size = page_size ? page_size : 10;
let where = { status: 'pass' };
if (city_code) {
where.city = city_code;
......@@ -20,7 +21,7 @@ class HouseAnalysisService extends Service {
if (keyword && keyword.length !== 0) {
where.residential = { $like: `%${keyword}%` }
}
const house_analysis_rows = await ctx.realestateModel.HouseAnalysis.list({ page: page, where: where, order: [['id', 'desc']] });
const house_analysis_rows = await ctx.realestateModel.HouseAnalysis.list({ page: page, limit: Number(page_size), where: where, order: [['id', 'desc']] });
const house_analysis = R.project(['id', 'image', 'residential', 'house_type', 'house_area', 'text'])(house_analysis_rows.rows);
return { page: page, count: house_analysis_rows.count, results: house_analysis };
......@@ -83,7 +84,7 @@ class HouseAnalysisService extends Service {
if (!user_id || !app_type_id) {
ctx.failed('login error');
}
const results = await ctx.realestateModel.HouseAnalysis.list({ page: page, limit: limit, where: { user_id: user_id, app_type_id: app_type_id }, order: [['id', 'desc']] });
const results = await ctx.realestateModel.HouseAnalysis.list({ page: page, limit: Number(limit), where: { user_id: user_id, app_type_id: app_type_id }, order: [['id', 'desc']] });
return results;
}
......
......@@ -51,7 +51,7 @@ class NewHouseService extends Service {
}
let newHouseImagesTask = ctx.realestateModel.HouseImage.all(filter);
//是否关注
let collectionTask = ctx.service.house.collection.getCollection({ type: 1, id: id });
let collectionTask = ctx.service.house.v2.collection.getCollection({ type: 1, id: id });
//获取每个任务的数据
const retList = await Promise.all([developerInfoTask, newHouseTypeInfoTask, newHouseImagesTask, collectionTask]).then(result => {
......@@ -124,19 +124,22 @@ class NewHouseService extends Service {
const saleType = { 0: '未开售', 1: '售罄', 2: '预售', 3: '在售' };
const decorationType = { 1: '毛坯', 2: '简装', 3: '精装' }
const archType = { 1: '板楼', 2: '塔楼' };
const houseType = { 1: '住宅', 2: '公寓' };
let ret = {};
if (Object.keys(data).length > 0) {
//将json格式字符串处理
let nearBy = '';
if (data.residential_nearby.length > 0) {
let temp = eval(data.residential_nearby);
for (let i in temp) {
let subTemp = '';
for (let j in temp[i]) {
subTemp += j + ':' + temp[i][j].join(',');
if (/^\[(.*?)\]$/.test(data.residential_nearby)) {//粗略的匹配
//将json格式字符串处理
let temp = JSON.parse(data.residential_nearby);
for (let i in temp) {
let subTemp = '';
for (let j in temp[i]) {
subTemp += j + ':' + temp[i][j].join(',');
}
nearBy += subTemp + ';';
}
nearBy += subTemp + ';';
} else {
nearBy = data.residential_nearby;
}
}
//房型面积处理
......@@ -154,17 +157,11 @@ class NewHouseService extends Service {
let area = typeArea.min === typeArea.max ? Number(typeArea.min) : Number(typeArea.min) + '-' + Number(typeArea.max);
//经纬度
const city = await ctx.blockModel.City.one({ where: { code: data.option_city_code } });
const county = await ctx.blockModel.HouseDistrict.one({ where: { id: data.option_district_code } });
const region = await ctx.blockModel.HouseBizcircle.one({ where: { id: data.option_bizicircle_code } });
const city_name = city.name ? city.name : '';
const county_name = county.name ? county.name : '';
const region_name = region.name ? region.name : '';
let address = city_name + county_name + region_name + data.address;
let gps_result = await ctx.helper.getGPS(address, city_name);
let addressDecode = await this.addressDecode({ city: data.option_city_code, district: data.option_district_code, bizicircle: data.option_bizicircle_code });
let address = addressDecode.city + addressDecode.county + addressDecode.region + data.address;
let gps_result = await ctx.helper.getGPS(address, addressDecode.city);
if (!gps_result.lat || !gps_result.lng) {
address = city_name + county_name + region_name;
gps_result = await ctx.helper.getGPS(address, city_name);
gps_result = await ctx.helper.getGPS(addressDecode, addressDecode.city);
}
let longitude = 0;
let latitude = 0;
......@@ -181,16 +178,16 @@ class NewHouseService extends Service {
favourable_info: data.favourable_info || '',//优惠
reference_avg_price: data.reference_avg_price === 0 ? '--' : Number(data.reference_avg_price),//均价
reference_total_price: data.reference_total_price === 0 ? '--' : Number(data.reference_total_price),//总价
property_type: houseType[data.house_type] || '',//物业类型
property_type: data.house_type.split(',').slice(0, 2),//物业类型
}
ret.info = {
open_date: data.open_date,//开盘时间
due_date: ['0000-00-00 00:00:00', ''].includes(data.due_date) ? '--' : data.due_date,//交房时间
house_area: area,//建筑面积
house_area: area,//建筑面积包含各个户型的面积
decoration: decorationType[data.decoration_type] || '',//装修情况,1 毛坯,2简装,3精装
green_ratio: Number(data.green_ratio),//绿化
area_ratio: Number(data.area_ratio),//容积
green_ratio: Number(data.residential_green_ratio),//绿化
area_ratio: Number(data.residential_area_ratio),//容积
address: data.address,//地址
longitude: longitude,//经度
latitude: latitude,//纬度
......@@ -199,7 +196,7 @@ class NewHouseService extends Service {
basic: {
reference_avg_price: data.reference_avg_price === 0 ? '--' : Number(data.reference_avg_price),//均价
tags: data.tags ? eval(data.tags) : [],//项目特色
property_type: houseType[data.house_type] || '',//物业类型
property_type: data.house_type.split(',').slice(0, 2),//物业类型
property_right_years: data.residential_property_right_years,//产权年限
build_type: archType[data.residential_arch_type] || '',//建筑类型 1 板楼 2塔楼'
decoration: decorationType[data.decoration_type] || '',//装修情况,1 毛坯,2简装,3精装
......@@ -215,8 +212,8 @@ class NewHouseService extends Service {
residential: {
land_area: Number(data.residential_land_area),//占地面积
house_area: Number(data.residential_house_area),//建筑面积
area_ratio: Number(data.area_ratio),//容积率
green_ratio: Number(data.green_ratio),//绿化率
area_ratio: Number(data.residential_area_ratio),//容积率
green_ratio: Number(data.residential_green_ratio),//绿化率
property_fee: data.residential_property_fee,//物业费用
property_company: data.residential_property_company,//物业公司
plan_rooms: data.plan_rooms,//规划户数
......@@ -295,14 +292,13 @@ class NewHouseService extends Service {
async formatNewHouseType(data) {
const { ctx } = this;
const saleType = { 0: '未开售', 1: '售罄', 2: '预售', 3: '在售' };
const houseType = { 1: '住宅', 2: '公寓', 3: '别墅', 4: '商业', 5: '写字', 6: '底商' };
let ret = {};
if (Object.keys(data).length > 0) {
ret = {
id: data.id,
new_house_id: data.new_house_id,
type: data.type,//类型,如三居、四居
house_type: houseType[data.house_type] || '',
house_type: data.house_type.split(',').slice(0, 2),
image: data.image,
apartment: data.apartment,//户型,如4室2厅3卫
sale_type: saleType[data.sale_type] || '',
......@@ -342,7 +338,7 @@ class NewHouseService extends Service {
if (type === 'home') {
//为您推荐只展示50条在售楼盘的数据,根据排序序号取数,数字小的排在前面,数字一样的情况下根据时间逆序排列,时间也一样的情况下随机排列;
filter.limit = Number(condition.page_size) || 50;
filter.order.push(['order_id', 'desc'], ['created_at', 'desc']);
// filter.order.push(['order_id', 'desc'], ['created_at', 'desc']);拿掉排序,跟默认排序重复了 2019-6-28 14:06:00 lisk
} else if (type === 'all') {
filter.order.push(['sale_type', 'desc']);
} else if (type === 'sale') {
......@@ -409,19 +405,12 @@ class NewHouseService extends Service {
filter.where.option_bizicircle_code = condition.area_code.bizcircle_code;
}
}
filter.order.push(['order_id', 'desc'], ['id', 'desc']);//添加默认排序 2019-6-28 14:05:25 lisk
let newHouseList = await ctx.realestateModel.NewHouse.list(filter);
let list = [];
if (newHouseList.count > 0) {
for (let i in newHouseList.rows) {
let tmp = {
id: newHouseList.rows[i].id,
name: newHouseList.rows[i].name,
address: newHouseList.rows[i].address,
tags: newHouseList.rows[i].tags ? eval(newHouseList.rows[i].tags) : [],
image: newHouseList.rows[i].image,
price: Number(newHouseList.rows[i].reference_avg_price) === 0 ? '--' : Number(newHouseList.rows[i].reference_avg_price),
corner: newHouseList.rows[i].cornerMarker,
};
let tmp = await this.formatNewHouseBasic(newHouseList.rows[i]);
list.push(tmp);
}
}
......@@ -432,6 +421,21 @@ class NewHouseService extends Service {
return ret;
}
async formatNewHouseBasic(newHouseInfo) {
const { ctx } = this;
let ret = {
id: newHouseInfo.id,
name: newHouseInfo.name,
address: newHouseInfo.address,
tags: newHouseInfo.tags ? eval(newHouseInfo.tags) : [],
image: newHouseInfo.image,
price: Number(newHouseInfo.reference_avg_price) === 0 ? '--' : Number(newHouseInfo.reference_avg_price),
corner: newHouseInfo.corner || '',
}
return ret;
}
//获取推荐楼盘 目前推荐逻辑条件少 后面扩展
async getRecommendNewHouses(condition) {
......@@ -444,7 +448,7 @@ class NewHouseService extends Service {
if (city_code) {
where.option_city_code = city_code;
}
let new_houses_rows = await ctx.realestateModel.NewHouse.list({ page: page, limit: limit, where: where, order: [['order_id', 'asc']] });
let new_houses_rows = await ctx.realestateModel.NewHouse.list({ page: page, limit: limit, where: where, order: [['order_id', 'desc']] });
const similar_list = [];
for (let i in new_houses_rows.rows) {
const new_house = new_houses_rows.rows[i];
......@@ -453,12 +457,37 @@ class NewHouseService extends Service {
name: new_house.name,
image: new_house.image,
corner: new_house.corner,
can_gjj_loan: new_house.corner ? 1 : 0,
});
}
return similar_list;
}
/**
* 根据市区商圈的城市编码获取地址
* @param {*} code
*/
async addressDecode(code) {
const { ctx } = this;
let taskList = [
ctx.blockModel.City.one({ where: { code: code.city } }),
ctx.blockModel.HouseDistrict.one({ where: { id: code.district } }),
ctx.blockModel.HouseBizcircle.one({ where: { id: code.bizicircle } }),
];
let retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
const city = retList[0].name ? retList[0].name : '';
const county = retList[1].name ? retList[1].name : '';
const region = retList[2].name ? retList[2].name : '';
return { city, county, region };
}
}
module.exports = NewHouseService;
......@@ -112,9 +112,9 @@ class OptionService extends Service {
async getDevelopers(city_code) {
const { ctx } = this;
const rental_house_developers = await ctx.realestateModel.RentalHouse.findAll({ attributes: ['developer_id'], group: 'developer_id', where: { option_city_code: city_code } });
const developers_ids = rental_house_developers.map(item => { return item.dataValues.developer_id });
const developers = await ctx.realestateModel.Developer.all({ where: { id: { $in: developers_ids } } });
const rental_house_developers = await ctx.realestateModel.RentalHouse.findAll({ attributes: ['developer_id'], group: 'developer_id', where: { option_city_code: city_code, status: 'online', valid: 1 } });
const developers_ids = rental_house_developers.map(item => { return item.developer_id });
const developers = await ctx.realestateModel.Developer.all({ where: { id: { $in: developers_ids }, status: 'online', valid: 1 } });
const ret = developers.map(item => { return { id: item.id, name: item.name, image: item.logo, value: item.id } });
return ret;
}
......
......@@ -11,8 +11,11 @@ class OrderService extends Service {
* @param {object} inputParams
*/
async addOrder(inputParams) {
const { ctx, service } = this;
const { ctx } = this;
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就不做处理
return false;
}
let filter = {
where: {
state: 1,
......@@ -33,6 +36,8 @@ class OrderService extends Service {
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
house_style: inputParams.type,
connect_id: inputParams.id,
name: inputParams.name,
......@@ -64,7 +69,7 @@ class OrderService extends Service {
user_id: ctx.userId,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']]
order: [['id', 'desc']]
}
let list = [];
let orderList = await ctx.realestateModel.Order.all(filter);
......@@ -85,6 +90,9 @@ class OrderService extends Service {
});
//数据整理
for (let j in retList) {
if (retList[j].status === 'offline' || Number(retList[j].valid) === 0) {
continue;
}
let type = orderList[j].house_style;
let tmp = {
id: retList[j].id,
......@@ -92,7 +100,7 @@ class OrderService extends Service {
address: retList[j].address,
tags: retList[j].tags ? eval(retList[j].tags) : [],
image: retList[j].image,
area: type === 1 ? Number(retList[j].house_area) : '',
area: type === 1 ? Number(retList[j].residential_house_area) : '',
price: type === 1 ? (Number(retList[j].reference_avg_price) === 0 ? '--' : Number(retList[j].reference_avg_price)) : Number(retList[j].price),
time: moment().format('YYYY-MM-DD') === moment(orderList[j].order_at).format('YYYY-MM-DD') ? '今天' : moment(orderList[j].order_at).format('YYYY-MM-DD'),
type: type === 1 ? 'new_house' : 'rental_house',
......@@ -120,17 +128,52 @@ class OrderService extends Service {
let filter = {
page: 1,
limit: 50,
attributes: ['connect_id', 'house_style'],
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
order: [['id', 'desc']]
}
let list = await ctx.realestateModel.Order.all(filter);
let count = 0;
if (list.length > 0) {
let newHouseId = [];
let rentalHouseId = [];
for (let i in list) {
if (Number(list[i].house_style) === 1) {
newHouseId.push(list[i].connect_id);
}
if (Number(list[i].house_style) === 2) {
rentalHouseId.push(list[i].connect_id);
}
}
let newHousefilter = {
where: {
status: 'online',
valid: 1,
id: { $in: newHouseId },
},
}
let newHouseCountTask = ctx.realestateModel.NewHouse.count(newHousefilter);
let rentalHousefilter = {
where: {
status: 'online',
valid: 1,
id: { $in: rentalHouseId },
},
}
let rentalHouseCountTask = ctx.realestateModel.RentalHouse.count(rentalHousefilter);
const retList = await Promise.all([newHouseCountTask, rentalHouseCountTask]).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
count = Number(retList[0]) + Number(retList[1]);
}
let orderList = await ctx.realestateModel.Order.all(filter);
let ret = {
count: orderList.length
count: count
};
return ret;
}
......
......@@ -31,6 +31,8 @@ class RentalHouseService extends Service {
where.developer_id = brand;
}
if (name) {
//增加搜索历史
ctx.service.house.v2.searchHistory.addSearchHistory({ type: 2, key_word: name });
where.name = { $like: `%${name}%` };
}
if (price && price.max) {
......@@ -45,7 +47,7 @@ class RentalHouseService extends Service {
where.option_district_code = area_code.district_code;
}
if (area_code.bizcircle_code && area_code.bizcircle_code !== '') {
where.option_bizcircle_code = area_code.bizcircle_code;
where.option_bizicircle_code = area_code.bizcircle_code;
}
}
if (house_type) {
......@@ -53,12 +55,13 @@ class RentalHouseService extends Service {
const rental_houses_ids = R.pluck('rental_house_id', house_types);
let match_ids = new Set(rental_houses_ids);
match_ids = [...match_ids];
if (Array.isArray(match_ids) && match_ids.length !== 0) {
where.id = { $in: match_ids };
}
// if (Array.isArray(match_ids) && match_ids.length !== 0) {
// where.id = { $in: match_ids };
// }
where.id = { $in: match_ids };
}
const rental_houses_results = await ctx.realestateModel.RentalHouse.list({ page: page, limit: Number(limit), where: where, order: [['order_id', 'asc']] });
const rental_houses_results = await ctx.realestateModel.RentalHouse.list({ page: page, limit: Number(limit), where: where, order: [['order_id', 'desc'], ['id', 'desc']] });
let rental_houses = await this.formatRentalHouseBasic(rental_houses_results.rows);
rental_houses = R.project(['id', 'image', 'name', 'address', 'price', 'tags', 'favourable_info'])(rental_houses);
......@@ -78,26 +81,34 @@ class RentalHouseService extends Service {
//楼盘图片信息和房型信息
const house_types_rets = await ctx.realestateModel.RentalHouseType.all({ where: { rental_house_id: rental_house_id, status: 'online', valid: 1 } });
const p_house_images = ctx.service.house.v2.houseImage.getAll({ type: 1, connect_id: rental_house_id }, ['id', 'path', 'description']);
const p_house_images = ctx.service.house.v2.houseImage.getAll({ type: 0, connect_id: rental_house_id }, ['id', 'path', 'description']);
const p_house_types = this.formatRentHouseTypes(house_types_rets);
const p_ret = await Promise.all([p_house_images, p_house_types]).then(result => {//等待所有异步内容获取完成
const p_collection = await ctx.service.house.v2.collection.getCollection({ type: 2, id: rental_house_id });
const p_ret = await Promise.all([p_house_images, p_house_types, p_collection]).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
const house_images = p_ret[0];
const house_types = p_ret[1];
const collection = p_ret[2];//是否关注
//处理房源基本信息格式
let house_basic = await this.formatRentalHouseBasic([rental_house_info]);
house_basic = house_basic[0];
//添加用户足迹,是否关注过房源
await ctx.service.house.v2.footPrint.addFootPrint({ type: 2, id: rental_house_id });
//是否关注
let collectionTask = await ctx.service.house.collection.getCollection({ type: 2, id: rental_house_id });
//添加用户足迹
ctx.service.house.v2.footPrint.addFootPrint({ type: 2, id: rental_house_id });
const city_codes = [rental_house_info.province, rental_house_info.city, rental_house_info.area];
const cities = await ctx.blockModel.City.all({ where: { code: { $in: city_codes } } });
const city = (cities && cities[1] && cities[1].name) ? cities[1].name : '';
const address = R.pluck('name', cities).join('') + rental_house_info.address;
const gps_info = await ctx.helper.getGPS(address, city);
house_basic.longitude = gps_info.lng;
house_basic.latitude = gps_info.lat;
return { house_basic, house_images, house_types, collection: collectionTask, };
return { house_basic, house_images, house_types, collection: collection.length > 0 ? true : false, };
}
//格式化户型数据
......@@ -156,19 +167,20 @@ class RentalHouseService extends Service {
id: rental_house.id,
name: rental_house.name,//房源名称
image: rental_house.image,//列表展示图片
residential_id: rental_house.residentialId,//小区id
// residential_id: rental_house.residentialId,//小区id
address: rental_house.address,//详细地址
price: rental_house.price,//价格
discount: rental_house.discount,//折扣
// business_license: rental_house.businessLicense,
tags: rental_house.tags ? eval(rental_house.tags) : [],//房源特点
favourable_info: rental_house.favourableInfo,//优惠信息
tags: rental_house.tags,//房源特点
rental_type: rental_house.rental_type,//租房类型 1整租 2合租 3独栋公寓
favourable_info: rental_house.favourable_info,//优惠信息
introduce: rental_house.description || `该社区亮点:
1、房源介绍:精装公寓,家电齐全,独立卫生间,南通北透,独门独户。
2、房型说明:独门独户,拎包入住,满足各种需求,采光
3、社区配套:健身房、休憩区、小影院、娱乐室、商务区、无人商店、快递柜。
4、房间配套:空调、Wifi、洗衣机、热水器、冰箱、床、衣柜、电脑桌、沙发。`,
room_configuration: ctx.helper.JsonParse(rental_house.roomConfiguration),//房间配置
room_configuration: rental_house.room_configuration,//房间配置
// room_configuration: rental_house.roomConfiguration,//房间配置
notice: rental_house.notice,//入住须知
};
......
......@@ -12,12 +12,15 @@ class searchHistoryService extends Service {
*/
async addSearchHistory(inputParams) {
const { ctx } = this;
if (!ctx.userId) {
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就不做处理
return false;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
key_word: inputParams.key_word,
house_style: inputParams.type,
state: 1,
......@@ -36,8 +39,10 @@ class searchHistoryService extends Service {
const { ctx } = this;
let ret = {
hot_search: {
results: [],
count: 0
results: {
results: [],
count: 0
}
},
search_history: {
results: [],
......@@ -45,21 +50,14 @@ class searchHistoryService extends Service {
}
};
//不管有没有登录获取城市相关的热门搜索
let hotList = await ctx.service.house.v2.hotSearch.getHotSearch(condition);
ret.hot_search = {
results: hotList,
count: hotList.length
}
ret.hot_search.results = await ctx.service.house.v2.hotSearch.getHotSearch(condition);
if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就返回
return ret;
}
//用户的搜索记录
let list = await this.getSearchHistory(condition.type);
ret.search_history = {
results: list,
count: list.length
};
ret.search_history = await this.getSearchHistory(condition.type);
return ret;
}
......
......@@ -91,7 +91,7 @@ class ToolService extends Service {
let notice = '';
let status = 0;
let invest_items = [];
if (balance < 0) {
if (balance <= 0) {
status = 2;//完全有能力买到房
notice = '您的资金已满足本项目首付条件,还有更多项目在您预算范围内。一键预约,轻松看房!';
return { status, notice, invest_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