Commit 89ab9771 authored by Hsinli's avatar Hsinli

addd

parent 377e3972
Pipeline #5860 passed with stage
in 8 seconds
......@@ -14,12 +14,12 @@ module.exports = app => {
router.get('/new_house_type/:id', 'house.newHouse.getNewHouseType');//新房户型
//预约
router.post('/order', 'house.order.addOrder');//预约
router.get('/order/list', 'house.order.getOrderList');//预约列表
router.post('/order', loginAuth, 'house.order.addOrder');//预约
router.get('/order/list', loginAuth, 'house.order.getOrderList');//预约列表
//收藏
router.post('/collection', 'house.collection.addCollection');//收藏
router.get('/collection/list', 'house.collection.getCollectionList');//收藏列表
router.post('/collection', loginAuth, 'house.collection.addCollection');//收藏
router.get('/collection/list', loginAuth, 'house.collection.getCollectionList');//收藏列表
......
......@@ -12,6 +12,34 @@ class CollectionService extends Service {
*/
async addCollection(inputParams) {
const { ctx, service } = this;
let filter = {
pageIndex: 1,
pageSize: 999,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "userId",
value: ctx.userId,
operator: "equal"
}, {
key: "connectId",
value: inputParams.id,
operator: "equal"
}, {
key: "houseStyle",
value: inputParams.type,
operator: "equal"
},
],
orderConditions: [],
}
let collectionHistory = await service.houseCommon.collection.all(filter);
if (collectionHistory.rowCount > 0) {
ctx.failed('已经关注过啦');
}
let data = {
userId: ctx.userId,
appUserId: ctx.appUserId,
......@@ -21,7 +49,7 @@ class CollectionService extends Service {
remark: inputParams.remark || ''
}
let ret = await service.houseCommon.collection.add(data);
return ret;
return { collection_id: ret.id };
}
......@@ -41,7 +69,7 @@ class CollectionService extends Service {
operator: "equal"
}, {
key: "userId",
value: '33A54829-1262-40B5-BE36-B57A12DA090B',//TODO
value: ctx.userId,
operator: "equal"
},
// {
......
......@@ -58,17 +58,18 @@ class NewHouseService extends Service {
const { ctx, service } = this;
//房产基本信息
let newHouseInfo = await service.houseCommon.newHouse.one(id);
let newHouseFormat = await this.formatNewHouse(newHouseInfo);
//图片
let filter = {
pageIndex: 1,
pageSize: 100,
pageSize: 999,
queryConditions: [{
key: "state",
value: 1,
value: '1',
operator: "equal"
}, {
key: "type",
value: 1,
value: '1',
operator: "equal"
}, {
key: "connectId",
......@@ -78,49 +79,92 @@ class NewHouseService extends Service {
orderConditions: [],
}
let newHouseImages = await service.houseCommon.houseImage.all(filter);
ctx.logger.info(newHouseImages);
let images = [];
if (newHouseImages.rowCount > 0) {
for (let i in newHouseImages.results) {
images.push(newHouseImages.results[i].path);
let image = {
id: newHouseImages.results[i].id,
path: newHouseImages.results[i].path,
description: newHouseImages.results[i].description,
}
images.push(image);
}
}
//户型信息
let newHouseType = await this.getNewHouseType(id);
let ret = {
house_basic: await this.formatNewHouse(newHouseInfo),
house_basic: newHouseFormat,
house_images: images,
house_types: newHouseType.all.results
house_types: newHouseType
}
//TODO对数据格式化处理
return ret;
}
async formatNewHouse(data) {
const { ctx, service } = this;
let ret = {};
if (Object.keys(data) > 0) {
ret = {
if (Object.keys(data).length > 0) {
let residentialInfo = await service.houseCommon.residential.one(data.residentialId);
// let developerInfo = await service.houseCommon.developer.one(data.residentialId);
ret.basic = {
id: data.id,
name: data.name,
residential_id: data.residentialId,
tags: data.tags.split(','),
reference_avg_price: data.referenceAvgPrice,
reference_total_price: data.referenceTotalPrice,
image: data.image,
address: data.address,
discount: data.discount,
description: data.description,
open_date: data.openDate,
open_date: data.openDate,
land_area: data.landArea,
house_area: data.houseArea,
area_ratio: data.areaRatio,
green_ratio: data.greenRatio,
plan_rooms: data.planRooms,
plan_parks: data.planParks,
plan_near_by: data.planNearBy,
pre_sale_permit: data.preSalePermit,
pre_sale_permit_date: data.preSalePermitDate,
building_numbers: data.buildingNumbers
name: data.name,//标题
description: data.description,//描述
tags: data.tags.split(','),//项目特色
favourable_info: data.favourableInfo,//优惠
reference_avg_price: data.referenceAvgPrice,//均价
reference_total_price: data.referenceTotalPrice,//总价
//物业类型
}
ret.info = {
open_date: data.openDate,//开盘时间
due_date: data.dueDate,//交房时间
house_area: data.houseArea,//建筑面积
//装修情况
green_ratio: data.greenRatio,//绿化
area_ratio: data.areaRatio,//容积
address: data.address,//地址
}
ret.detail = {
basic: {
reference_avg_price: data.referenceAvgPrice,//均价
tags: data.tags.split(','),//项目特色
//物业类型
property_right_years: residentialInfo.propertyRightYears || '',//产权年限
//建筑类型
//装修情况
},
sale: {
//销售状态
address: data.address,//地址
//售楼地址
//开发商
open_date: data.openDate,//开盘时间
due_date: data.dueDate,//交房时间
},
residential: {
//占地面积
//建筑面积
area_ratio: data.areaRatio,//容积率
green_ratio: data.greenRatio,//绿化率
property_fee: residentialInfo.PropertyFee || '',//物业费用
property_company: residentialInfo.propertyCompany || '',//物业公司
plan_rooms: data.planRooms,//规划户数
plan_parks: data.planParks,//车位情况
heat_supply_type: residentialInfo.heatSupplyType || '',//供暖方式
water_supply_type: residentialInfo.waterSupplyType || '',//供水方式
power_supply_type: residentialInfo.powerSupplyType || '',//供电方式
near_by: residentialInfo.nearBy || '',//周边规划
},
permit: {
pre_sale_permit: data.preSalePermit,//预售证
pre_sale_permit_date: data.preSalePermitDate,//发证时间
building_numbers: data.buildingNumbers,//绑定楼栋
}
}
}
return ret;
......@@ -147,11 +191,26 @@ class NewHouseService extends Service {
orderConditions: [],
}
let newHouseTypeList = await service.houseCommon.newHouseType.all(filter);
//数据格式化
ctx.logger.info(newHouseTypeList);
let retList = [];
if (newHouseTypeList.rowCount > 0) {
let taskList = [];
for (let i in newHouseTypeList.results) {
taskList[i] = this.formatNewHouseType(newHouseTypeList.results[i]);
}
retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
}
//TODO需要根据几居室区分
let ret = {
all: {
results: newHouseTypeList.results,
count: newHouseTypeList.rowCount
results: retList,
count: retList.count
}
};
return ret;
......@@ -304,6 +363,30 @@ class NewHouseService extends Service {
return ret;
}
async formatNewHouseType(data) {
const { ctx } = this;
let ret = {};
if (Object.keys(data).length > 0) {
ret = {
id: data.id,
newHouseId: data.newHouseId,
type: data.type,//类型,如三居、四居
image: data.image,
house_type: data.houseType,//住宅类型,如住宅,公寓
apartment: data.apartment,//户型,如4室2厅3卫
sale_type: data.saleType,//销售类型,0未开售,1预售,2在售,3售罄
area: data.area,//面积
orientation: data.orientation,//朝向
num: data.num,//房源数量
price: data.price,//价格
discount: data.discount,//折扣
// tag: data.tags.split(','),//特点
}
}
return ret;
}
}
module.exports = NewHouseService;
......@@ -12,6 +12,34 @@ class OrderService extends Service {
*/
async addOrder(inputParams) {
const { ctx, service } = this;
let filter = {
pageIndex: 1,
pageSize: 999,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "userId",
value: ctx.userId,
operator: "equal"
}, {
key: "connectId",
value: inputParams.id,
operator: "equal"
}, {
key: "houseStyle",
value: inputParams.type,
operator: "equal"
},
],
orderConditions: [],
}
let orderHistory = await service.houseCommon.order.all(filter);
if (orderHistory.rowCount > 0) {
ctx.failed('已经预约过');
}
let data = {
userId: ctx.userId,
appUserId: ctx.appUserId,
......@@ -22,9 +50,9 @@ class OrderService extends Service {
orderAt: inputParams.time,
state: 1,
remark: inputParams.remark || ''
}
};
let ret = await service.houseCommon.order.add(data);
return ret;
return { order_id: ret.id };
}
/**
......@@ -42,7 +70,7 @@ class OrderService extends Service {
operator: "equal"
}, {
key: "userId",
value: '33A54829-1262-40B5-BE36-B57A12DA090B',//TODO
value: ctx.userId,
operator: "equal"
},
// {
......
'use strict';
const Service = require('egg').Service;
class ResidentialService extends Service {
async getResidential(id) {
const { ctx, service } = this;
let residentialInfo = await service.houseCommon.residential.one(id);
return residentialInfo;
}
}
module.exports = ResidentialService;
'use strict';
const Service = require('egg').Service;
class ResidentialService extends Service {
//根据Id,获取新房信息表
async one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/residential/' + 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/residential/' + 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/residential/' + 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/residential/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/residential/', 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 = ResidentialService;
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