Commit ee751c1a authored by Hsinli's avatar Hsinli

adddd

parent d88737a2
Pipeline #5769 passed with stage
in 9 minutes 34 seconds
'use strict';
const Controller = require('egg').Controller;
class NewHouseController extends Controller {
/**
* 新房列表
* 全部all 在售sale 最近开盘open 优惠favourtable 首页home
*/
async getNewHouseList() {
const { ctx } = this;
let inputParams = ctx.params;
const ret = await ctx.service.house.newHouse.getNewHouseList(inputParams.type);
ctx.success(ret);
}
/**
* 新房具体信息
*/
async getNewHouse() {
const { ctx } = this;
let inputParams = ctx.params;
const ret = await ctx.service.house.newHouse.getNewHouse(inputParams.id);
ctx.success(ret);
}
/**
* 新房户型信息
*/
async getNewHouseType() {
const { ctx } = this;
let inputParams = ctx.params;
const ret = await ctx.service.house.newHouse.getNewHouseType(inputParams.id);
ctx.success(ret);
}
}
module.exports = NewHouseController;
...@@ -8,4 +8,10 @@ module.exports = app => { ...@@ -8,4 +8,10 @@ module.exports = app => {
router.get('/rental_house', 'house.rentalHouse.getRentalHouses');//租房列表 router.get('/rental_house', 'house.rentalHouse.getRentalHouses');//租房列表
router.get('/rental_house/:rental_house_id', 'house.rentalHouse.getRentalHouse');//租房列表 router.get('/rental_house/:rental_house_id', 'house.rentalHouse.getRentalHouse');//租房列表
//新房
router.get('/new_house/list/:type', 'house.newHouse.getNewHouseList');//列表
router.get('/new_house/:id', 'house.newHouse.getNewHouse');//新房具体信息
router.get('/new_house_type/:id', 'house.newHouse.getNewHouseType');//新房具体信息
}; };
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class NewHouseService extends Service {
/**
* 根据不同筛选获取列表
* @param {*} type 四种默认的按钮筛选 全部all 在售sale 最近开盘open 优惠favourable 首页home
*/
async getNewHouseList(type) {
const { ctx } = this;
let types = ['all', 'sale', 'open', 'favourable', 'home'];
if (!types.includes(type)) {
ctx.failed('error list type');
}
let newHouseList = [];
if (type === 'home') {
//为您推荐只展示50条在售楼盘的数据,根据排序序号取数,数字小的排在前面,数字一样的情况下根据时间逆序排列,时间也一样的情况下随机排列;
let condition = { pageSize: 50 };
newHouseList = await this.getNewHouseByFilter(condition);
} else if (type === 'all') {
} else if (type === 'sale') {
} else if (type === 'open') {
//只展示最近三个月内开盘的楼盘,往前追溯三个月,列表单次加载30条楼盘数据,滑到底部再次加载30条
let endDate = moment().subtract(30, 'days').format('YYYY-MM-DD HH:mm:ss');
let condition = {
queryConditions: [{
key: "openDate",
value: endDate,
operator: "greater"
}],
};
newHouseList = await this.getNewHouseByFilter(condition);
} else if (type === 'favourable') {
//点击优惠好盘只展示有优惠的楼盘,列表单次加载30条楼盘数据,滑到底部再次加载30条
let condition = {
queryConditions: [{
key: "favourableInfo",
value: false,
operator: "isnull"
}],
};
newHouseList = await this.getNewHouseByFilter(condition);
}
return newHouseList;
}
/**
* 新房信息
* @param {string} id 新房id
*/
async getNewHouse(id) {
const { ctx, service } = this;
let newHouseInfo = await service.houseCommon.newHouse.one(id);
let filter = {
pageIndex: 1,
pageSize: 100,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "type",
value: 1,
operator: "equal"
}, {
key: "connectId",
value: id,
operator: "equal"
}],
orderConditions: [],
}
let newHouseImages = await service.houseCommon.houseImage.all(filter);
let images = [];
if (newHouseImages.rowCount > 0) {
for (let i in newHouseImages.results) {
images.push(newHouseImages.results[i].path);
}
}
newHouseInfo.images = images;
//TODO对数据格式化处理
return newHouseInfo;
}
/**
* 通过NewHouseId获取新房户型信息
* @param {*} id
*/
async getNewHouseType(id) {
const { ctx, service } = this;
let filter = {
pageIndex: 1,
pageSize: 999,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "newHouseId",
value: id,
operator: "equal"
}],
orderConditions: [],
}
let newHouseTypeList = await service.houseCommon.newHouseType.all(filter);
//TODO需要根据几居室区分
let ret = {
results: newHouseTypeList.results,
count: newHouseTypeList.rowCount
};
return ret;
}
/**
* 根据筛选条件newHouseType列表来获取newHouse
* @param {*} condition
*/
async getNewHouseByTypeFilter(condition) {
const { ctx, service } = this;
let page = Number(condition.page) || 1;
let pageSize = Number(condition.pageSize) || 30;
let filter = {
pageIndex: page,
pageSize: pageSize,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}],
orderConditions: [{
key: 'orderNum',
orderSequence: 'asc',
},
{
key: 'createdAt',
orderSequence: 'desc',
}],
}
//根是否有值来增加筛选项
if (condition.unitPrice) {//单价
filter.queryConditions.push(
{
key: 'referenceAvgPrice',
value: condition.unitPrice.min,
operator: 'greaterEqual',
},
{
key: 'referenceAvgPrice',
value: condition.unitPrice.max,
operator: 'lessEqual',
}
);
}
if (condition.totalPrice) {//总价
filter.queryConditions.push(
{
key: 'referenceTotalPrice',
value: condition.totalPrice.min,
operator: 'greaterEqual',
},
{
key: 'referenceTotalPrice',
value: condition.totalPrice.max,
operator: 'lessEqual',
}
);
}
if (condition.area) {//面积
filter.queryConditions.push(
{
key: 'area',
value: condition.area.min,
operator: 'greaterEqual',
},
{
key: 'area',
value: condition.area.min,
operator: 'lessEqual',
})
;
}
if (condition.type) {//户型
filter.queryConditions.push({
key: 'Apartment',
value: condition.type,
operator: 'equal',
});
}
let newHouseTypeList = await service.houseCommon.newHouse.all(filter);
let list = [];
if (newHouseTypeList.rowCount !== 0) {
for (let i in newHouseTypeList) {
let newHouseInfo = await service.houseCommon.newHouse.one(newHouseTypeList[i].NewHouseId);
if (newHouseInfo.length > 0) {
let tmp = {
id: newHouseInfo.id,
name: newHouseInfo.name,
address: newHouseInfo.address,
tags: newHouseInfo.tags,
name: newHouseInfo.Image,
}
list.push(tmp);
}
}
}
let ret = {
results: list,
count: list.length
};
return ret;
}
async getNewHouseByFilter(condition) {
const { ctx, service } = this;
let page = Number(condition.page) || 1;
let pageSize = Number(condition.pageSize) || 30;
let filter = {
pageIndex: page,
pageSize: pageSize,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
},],
orderConditions: [{
key: 'orderNum',
orderSequence: 'asc',
},
{
key: 'createdAt',
orderSequence: 'desc',
},],
}
if (condition.hasOwnProperty('queryConditions')) {
filter.queryConditions = filter.queryConditions.concat(condition.queryConditions);
}
if (condition.hasOwnProperty('orderConditions')) {
filter.orderConditions = filter.orderConditions.concat(condition.orderConditions);
}
let newHouseList = await service.houseCommon.newHouse.all(filter);
let list = [];
if (newHouseList.rowCount > 0) {
for (let i in newHouseList.results) {
let tmp = {
id: newHouseList.results[i].id,
name: newHouseList.results[i].name,
address: newHouseList.results[i].address,
tags: newHouseList.results[i].tags,
image: newHouseList.results[i].image,
};
list.push(tmp);
}
}
let ret = {
results: list,
count: list.length
};
return ret;
}
}
module.exports = NewHouseService;
'use strict';
const Service = require('egg').Service;
class NewHouseService extends Service {
//根据Id,获取新房信息表
async one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhouse/' + id, {}, { method: 'GET' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//修改新房信息表
async edit(id, data) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhouse/' + id, data, { method: 'PUT' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//根据Id,删除新房信息表
async delete(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhouse/' + id, {}, { method: 'DELETE' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//获取新房信息表信息(分页)
async all(data) {
const { ctx } = this;
const queryConditions = data.queryConditions;
const sum = queryConditions.length;
for (let i = 0; i < sum; i++) {
if (queryConditions[i].key === 'userId' && queryConditions[i].value.length === 0) {
queryConditions[i].value = true;
queryConditions[i].operator = 'isnull';
}
}
data.queryConditions = queryConditions;
if (Object.keys(data.orderConditions).length === 0) {
data.orderConditions = [{
key: 'createdAt',
orderSequence: 'desc',
}];
}
ctx.logger.info('get_newHouse_filter: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhouse/list', data, { method: 'POST' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//新增新房信息表
async add(data) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhouse/', data, { method: 'POST' });
if (result.status !== 201) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
}
module.exports = NewHouseService;
'use strict';
const Service = require('egg').Service;
class NewHouseTypeService extends Service {
//根据Id,获取新房户型信息表
async one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhousetype/' + id, {}, { method: 'GET' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//修改新房户型信息表
async edit(id, data) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhousetype/' + id, data, { method: 'PUT' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//根据Id,删除新房户型信息表
async delete(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhousetype/' + id, {}, { method: 'DELETE' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//获取新房户型信息表信息(分页)
async all(data) {
const { ctx } = this;
const queryConditions = data.queryConditions;
const sum = queryConditions.length;
for (let i = 0; i < sum; i++) {
if (queryConditions[i].key === 'userId' && queryConditions[i].value.length === 0) {
queryConditions[i].value = true;
queryConditions[i].operator = 'isnull';
}
}
data.queryConditions = queryConditions;
if (Object.keys(data.orderConditions).length === 0) {
data.orderConditions = [{
key: 'createdAt',
orderSequence: 'desc',
}];
}
ctx.logger.info('get_newHouseType_filter: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhousetype/list', data, { method: 'POST' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
//新增新房户型信息表
async add(data) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/newhousetype/', data, { method: 'POST' });
if (result.status !== 201) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
}
module.exports = NewHouseTypeService;
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