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

rental house fix

parent f74f2f65
Pipeline #5911 passed with stage
in 2 seconds
'use strict'; 'use strict';
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
const MAP_POINT_FUNCTION = {
used_house: 'getUsedHouseMapPoint',
new_house: 'getNewHouseMapPoint',
}
class ToolController extends Controller { class ToolController extends Controller {
//获取地图上的点位
async getMapPoint() { async getMapPoint() {
const { ctx } = this; const { ctx } = this;
const input_parmas = ctx.params; const input_parmas = ctx.params;
const rule = { const rule = {
city_code: { type: 'string', required: true }, house_style: { type: 'string', required: true },
area_code: { type: 'string', required: true },
level: { type: 'string', required: true },
} }
ctx.validate(rule, input_parmas); ctx.validate(rule, input_parmas);
const city_code = input_parmas.city_code;
const ret = await ctx.service.house.tool.getMapPoint(city_code); const house_style = input_parmas.house_style;
const area_code = input_parmas.area_code;
const level = input_parmas.level;
let ret = [];
if (house_style === 'used_house') {
ret = await ctx.service.house.tool.getUsedHouseMapPoint(area_code, level);
} else if(house_style === 'new_house'){
ret = await ctx.service.house.tool.getNewHouseMapPoint(area_code, level);
}
ctx.success({ results: ret }); ctx.success({ results: ret });
} }
//生成购房计划
async generateBuyHousePlan() { async generateBuyHousePlan() {
const { ctx } = this; const { ctx } = this;
......
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const HouseInvestPlan = app.blockModel.define('house_invest_map', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
alias: STRING,
condition: STRING,
period: STRING,
items: STRING,
status: INTEGER,
remark: STRING,
valid: INTEGER,
}, {
timestamps: false,
tableName: 'house_invest_map',
freezeTableName: true,
});
HouseInvestPlan.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseInvestPlan.findOne({
attributes: attributes,
where : where,
});
}
HouseInvestPlan.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseInvestPlan.findAll({
attributes: attributes,
where : where,
});
}
HouseInvestPlan.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await HouseInvestPlan.findAndCountAll(condition);
return { page, count, rows };
}
HouseInvestPlan.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HouseInvestPlan.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
HouseInvestPlan.edit = async (data) => {
const where = data.where;
const params = data.params;
HouseInvestPlan.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return HouseInvestPlan;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const HouseNewHousePriceMap = app.blockModel.define('house_new_house_price_map', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
pid: INTEGER,
name: STRING,
longitude: STRING,
latitude: STRING,
count: INTEGER,
}, {
timestamps: false,
tableName: 'house_new_house_price_map',
freezeTableName: true,
});
HouseNewHousePriceMap.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseNewHousePriceMap.findOne({
attributes: attributes,
where : where,
});
}
HouseNewHousePriceMap.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseNewHousePriceMap.findAll({
attributes: attributes,
where : where,
});
}
HouseNewHousePriceMap.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await HouseNewHousePriceMap.findAndCountAll(condition);
return { page, count, rows };
}
HouseNewHousePriceMap.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HouseNewHousePriceMap.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
HouseNewHousePriceMap.edit = async (data) => {
const where = data.where;
const params = data.params;
HouseNewHousePriceMap.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return HouseNewHousePriceMap;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const HouseNewHousePriceMap2 = app.blockModel.define('house_new_house_price_map2', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
pid: INTEGER,
name: STRING,
longitude: STRING,
latitude: STRING,
price: INTEGER,
unit: STRING,
}, {
timestamps: false,
tableName: 'house_new_house_price_map2',
freezeTableName: true,
});
HouseNewHousePriceMap2.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseNewHousePriceMap2.findOne({
attributes: attributes,
where : where,
});
}
HouseNewHousePriceMap2.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseNewHousePriceMap2.findAll({
attributes: attributes,
where : where,
});
}
HouseNewHousePriceMap2.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await HouseNewHousePriceMap2.findAndCountAll(condition);
return { page, count, rows };
}
HouseNewHousePriceMap2.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HouseNewHousePriceMap2.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
HouseNewHousePriceMap2.edit = async (data) => {
const where = data.where;
const params = data.params;
HouseNewHousePriceMap2.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return HouseNewHousePriceMap2;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const HousePriceMap2 = app.blockModel.define('house_price_map2', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
pid: INTEGER,
name: STRING,
spell: STRING,
longitude: STRING,
latitude: STRING,
price: INTEGER,
}, {
timestamps: false,
tableName: 'house_price_map2',
freezeTableName: true,
});
HousePriceMap2.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HousePriceMap2.findOne({
attributes: attributes,
where : where,
});
}
HousePriceMap2.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HousePriceMap2.findAll({
attributes: attributes,
where : where,
});
}
HousePriceMap2.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await HousePriceMap2.findAndCountAll(condition);
return { page, count, rows };
}
HousePriceMap2.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HousePriceMap2.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
HousePriceMap2.edit = async (data) => {
const where = data.where;
const params = data.params;
HousePriceMap2.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return HousePriceMap2;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const HousePriceMap3 = app.blockModel.define('house_price_map3', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
pid: INTEGER,
name: STRING,
spell: STRING,
longitude: STRING,
latitude: STRING,
price: INTEGER,
}, {
timestamps: false,
tableName: 'house_price_map3',
freezeTableName: true,
});
HousePriceMap3.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HousePriceMap3.findOne({
attributes: attributes,
where : where,
});
}
HousePriceMap3.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HousePriceMap3.findAll({
attributes: attributes,
where : where,
});
}
HousePriceMap3.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await HousePriceMap3.findAndCountAll(condition);
return { page, count, rows };
}
HousePriceMap3.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HousePriceMap3.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
HousePriceMap3.edit = async (data) => {
const where = data.where;
const params = data.params;
HousePriceMap3.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return HousePriceMap3;
};
...@@ -3,7 +3,16 @@ ...@@ -3,7 +3,16 @@
const Service = require('egg').Service; const Service = require('egg').Service;
const R = require('ramda'); const R = require('ramda');
const HOUSE_TYPE = [
{ name: '不限', min: 0, max: 0, value: 0, },
{ name: '1室', min: 1, max: 1, value: 1, },
{ name: '2室', min: 2, max: 2, value: 2, },
{ name: '3室', min: 3, max: 3, value: 3, },
{ name: '4室', min: 4, max: 4, value: 4, },
{ name: '5室', min: 4, max: 4, value: 5, },
{ name: '5室以上', min: 5, max: 10000, value: 6, },
{ name: '别墅', min: 10000, max: 10000000, value: 7, },
]
class RentalHouseService extends Service { class RentalHouseService extends Service {
async getRentalHousesByFilter(condition) { async getRentalHousesByFilter(condition) {
...@@ -34,6 +43,13 @@ class RentalHouseService extends Service { ...@@ -34,6 +43,13 @@ class RentalHouseService extends Service {
queryConditions.push({ queryConditions.push({
key: 'rentalHouseType', key: 'rentalHouseType',
value: condition.house_type, value: condition.house_type,
operator: 'contains',
});
}
if (condition.area_name) {
queryConditions.push({
key: 'area_name',
value: condition.area_name,
operator: 'equal', operator: 'equal',
}); });
} }
...@@ -73,7 +89,7 @@ class RentalHouseService extends Service { ...@@ -73,7 +89,7 @@ class RentalHouseService extends Service {
const p_house_images = this.getRentalHouseImages(rental_house_id); const p_house_images = this.getRentalHouseImages(rental_house_id);
//获取房源类型 //获取房源类型
const p_house_types = this.getRentalHouseTypes(rental_house_id); const p_house_types = this.formatRentHouseTypes(house_basic_result.rentalHouseType);
const p_ret = await Promise.all([p_house_images, p_house_types]).then(result => {//等待所有异步内容获取完成 const p_ret = await Promise.all([p_house_images, p_house_types]).then(result => {//等待所有异步内容获取完成
return result; return result;
...@@ -125,6 +141,63 @@ class RentalHouseService extends Service { ...@@ -125,6 +141,63 @@ class RentalHouseService extends Service {
return house_images; return house_images;
} }
//格式化户型数据
async formatRentHouseTypes(house_types) {
if (!Array.isArray(house_types) || house_types.length === 0) {
return [];
}
const { ctx } = this;
let house_types_tmp = {};
let house_type_image_filter = {
pageSize: 10000,
queryConditions: [
{
key: 'state',
value: 1,
operator: 'equal'
},
{
key: 'type',
value: 3,
operator: 'equal',
},
],
};
for (let i in house_types) {
const house_type = house_types[i];
house_type_image_filter.queryConditions.push({
key: 'connectId',
value: house_type.id,
operator: 'equal',
});
const house_type_images_results = await ctx.service.houseCommon.houseImage.all(house_type_image_filter);
const type = house_type.type || 1;
const house_type_value = HOUSE_TYPE[type];
if (!house_types_tmp[type]) {
house_types_tmp[type] = {
name: house_type_value.name,
results: [],
count: 0,
}
}
house_types_tmp[type].results.push({
id: house_type.id,
name: house_type.name,
area: house_type.area,
price: house_type.price,
images: R.project(['id', 'path', 'description'])(house_type_images_results.results),
});
house_types_tmp[type].count++;
}
const ret = [];
for (let i in house_types_tmp) { const item = ret.push(house_types_tmp[i]) }
return ret;
}
//获取房源类型 //获取房源类型
async getRentalHouseTypes(rental_house_id) { async getRentalHouseTypes(rental_house_id) {
...@@ -172,16 +245,23 @@ class RentalHouseService extends Service { ...@@ -172,16 +245,23 @@ class RentalHouseService extends Service {
operator: 'equal', operator: 'equal',
}); });
const house_type_images_results = await ctx.service.houseCommon.houseImage.all(house_type_image_filter); const house_type_images_results = await ctx.service.houseCommon.houseImage.all(house_type_image_filter);
if (!ret[house_type.name] || ret[house_type.name].length === 0) { const type = house_type.type || 1;
ret[house_type.name] = []; const house_type_value = HOUSE_TYPE[type];
if (!ret[type]) {
ret[type] = {
name: house_type_value.name,
results: [],
count: 0,
}
} }
ret[house_type.name].push({ ret[type].results.push({
id: house_type.id, id: house_type.id,
name: house_type.name, name: house_type.name,
area: house_type.area, area: house_type.area,
price: house_type.price, price: house_type.price,
images: R.project(['id', 'path', 'description'])(house_type_images_results.results) images: R.project(['id', 'path', 'description'])(house_type_images_results.results),
}); });
ret[type].count++;
} }
return ret; return ret;
......
...@@ -5,21 +5,61 @@ const Service = require('egg').Service; ...@@ -5,21 +5,61 @@ const Service = require('egg').Service;
class ToolService extends Service { class ToolService extends Service {
async getMapPoint(city_code) { async getNewHouseMapPoint(area_code, level) {
const { ctx } = this;
let map_points = [];
if(level == 1){
map_points = await ctx.blockModel.HouseNewHousePriceMap.all({ where: { pid: area_code } });
} else {
map_points = await ctx.blockModel.HouseNewHousePriceMap2.all({ where: { pid: area_code } });
}
if (!map_points || map_points.length === 0) {
return [];
}
const ret = [];
for (let i in map_points) {
const item = map_points[i];
ret.push({
id: item.id,
name: item.name,
longitude: item.longitude,
latitude: item.latitude,
price: item.price,
unit: item.unit || '元/平',
});
}
return ret;
}
async getUsedHouseMapPoint(area_code, level) {
const { ctx } = this; const { ctx } = this;
const first_tops = await ctx.blockModel.HousePriceMap.all({ where: { pid: city_code } }); let map_points = [];
if (!first_tops || first_tops.length === 0) { if (level == 1) {
map_points = await ctx.blockModel.HousePriceMap.all({ where: { pid: area_code } });
} else if (level == 2) {
map_points = await ctx.blockModel.HousePriceMap2.all({ where: { pid: area_code } });
} else {
map_points = await ctx.blockModel.HousePriceMap3.all({ where: { pid: area_code } });
}
if (!map_points || map_points.length === 0) {
return []; return [];
} }
const ret = []; const ret = [];
for (let i in first_tops) { for (let i in map_points) {
const item = first_tops[i]; const item = map_points[i];
ret.push({ ret.push({
id: item.id, id: item.id,
name: item.name, name: item.name,
longitude: item.longitude, longitude: item.longitude,
latitude: item.latitude, latitude: item.latitude,
price: item.price, price: item.price,
unit: item.unit || '元/平',
}); });
} }
......
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