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

v2 rental house fix

parent ff5bccaa
Pipeline #8609 passed with stage
in 12 seconds
'use strict';
const Controller = require('egg').Controller;
class FootPrintController extends Controller {
/**
* 获取足迹列表
*/
async getFootPrintList() {
const { ctx } = this;
let ret = await ctx.service.house.v2.footPrint.getFootPrintList();
ctx.success(ret);
}
}
module.exports = FootPrintController;
'use strict';
const Controller = require('egg').Controller;
class OptionsController extends Controller {
async getOptions() {
const { ctx } = this;
const input_parmas = ctx.params;
const rule = {
city_code: { type: 'string', required: true }
}
ctx.validate(rule, input_parmas);
const city_code = input_parmas.city_code;
const ret = await ctx.service.house.v2.option.getOptions(city_code);
ctx.success(ret);
}
/**
* 获取新房的筛选项
*/
async getNewHouseOptions() {
const { ctx } = this;
const input_parmas = ctx.params;
const rule = {
city_code: { type: 'string', required: true }
}
ctx.validate(rule, input_parmas);
const city_code = input_parmas.city_code;
const ret = await ctx.service.house.v2.option.getNewHouseOptions(city_code);
ctx.success(ret);
}
}
module.exports = OptionsController;
......@@ -11,6 +11,10 @@ module.exports = app => {
primaryKey: true,
autoIncrement: true,
},
app_type_id: {
type: STRING,
allowNull: true,
},
user_id: {
type: STRING,
allowNull: true
......@@ -35,10 +39,6 @@ module.exports = app => {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
......
......@@ -15,6 +15,7 @@ module.exports = app => {
connect_id: INTEGER,
type: INTEGER,
remark: STRING,
description: STRING,
status: ENUM('online', 'offline'),
valid: INTEGER,
created_at: {
......
......@@ -13,10 +13,10 @@ module.exports = app => {
//租房
router.get('/rental_house/home', 'house.rentalHouse.home');//租房首页信息
router.get('/options/:city_code', 'house.options.getOptions');//筛选项信息
router.get('/rental_house/list', 'house.rentalHouse.getRentalHouses');//租房列表
router.post('/rental_house/list', 'house.rentalHouse.getRentalHouses');//租房列表
router.get('/rental_house/info/:rental_house_id', 'house.rentalHouse.getRentalHouse');//租房列表
router.get('/rental_house/info/:rental_house_id', 'house.rentalHouse.getRentalHouse');//租房详情
router.get('/options/:city_code', 'house.options.getOptions');//筛选项信息
//新房
......@@ -51,7 +51,10 @@ module.exports = app => {
//租房列表
router.get('/v2/rental_house/list', 'house.v2.rentalHouse.getRentalHouses');//租房列表
router.post('/v2/rental_house/list', 'house.v2.rentalHouse.getRentalHouses');//租房列表
router.get('/v2/rental_house/info/:rental_house_id', 'house.v2.rentalHouse.getRentalHouse');//住房详情
router.get('/v2/options/:city_code', 'house.v2.options.getOptions');//筛选项信息
//足迹
router.get('/v2/foot_print/list', 'house.v2.footPrint.getFootPrintList');//用户浏览记录列表
};
......@@ -11,11 +11,11 @@ class FootPrintService extends Service {
* @param {object} inputParams {id: XX, type: XX, remark: XX}
*/
async addFootPrint(inputParams) {
const { ctx } = this;
const user_id = ctx.userId;
const app_user_id = ctx.appUserId;
const app_type_id = ctx.appTypeId;
const app_id = ctx.app_id;
if (!user_id || !app_user_id) {
return false;
}
......@@ -23,13 +23,13 @@ class FootPrintService extends Service {
const data = {
user_id: user_id,
app_type_id: app_type_id,
app_id: app_id,
app_user_id: app_user_id,
house_style: inputParams.type,
connectId: inputParams.id,
connect_id: inputParams.id,
state: 1,
remark: inputParams.remark || '',
}
let ret = await ctx.realestateModel.footPrint.add(data);
let ret = await ctx.realestateModel.FootPrint.add(data);
return { id: ret.id };
}
......@@ -52,15 +52,15 @@ class FootPrintService extends Service {
};
}
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']] } });
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']] });
const foot_prints = foot_prints_rows.rows;
const p_houses = [];
for (let i in foot_prints) {
let foot_print = foot_prints[i];
if (foot_print.house_style === 1) {//获取房源信息
p_houses[i] = ctx.realestateModel.NewHouse.one(foot_print.connect_id);
} else {
p_houses[i] = ctx.realestateModel.RentalHouse.one(foot_print.connect_id);
p_houses[i] = ctx.realestateModel.NewHouse.one({ where: { id: foot_print.connect_id } });
} else if (foot_print.house_style === 2) {
p_houses[i] = ctx.realestateModel.RentalHouse.one({ where: { id: foot_print.connect_id } });
}
}
const houses = await Promise.all(p_houses).then(result => {//等待所有异步内容获取完成
......@@ -94,7 +94,7 @@ class FootPrintService extends Service {
});
}
return { results: foot_print_records, count: foot_prints_results.rowCount };
return { results: foot_print_records, count: foot_prints_rows.count };
}
......
'use strict';
const Service = require('egg').Service;
const PRICE_RANGE = [
{ name: '不限', id: -100, min: 0, max: 0 },
{ name: '2000元以下', id: -101, min: 0, max: 2000 },
{ name: '2000元-3000元', id: -102, min: 2000, max: 3000 },
{ name: '3000元-4000元', id: -103, min: 3000, max: 4000 },
{ name: '4000元-5000元', id: -104, min: 4000, max: 5000 },
{ name: '5000元-6000元', id: -105, min: 5000, max: 6000 },
{ name: '6000元-7000元', id: -106, min: 6000, max: 7000 },
{ name: '7000元-8000元', id: -107, min: 7000, max: 8000 },
{ name: '8000元-10000元', id: -108, min: 8000, max: 10000 },
{ name: '10000元以上', id: -109, min: 10000, max: 10000000000000 },
]
const HOUSE_TYPE = [
{ name: '不限', id: -110, min: 0, max: 0, value: 0, },
{ name: '1室', id: -111, min: 1, max: 1, value: 1, },
{ name: '2室', id: -112, min: 2, max: 2, value: 2, },
{ name: '3室', id: -113, min: 3, max: 3, value: 3, },
{ name: '4室', id: -114, min: 4, max: 4, value: 4, },
{ name: '5室', id: -115, min: 4, max: 4, value: 5, },
{ name: '5室以上', id: -116, min: 5, max: 10000, value: 6, },
{ name: '别墅', id: -117, min: 10000, max: 10000000, value: 7, },
]
const NEW_HOUSE_UNIT_PRICE = [
{ name: '不限', id: -118, min: 0, max: 0 },
{ name: '1万以下', id: -119, min: 0, max: 10000 },
{ name: '1万-2万', id: -120, min: 10000, max: 20000 },
{ name: '2万-3万', id: -121, min: 20000, max: 30000 },
{ name: '3万-4万', id: -122, min: 30000, max: 40000 },
{ name: '4万-5万', id: -123, min: 40000, max: 50000 },
{ name: '5万-6万', id: -124, min: 50000, max: 60000 },
]
const NEW_HOUSE_TOTAL_PRICE = [
{ name: '不限', id: -125, min: 0, max: 0 },
{ name: '100万以下', id: -126, min: 0, max: 100 },
{ name: '100万-200万', id: -127, min: 100, max: 200 },
{ name: '200万-300万', id: -128, min: 200, max: 300 },
{ name: '300万-400万', id: -129, min: 300, max: 400 },
{ name: '400万-500万', id: -130, min: 400, max: 500 },
{ name: '500万-600万', id: -131, min: 500, max: 600 },
{ name: '600万-700万', id: -132, min: 600, max: 700 },
{ name: '700万-800万', id: -133, min: 700, max: 800 },
{ name: '800万-900万', id: -134, min: 800, max: 900 },
{ name: '900万-1000万', id: -135, min: 900, max: 1000 },
{ name: '1000万以上', id: -136, min: 1000, max: 999999999 },
]
const NEW_HOUSE_AREA = [
{ name: '不限', id: -137, min: 0, max: 0 },
{ name: '50平米以下', id: -138, min: 0, max: 50 },
{ name: '50平米-70平米', id: -139, min: 50, max: 70 },
{ name: '70平米-90平米', id: -140, min: 70, max: 90 },
{ name: '90平米-120平米', id: -141, min: 90, max: 120 },
{ name: '120平米-150平米', id: -142, min: 120, max: 150 },
{ name: '150平米-200平米', id: -143, min: 150, max: 200 },
{ name: '200平米以上', id: -144, min: 200, max: 999 }
]
class OptionService extends Service {
//获取筛选项
async getOptions(city_code) {
let brands = await this.getDevelopers(city_code);
brands.unshift({ id: -145, name: '不限', image: '', value: 0 });
const house_types = HOUSE_TYPE;
const prices = PRICE_RANGE;
const areas = await this.getAreaOptions(city_code);
return {
result: [
{ name: '品牌', id: -1, path: [], nameShow: '', _children: brands },
{ name: '区域', id: -2, path: [], nameShow: '', _children: areas },
{ name: '价格', id: -3, path: [], nameShow: '', _children: prices },
{ name: '户型', id: -4, path: [], nameShow: '', _children: house_types }]
};
}
//获取新房的筛选项
async getNewHouseOptions(city_code) {
const unit_price = NEW_HOUSE_UNIT_PRICE;
const total_price = NEW_HOUSE_TOTAL_PRICE;
const house_types = HOUSE_TYPE;
const house_area = NEW_HOUSE_AREA;
const areas = await this.getAreaOptions(city_code);
return {
result: [
{ name: '区域', id: -1, path: [], nameShow: '', _children: areas },
{
name: '价格', id: -2, path: [], nameShow: '', _children: [
{ name: '总价', id: -3, _children: total_price },
{ name: '单价', id: -4, _children: unit_price }]
},
{ name: '面积', id: -5, path: [], nameShow: '', _children: house_area },
{ name: '户型', id: -6, path: [], nameShow: '', _children: house_types },
]
};
}
//获取开发商列表
async getDevelopers(city_code) {
const { ctx } = this;
const developers_results = await ctx.service.houseCommon.developer.all({});
const developers = developers_results.results;
const ret = [];
city_code = city_code ? parseInt(city_code) : 330100;
const setting_ret = await ctx.blockModel.Setting.one({ where: { keyword: 'config_fangc_developers' } });
const setting_value = ctx.helper.JsonParse(setting_ret.value);
for (let i in developers) {
const developer = developers[i];
if (setting_value && setting_value[city_code]) {
const setting_developers = setting_value[city_code];
if (setting_developers.includes(developer.id)) {
ret.push({
id: developer.id,
name: developer.name,
image: developer.logo,
value: developer.id,
});
}
}
// if (city_code === 330100 && [2, 4, 5, 6, 7].includes(developer.id)) {
// ret.push({
// id: developer.id,
// name: developer.name,
// image: developer.logo,
// value: developer.id,
// });
// }
// if (city_code === 500000 && [1, 3].includes(developer.id)) {
// ret.push({
// id: developer.id,
// name: developer.name,
// image: developer.logo,
// value: developer.id,
// });
// }
}
return ret;
}
//获取区域商圈
async getAreaOptions(city_code) {
const { ctx } = this;
const city = await ctx.blockModel.City.one({ where: { code: city_code } });
if (!city || !city.name) {
ctx.failed('city code error');
}
const districts = await ctx.blockModel.HouseDistrict.all({ where: { city_id: city.code } });
if (!districts || districts.length === 0) {
return [];
}
const ret = [{ id: 0, name: '不限' }];
for (let j in districts) {
const district = districts[j];
const _children = [{ id: 0, name: '不限' }];
const bizcircles = await ctx.blockModel.HouseBizcircle.all({ where: { district_id: district.id } });
if (!bizcircles || bizcircles.length === 0) {
continue;
}
for (let i in bizcircles) {
const bizcircle = bizcircles[i];
_children.push({
id: bizcircle.id,
name: bizcircle.name,
value: bizcircle.id,
// district_id: bizcircle.district_id,
});
}
ret.push({
id: district.id,
name: district.name,
// city_id: district.city_id,
_children: _children,
value: district.id,
})
}
return ret;
}
}
module.exports = OptionService;
......@@ -64,7 +64,7 @@ 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.houseImage.getAll({ type: 1, connect_id: rental_house_id }, ['id', 'path', 'description']);
const p_house_images = ctx.service.house.v2.houseImage.getAll({ type: 1, 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 => {//等待所有异步内容获取完成
return result;
......@@ -79,6 +79,7 @@ class RentalHouseService extends Service {
house_basic = house_basic[0];
//TODO添加用户足迹,是否关注过房源
await ctx.service.house.v2.footPrint.addFootPrint({ type: 2, id: rental_house_id });
return { house_basic, house_images, house_types, collection: false, };
}
......@@ -98,7 +99,7 @@ class RentalHouseService extends Service {
continue;
}
const house_type_images_results = await ctx.service.houseImage.getAll({ type: 3, connect_id: house_type.id });
const house_type_images = await ctx.service.house.v2.houseImage.getAll({ type: 3, connect_id: house_type.id });
const type = house_type.type || 1;
const house_type_value = HOUSE_TYPE[type];
......@@ -114,7 +115,7 @@ class RentalHouseService extends Service {
name: house_type.name,
area: house_type.area,
price: house_type.price,
images: R.project(['id', 'path', 'description'])(house_type_images_results.results),
images: R.project(['id', 'path', 'description'])(house_type_images),
});
house_types_tmp[type].count++;
}
......
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