Commit 3299ad37 authored by Hsinli's avatar Hsinli

addd

parent 5d600b90
Pipeline #8689 passed with stage
in 12 seconds
'use strict';
const Controller = require('egg').Controller;
class CollectionController extends Controller {
/**
* 关注
*/
async addCollection() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: {
type: 'integer',
required: true,
},
type: {
type: 'integer',
required: true,
}
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.collection.addCollection(inputParams);
ctx.success(ret);
}
/**
* 获取关注列表
*/
async getCollectionList() {
const { ctx } = this;
let ret = await ctx.service.house.v2.collection.getCollectionList();
ctx.success(ret);
}
async unCollection() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: {
type: 'integer',
required: true,
},
type: {
type: 'integer',
required: true,
}
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.collection.unCollection(inputParams);
ctx.success(ret);
}
}
module.exports = CollectionController;
'use strict';
const Controller = require('egg').Controller;
class MineController extends Controller {
/**
* 获取我的信息
*/
async getMineInfo() {
const { ctx } = this;
let ret = await ctx.service.house.v2.mine.getMineInfo();
ctx.success(ret);
}
}
module.exports = MineController;
'use strict';
const Controller = require('egg').Controller;
class NewHouseController extends Controller {
/**
* 根据筛选条件获得新房列表
*/
async getNewHouseList() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
page: { type: 'string', required: false },//页面
page_size: { type: 'string', required: false },//条数
area_code: { type: 'object', required: false },//区域
unit_price: { type: 'object', required: false },//价格
total_price: { type: 'object', required: false },//总价
area: { type: 'object', required: false },//面积
house_type: { type: 'string', required: false },//房型
//通过type选择指定内容 全部all 在售sale 最近开盘open 优惠favourtable 首页home,和上面的筛选项互斥
type: { type: 'string', required: false },//
};
ctx.validate(rule, inputParams);
let ret = {};
ret = await ctx.service.house.v2.newHouse.getNewHouseList(inputParams);
ctx.success(ret);
}
/**
* 新房具体信息
*/
async getNewHouse() {
const { ctx } = this;
let inputParams = ctx.params;
const ret = await ctx.service.house.v2.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;
'use strict';
const Controller = require('egg').Controller;
class OrderController extends Controller {
/**
* 预约
*/
async addOrder() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: {
type: 'integer',
required: true,
},
type: {
type: 'integer',
required: true,
},
name: {
type: 'string',
required: true,
},
phone: {
type: 'string',
required: true,
},
time: {
type: 'string',
required: true,
},
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.order.addOrder(inputParams);
ctx.success(ret);
}
/**
* 获取预约列表
*/
async getOrderList() {
const { ctx } = this;
let ret = await ctx.service.house.v2.order.getOrderList();
ctx.success(ret);
}
}
module.exports = OrderController;
'use strict';
const Controller = require('egg').Controller;
class searchHistoryController extends Controller {
/**
* 获取预约列表
*/
async getSearchHistory() {
const { ctx } = this;
//获取租房2和新房1的搜索记录
let ret = {};
let type = [1, 2];
for (let i in type) {
let tag = type[i] === 1 ? 'new_house' : 'rental_house';
ret[tag] = await ctx.service.house.v2.searchHistory.getSearchHistoryList(type[i]);
}
ctx.success(ret);
}
/**
* 清除搜索记录
*/
async cleanSearchHistory() {
const { ctx } = this;
let inputParams = ctx.params;
const rule = {
type: {
type: 'string',
required: true,
}
};
ctx.validate(rule, inputParams);
if (!['new_house', 'rental_house'].includes(inputParams.type)) {
ctx.failed('error type');
}
let type = inputParams.type === 'new_house' ? 1 : 2;
let ret = await ctx.service.house.v2.searchHistory.cleanSearchHistory(type);
ctx.success(ret);
}
}
module.exports = searchHistoryController;
...@@ -35,10 +35,6 @@ module.exports = app => { ...@@ -35,10 +35,6 @@ module.exports = app => {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
valid: {
type: INTEGER,
allowNull: true
},
created_at: { created_at: {
type: DATE, type: DATE,
get() { get() {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
const moment = require('moment'); const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const NewHouse = app.realestateModel.define('new_house', { const NewHouse = app.realestateModel.define('new_house', {
id: { id: {
...@@ -20,6 +20,10 @@ module.exports = app => { ...@@ -20,6 +20,10 @@ module.exports = app => {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
developer_id: {
type: INTEGER,
allowNull: true
},
address: { address: {
type: STRING, type: STRING,
allowNull: true allowNull: true
...@@ -41,11 +45,11 @@ module.exports = app => { ...@@ -41,11 +45,11 @@ module.exports = app => {
allowNull: true allowNull: true
}, },
reference_avg_price: { reference_avg_price: {
type: STRING, type: DECIMAL,
allowNull: true allowNull: true
}, },
reference_total_price: { reference_total_price: {
type: STRING, type: DECIMAL,
allowNull: true allowNull: true
}, },
image: { image: {
...@@ -128,15 +132,107 @@ module.exports = app => { ...@@ -128,15 +132,107 @@ module.exports = app => {
type: STRING, type: STRING,
allowNull: true allowNull: true
}, },
order_num: { order_id: {
type: INTEGER,
allowNull: true
},
is_reality: {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
state: { status: {
type: ENUM('offline', 'online'),
allowNull: true
},
valid: {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
remark: { remark: {
type: STRING,
allowNull: true
},
option_city_code: {
type: INTEGER,
allowNull: true
},
option_district_code: {
type: INTEGER,
allowNull: true
},
option_bizicircle_code: {
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
},
residential_property_fee: {
type: STRING,
allowNull: true
},
residential_property_company: {
type: STRING,
allowNull: true
},
residential_heat_supply_type: {
type: STRING,
allowNull: true
},
residential_water_suppler_type: {
type: STRING,
allowNull: true
},
residential_power_suppler_type: {
type: STRING,
allowNull: true
},
residential_land_area: {
type: DECIMAL,
allowNull: true
},
residential_house_area: {
type: DECIMAL,
allowNull: true
},
residential_area_ratio: {
type: DECIMAL,
allowNull: true
},
residential_green_ratio: {
type: DECIMAL,
allowNull: true
},
residential_arch_type: {
type: INTEGER,
allowNull: true
},
residential_nearby: {
type: TEXT,
allowNull: true
},
sale_province: {
type: INTEGER,
allowNull: true
},
sale_city: {
type: INTEGER,
allowNull: true
},
sale_area: {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
...@@ -163,7 +259,7 @@ module.exports = app => { ...@@ -163,7 +259,7 @@ module.exports = app => {
const date = this.getDataValue('created_at'); const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined; return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
}, },
} },
}, { }, {
timestamps: false, timestamps: false,
tableName: 'new_house', tableName: 'new_house',
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
const moment = require('moment'); const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const NewHouseType = app.realestateModel.define('new_house_type', { const NewHouseType = app.realestateModel.define('new_house_type', {
id: { id: {
...@@ -56,7 +56,11 @@ module.exports = app => { ...@@ -56,7 +56,11 @@ module.exports = app => {
type: DECIMAL, type: DECIMAL,
allowNull: true allowNull: true
}, },
state: { status: {
type: ENUM('offline', 'online'),
allowNull: true
},
valid: {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
...@@ -93,65 +97,65 @@ module.exports = app => { ...@@ -93,65 +97,65 @@ module.exports = app => {
tableName: 'new_house_type', tableName: 'new_house_type',
}); });
NewHouseType.one = async (data) => { NewHouseType.one = async (data) => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
return await NewHouseType.findOne({ return await NewHouseType.findOne({
attributes: attributes, attributes: attributes,
where: where, where: where,
}); });
} }
NewHouseType.all = async (data) => { NewHouseType.all = async (data) => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
const order = data.order ? data.order : []; const order = data.order ? data.order : [];
return await NewHouseType.findAll({ return await NewHouseType.findAll({
attributes: attributes, attributes: attributes,
where: where, where: where,
order, order,
}); });
} }
NewHouseType.list = async (data = {}) => { NewHouseType.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10; const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1; const page = data.page ? data.page : 1;
const order = data.order ? data.order : []; const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
const condition = { const condition = {
offset: (page - 1) * limit, offset: (page - 1) * limit,
limit, limit,
where: where, where: where,
order: order, order: order,
attributes: attributes, attributes: attributes,
}; };
const { count, rows } = await NewHouseType.findAndCountAll(condition); const { count, rows } = await NewHouseType.findAndCountAll(condition);
return { page, count, rows }; return { page, count, rows };
} }
NewHouseType.add = async (data) => { NewHouseType.add = async (data) => {
try { try {
//返回promise对象实力 instance //返回promise对象实力 instance
const res = await NewHouseType.create(data); const res = await NewHouseType.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null //从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id; return res.id;
} catch (error) { } catch (error) {
throw (error); throw (error);
}
} }
}
NewHouseType.edit = async (data) => {
NewHouseType.edit = async (data) => {
const where = data.where;
const params = data.params; const where = data.where;
try { const params = data.params;
return res = await NewHouseType.update(params, { where: where }) try {
} catch (error) { return res = await NewHouseType.update(params, { where: where })
throw (error); } catch (error) {
} throw (error);
} }
}
return NewHouseType; return NewHouseType;
......
...@@ -50,10 +50,6 @@ module.exports = app => { ...@@ -50,10 +50,6 @@ module.exports = app => {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
valid: {
type: INTEGER,
allowNull: true
},
created_at: { created_at: {
type: DATE, type: DATE,
get() { get() {
......
...@@ -31,10 +31,6 @@ module.exports = app => { ...@@ -31,10 +31,6 @@ module.exports = app => {
type: INTEGER, type: INTEGER,
allowNull: true allowNull: true
}, },
valid: {
type: INTEGER,
allowNull: true
},
created_at: { created_at: {
type: DATE, type: DATE,
get() { get() {
......
...@@ -57,4 +57,27 @@ module.exports = app => { ...@@ -57,4 +57,27 @@ module.exports = app => {
//足迹 //足迹
router.get('/v2/foot_print/list', 'house.v2.footPrint.getFootPrintList');//用户浏览记录列表 router.get('/v2/foot_print/list', 'house.v2.footPrint.getFootPrintList');//用户浏览记录列表
};
//新房
router.post('/v2/new_house/list', 'house.v2.newHouse.getNewHouseList');//根据条件筛选列表
router.get('/v2/new_house/:id', 'house.v2.newHouse.getNewHouse');//新房具体信息
router.get('/v2/new_house/options/:city_code', 'house.v2.options.getNewHouseOptions');//筛选项信息
//关注
router.post('/v2/collection', loginAuth, 'house.v2.collection.addCollection');//关注
router.get('/v2/collection/list', loginAuth, 'house.v2.collection.getCollectionList');//关注列表
router.put('/v2/collection', loginAuth, 'house.v2.collection.unCollection');//取消关注
//预约
router.post('/v2/order', loginAuth, 'house.v2.order.addOrder');//预约
router.get('/v2/order/list', loginAuth, 'house.v2.order.getOrderList');//预约列表
//搜索历史
router.get('/v2/search_history', 'house.v2.searchHistory.getSearchHistory');//搜索历史
router.put('/v2/search_history/:type', 'house.v2.searchHistory.cleanSearchHistory');//用户点击清除搜索记录
//我的
router.get('/v2/mine', 'house.v2.mine.getMineInfo');//获取用户的头像昵称和关注等信息
};
\ No newline at end of file
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class CollectionService extends Service {
/**
* 添加关注
* @param {object} inputParams
*/
async addCollection(inputParams) {
const { ctx } = this;
let filter = {
where: {
state: 1,
house_style: inputParams.type,
connect_id: inputParams.id,
user_id: ctx.userId,
}
}
let collectionHistory = await ctx.realestateModel.Collection.one(filter);
if (collectionHistory.length > 0) {
ctx.failed('已经关注过啦');
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
house_style: inputParams.type,
connect_id: inputParams.id,
state: 1,
}
let ret = await ctx.realestateModel.Collection.add(data);
return { id: ret.id };
}
/**
* 取消关注
* @param {object} inputParams
*/
async unCollection(inputParams) {
const { ctx } = this;
let ret = { status: true };
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let filter = {
where: {
state: 1,
house_style: inputParams.type,
connect_id: inputParams.id,
user_id: ctx.userId,
}
}
let collectionHistory = await ctx.realestateModel.Collection.one(filter);
if (collectionHistory.length > 0) {
let filter = {
params: { state: 0 },
where: { connect_id: inputParams.id }
}
await ctx.realestateModel.Collection.edit(filter);
}
return ret;
}
/**
* 获取用户关注信息
* @param {object} inputParams
*/
async getCollection(inputParams) {
const { ctx } = this;
if (!inputParams.hasOwnProperty('type')) {
ctx.failed("empty house type");
}
if (!inputParams.hasOwnProperty('id')) {
ctx.failed("empty house id");
}
if (!ctx.userId) {
return [];
}
let filter = {
where: {
state: 1,
house_style: inputParams.type,
connect_id: inputParams.id,
user_id: ctx.userId,
}
}
let ret = await ctx.realestateModel.Collection.all(filter);
return ret;
}
/**
* 获取关注列表 保留最近6个月的记录,条数不超过50条
* @param {object} condition
*/
async getCollectionList() {
const { ctx } = this;
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: 1,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
}
let list = [];
let collectionList = await ctx.realestateModel.Collection.all(filter);
if (collectionList.length > 0) {
//整理所有收藏
let taskList = [];
for (let i in collectionList) {
if (collectionList[i].house_style === 1) {//1新房2租房 后续根据情况添加
taskList[i] = ctx.realestateModel.NewHouse.one(collectionList[i].connect_id);
} else {
taskList[i] = ctx.realestateModel.RentalHouse.one(collectionList[i].connect_id);
}
}
let retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
//数据整理
for (let j in retList) {
let type = collectionList.results[j].house_style;
let tmp = {
id: retList[j].id,
name: retList[j].name,
address: retList[j].address,
tags: retList[j].tags ? eval(retList[j].tags) : [],
image: retList[j].image,
area: type === 1 ? retList[j].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 : '',
};
list.push(tmp);
}
}
let ret = {
results: list,
count: list.length
};
return ret;
}
/**
* 给我的页面使用 只需要count
*/
async getCollectionCount() {
const { ctx } = this;
if (!ctx.userId) {
return { count: 0 };
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate },
},
order: [['created_at', 'desc']]
}
let collectionList = await ctx.realestateModel.Collection.all(filter);
let ret = {
count: collectionList.length
};
return ret;
}
}
module.exports = CollectionService;
...@@ -102,32 +102,23 @@ class FootPrintService extends Service { ...@@ -102,32 +102,23 @@ class FootPrintService extends Service {
* 我的-获取用户足迹个数 * 我的-获取用户足迹个数
*/ */
async getFootPrintCount() { async getFootPrintCount() {
const { ctx, service } = this; const { ctx } = this;
if (!ctx.userId) { if (!ctx.userId) {
return { count: 0 }; return { count: 0 };
} }
const filter = { const filter = {
pageIndex: 1, page: 1,
pageSize: 50, limit: 50,
queryConditions: [{ where: {
key: "state", state: 1,
value: 1, user_id: ctx.userId,
operator: "equal"
}, {
key: "userId",
value: ctx.userId,
operator: "equal"
}, },
], order: [['created_at', 'desc']]
orderConditions: [{
key: 'createdAt',
orderSequence: 'desc',
},],
} }
const foot_prints_results = await service.houseCommon.footPrint.all(filter); const footPrintsResults = await realestateModel.footPrint.all(filter);
let ret = { let ret = {
count: foot_prints_results.rowCount count: footPrintsResults.length
}; };
return ret; return ret;
} }
......
'use strict';
const Service = require('egg').Service;
class MineService extends Service {
/**
* 获取我的信息
*/
async getMineInfo() {
const { ctx, service } = this;
let ret = {
login: false,
user: {
nickname: '',
avatar: '',
phone: ''
},
classification: {
foot_print: {
count: 0,
name: '浏览足迹'
},
collection: {
count: 0,
name: '关注的房产'
},
order: {
count: 0,
name: '预约记录'
},
}
}
if (!ctx.userId) {
return ret;
}
let appUserInfo = await this.getAppUserInfo();
ctx.logger.info('appUserInfo:' + JSON.stringify(appUserInfo));
let footPrintList = await service.house.v2.footPrint.getFootPrintCount();
let collectionList = await service.house.v2.collection.getCollectionCount();
let orderList = await service.house.v2.order.getOrderCount();
let phone = appUserInfo.user.phone || '';
if (phone.length > 0) {
phone = phone.substring(0, 3) + '****' + phone.substring(7, 11);
}
ret.login = true;
ret.user.nickname = appUserInfo.nickname || '';
ret.user.avatar = appUserInfo.avatar || '';
ret.user.phone = phone;
ret.classification.foot_print.count = footPrintList.count;
ret.classification.collection.count = collectionList.count;
ret.classification.order.count = orderList.count;
return ret;
}
/**
* 获取用户信息
*/
async getAppUserInfo() {
const { ctx } = this;
let appUserId = ctx.appUserId;
const result = await ctx.helper.send_request(this.config.USER_CENTER_API_URI + '/v1/appusers/' + appUserId, {}, { method: 'GET', dataType: 'json' });
const ret = result.status === 200 ? result.data : {};
if (ret.avatar && ret.avatar.indexOf('http') === -1) {
ret.avatar = this.config.CDN_BASE_URL + ret.avatar;
}
if (ret.avatar && ret.avatar !== null) {
ret.avatar = ret.avatar.replace(/^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*/i, 'https://r.51gjj.com');
}
return ret;
}
}
module.exports = MineService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
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 NewHouseService extends Service {
/**
* 新房信息
* @param {string} id 新房id
*/
async getNewHouse(id) {
const { ctx } = this;
//新房楼盘基本信息
let newHouseInfo = await ctx.realestateModel.NewHouse.one({ where: { id: id } });
if (newHouseInfo === null) {
return {};
}
//开发商信息
let developerInfoTask = ctx.realestateModel.Developer.one({ where: { id: newHouseInfo.developer_id } });
//新房的户型信息
let houseTypeFilter = {
where: {
new_house_id: newHouseInfo.id,
status: 'online',
valid: 1
}
}
let newHouseTypeInfoTask = ctx.realestateModel.NewHouseType.all(houseTypeFilter);
//图片
let filter = {
pageIndex: 1,
pageSize: 999,
where: {
status: 'online',
valid: 1,
type: 1,
connect_id: id,
}
}
let newHouseImagesTask = ctx.realestateModel.HouseImage.all(filter);
//是否关注
let collectionTask = ctx.service.house.collection.getCollection({ type: 1, id: id });
//获取每个任务的数据
const retList = await Promise.all([developerInfoTask, newHouseTypeInfoTask, newHouseImagesTask, collectionTask]).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
let developerInfo = retList[0];
let newHouseTypeInfo = retList[1];
let newHouseImages = retList[2];
let collection = retList[3];
newHouseInfo.developer = developerInfo;
newHouseInfo.newHouseType = newHouseTypeInfo;
//对楼盘信息进行整理
let newHouseFormat = await this.formatNewHouse(newHouseInfo);
//图片信息整理
let images = [];
if (newHouseImages.length > 0) {
for (let i in newHouseImages) {
let image = {
id: newHouseImages[i].id,
path: newHouseImages[i].path,
description: newHouseImages[i].description,
}
images.push(image);
}
}
//整理户型信息
let newHouseType = await this.formatNewHouseTypeList(newHouseInfo);
let ret = {
house_basic: newHouseFormat,
house_images: images,
house_types: newHouseType,
collection: collection.length > 0 ? true : false,
}
// await ctx.service.house.footPrint.addFootPrint({ id: id, type: 1 });//添加用户足迹记录
return ret;
}
/**
* 通过NewHouseId获取新房户型信息
* @param {*} id
*/
async getNewHouseTypeList(id) {
const { ctx } = this;
let filter = {
pageIndex: 1,
pageSize: 999,
where: {
status: 'online',
valid: 1,
new_house_id: id,
}
}
let newHouseTypeList = await ctx.realestateModel.NewHouseType.all(filter);
let ret = await formatNewHouseTypeList(newHouseTypeList);
return ret;
}
/**
* 新房数据整理
* @param {object} data
*/
async formatNewHouse(data) {
const { ctx } = this;
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(',');
}
nearBy += subTemp + ';';
}
}
//房型面积处理
let newHouseTypeList = data.newHouseType;
let typeArea = {
min: 0,
max: 0
};
if (newHouseTypeList.length > 0) {
for (let i in newHouseTypeList) {
typeArea.min = typeArea.min === 0 ? newHouseTypeList[i].area : (newHouseTypeList[i].area < typeArea.min ? newHouseTypeList[i].area : typeArea.min);
typeArea.max = typeArea.max === 0 ? newHouseTypeList[i].area : (newHouseTypeList[i].area > typeArea.max ? newHouseTypeList[i].area : typeArea.max);
}
}
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);
if (!gps_result.lat || !gps_result.lng) {
address = city_name + county_name + region_name;
gps_result = await ctx.helper.getGPS(address, city_name);
}
let longitude = 0;
let latitude = 0;
if (gps_result) {
longitude = gps_result.lng;
latitude = gps_result.lat;
}
ret.basic = {
id: data.id,
name: data.name,//标题
description: data.description || '',//描述
tags: data.tags ? eval(data.tags) : [],//项目特色
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] || '',//物业类型
}
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,//建筑面积
decoration: decorationType[data.decoration_type] || '',//装修情况,1 毛坯,2简装,3精装
green_ratio: Number(data.green_ratio),//绿化
area_ratio: Number(data.area_ratio),//容积
address: data.address,//地址
longitude: longitude,//经度
latitude: latitude,//纬度
}
ret.detail = {
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_right_years: data.residential_property_right_years,//产权年限
build_type: archType[data.residential_arch_type] || '',//建筑类型 1 板楼 2塔楼'
decoration: decorationType[data.decoration_type] || '',//装修情况,1 毛坯,2简装,3精装
},
sale: {
sale_type: saleType[data.sale_type] || '',//销售状态 0未开售,1售罄,2预售,3在售
address: data.address,//地址
sale_address: data.sale_address,//售楼地址
developer: data.developer ? data.developer.name : '',//开发商
open_date: data.open_date,//开盘时间
due_date: ['0000-00-00 00:00:00', ''].includes(data.due_date) ? '--' : data.due_date,//交房时间
},
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),//绿化率
property_fee: data.residential_property_fee,//物业费用
property_company: data.residential_property_company,//物业公司
plan_rooms: data.plan_rooms,//规划户数
plan_parks: data.plan_parks,//车位情况
heat_supply_type: data.residential_heat_supply_type,//供暖方式
water_supply_type: data.residential_water_suppler_type,//供水方式
power_supply_type: data.residential_power_suppler_type,//供电方式
near_by: nearBy,//周边规划
},
permit: {
pre_sale_permit: data.pre_sale_permit,//预售证
pre_sale_permit_date: data.pre_sale_permit_date,//发证时间
building_numbers: data.building_numbers,//绑定楼栋
}
}
}
return ret;
}
/**
* 对newHouseTypeList格式化
* @param {object} newHouseTypeList
*/
async formatNewHouseTypeList(newHouseInfo) {
const { ctx } = this;
let newHouseTypeList = newHouseInfo.newHouseType;
//数据格式化
let retList = [];
if (newHouseTypeList.length > 0) {
let taskList = [];
for (let i in newHouseTypeList) {
newHouseTypeList[i].house_type = newHouseInfo.house_type;
taskList[i] = this.formatNewHouseType(newHouseTypeList[i]);
}
retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
}
//将楼盘的户型按照户型分组
let typeFormat = {};
for (let i in retList) {
let type = retList[i].type;
if (!typeFormat.hasOwnProperty(type)) {
typeFormat[type] = {
name: HOUSE_TYPE[type].name,
results: [],
count: 0
};
}
typeFormat[type].results.push(retList[i]);
typeFormat[type].count++;
}
let classification = [];
for (let i in typeFormat) {
classification.push(typeFormat[i]);
}
let ret = {
all: {
name: '全部',
results: retList,
count: retList.length
},
classification: classification
};
return ret;
}
/**
* newHouseType数据整理
* @param {object} data
*/
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] || '',
image: data.image,
apartment: data.apartment,//户型,如4室2厅3卫
sale_type: saleType[data.sale_type] || '',
area: Number(data.area),//面积
orientation: data.orientation,//朝向
num: data.num,//房源数量
price: data.price === 0 ? '--' : data.price,//价格
discount: Number(data.discount),//折扣
tag: data.tags ? eval(data.tags) : [],//特点
}
}
return ret;
}
/**
* 新房根据条件筛选
* @param {*} condition
*/
async getNewHouseList(condition) {
const { ctx } = this;
let types = ['all', 'sale', 'open', 'favourable', 'home'];
let type = (condition.hasOwnProperty('type') && types.includes(condition.type)) ? condition.type : '';
let page = Number(condition.page) || 1;
let pageSize = Number(condition.page_size) || 30;
let filter = {
page: page,
limit: pageSize,
where: {
status: 'online',
valid: 1
},
order: [],
}
//根据筛选项增加不同的指定类型
if (condition.hasOwnProperty('type') && condition.type !== '') {
if (type === 'home') {
//为您推荐只展示50条在售楼盘的数据,根据排序序号取数,数字小的排在前面,数字一样的情况下根据时间逆序排列,时间也一样的情况下随机排列;
filter.limit = Number(condition.page_size) || 50;
filter.order.push(['order_id', 'desc'], ['created_at', 'desc']);
} else if (type === 'all') {
filter.order.push(['sale_type', 'desc']);
} else if (type === 'sale') {
//点击在售楼盘进入列表页面且只展示当前销售状态为在售的楼盘
filter.where.sale_type = 3;
} else if (type === 'open') {
//只展示最近三个月内开盘的楼盘,往前追溯三个月,列表单次加载30条楼盘数据,滑到底部再次加载30条
let endDate = moment().subtract(90, 'days').format('YYYY-MM-DD HH:mm:ss');
filter.where.open_date = { $gt: endDate };
filter.order.push(['sal_type', 'desc']);
} else if (type === 'favourable') {
//点击优惠好盘只展示有优惠的楼盘,列表单次加载30条楼盘数据,滑到底部再次加载30条
filter.where.favourable_info = { $not: null };
filter.order.push(['sale_type', 'desc']);
}
}
//是否有值来增加筛选项
if (condition.unit_price && condition.unit_price.hasOwnProperty('min') && condition.unit_price.hasOwnProperty('max')) {//单价
filter.where.reference_avg_price = { $between: [condition.unit_price.min, condition.unit_price.max] };
}
//里面的min和max也需要判断
if (condition.total_price && condition.total_price.hasOwnProperty('min') && condition.total_price.hasOwnProperty('max')) {//总价
filter.where.reference_total_price = { $between: [condition.total_price.min, condition.total_price.max] };
}
//根据户型的面积筛选 TODO
// if (condition.area && condition.area.hasOwnProperty('min') && condition.area.hasOwnProperty('max')) {
// filter.where.area = { $between: [condition.area.min, condition.area.max] };
// }
if (condition.house_type) {//户型
filter.where.type = condition.house_type;
}
if (condition.name) {//关键词搜索 模糊查询
//增加搜索历史
let addHistory = {
type: 1,
key_word: condition.name
};
await ctx.service.house.searchHistory.addSearchHistory(addHistory);
filter.where.name = { $like: '%' + condition.name + '%' }
}
if (condition.area_code) {//城市\区域\商圈筛选
if (condition.area_code.hasOwnProperty('city_code') && condition.area_code.city_code !== '') {
filter.where.option_city_code = condition.area_code.city_code;
}
if (condition.area_code.hasOwnProperty('district_code') && condition.area_code.district_code !== '') {
filter.where.option_district_code = condition.area_code.district_code;
}
if (condition.area_code.hasOwnProperty('bizcircle_code') && condition.area_code.bizcircle_code !== '') {
filter.where.option_bizicircle_code = condition.area_code.bizcircle_code;
}
}
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,
};
list.push(tmp);
}
}
let ret = {
results: list,
count: newHouseList.count
};
return ret;
}
}
module.exports = NewHouseService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class OrderService extends Service {
/**
* 添加预约信息
* @param {object} inputParams
*/
async addOrder(inputParams) {
const { ctx, service } = this;
let filter = {
where: {
state: 1,
user_id: ctx.userId,
connect_id: inputParams.id,
house_style: inputParams.type,
},
order: [['created_at', 'desc']],
}
let orderHistory = await ctx.realestateModel.Order.all(filter);
if (orderHistory.length > 0) {
let ret = {
id: orderHistory[0].id,
msg: '已经预约过',
};
return ret;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
house_style: inputParams.type,
connect_id: inputParams.id,
name: inputParams.name,
phone: inputParams.phone,
order_at: inputParams.time,
state: 1,
};
let ret = await ctx.realestateModel.Order.add(data);
return { id: ret.id, msg: '预约成功' };
}
/**
* 获取预约列表 保留最近6个月的记录,条数不超过50条
*/
async getOrderList() {
const { ctx, service } = this;
if (!ctx.userId) {
return {
results: [],
count: 0
};
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']]
}
let list = [];
let orderList = await ctx.realestateModel.Order.all(filter);
if (orderList.length > 0) {
//整理所有预约记录
let taskList = [];
for (let i in orderList) {
if (orderList[i].houseStyle === 1) {
taskList[i] = ctx.realestateModel.NewHouse.one(orderList[i].connectId);
} else {
taskList[i] = ctx.realestateModel.RentalHousel.one(orderList[i].connectId);
}
}
let retList = await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
//数据整理
for (let j in retList) {
let type = orderList[j].house_style;
let tmp = {
id: retList[j].id,
name: retList[j].name,
address: retList[j].address,
tags: retList[j].tags ? eval(retList[j].tags) : [],
image: retList[j].image,
area: type === 1 ? retList[j].house_area : '',
price: type === 1 ? (Number(retList[j].reference_avg_price) === 0 ? '--' : 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',
corner: type === 1 ? retList[j].cornerMarker : '',
};
list.push(tmp);
}
}
let ret = {
results: list,
count: list.length
};
return ret;
}
/**
* 我的-获取预约个数
*/
async getOrderCount() {
const { ctx } = this;
if (!ctx.userId) {
return { count: 0 };
}
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']]
}
let orderList = await ctx.realestateModel.Order.all(filter);
let ret = {
count: orderList.length
};
return ret;
}
}
module.exports = OrderService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class searchHistoryService extends Service {
/**
* 添加搜索历史
* @param {object} inputParams
*/
async addSearchHistory(inputParams) {
const { ctx } = this;
if (!ctx.userId) {
return false;
}
let data = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
key_word: inputParams.key_word,
house_style: inputParams.type,
state: 1,
};
let ret = await ctx.realestateModel.SearchHistory.add(data);
return { id: ret.id };
}
/**
* 获取搜索历史
* 历史记录取用户最近6个月的搜索记录,去重处理,条数不超过50条
* 排序根据搜索时间逆序排列,距离当前时间近的排在前面,重复搜索的关键词取最近一次的搜索时间进行排序
* 如果没有搜索记录的就不显示搜索词
*/
async getSearchHistoryList(type) {
const { ctx } = this;
let ret = {
results: [],
count: 0
};
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就返回空
return ret;
}
let endDate = moment().subtract(180, 'days').format('YYYY-MM-DD HH:mm:ss');
let filter = {
page: 1,
limit: 50,
where: {
state: 1,
user_id: ctx.userId,
created_at: { $gt: endDate }
}
}
if (type) {
filter.where.house_style = type;
}
let list = [];
let searchHistoryList = await ctx.realestateModel.SearchHistory.all(filter);
if (searchHistoryList.length > 0) {
for (let i in searchHistoryList) {
if (list.indexOf(searchHistoryList[i].keyWord) === -1) {
list.push(searchHistoryList[i].keyWord);
}
}
}
ctx.logger.info(list);
ret = {
results: list,
count: list.length
};
return ret;
}
/**
* 用户点击清除搜索记录
*/
async cleanSearchHistory(type) {
const { ctx } = this;
let ret = { status: true };
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let filter = {
where: {
state: 1,
user_id: ctx.userId,
house_style: type
}
}
let searchHistoryList = await ctx.realestateModel.SearchHistory.all(filter);
if (searchHistoryList.length > 0) {
let updateFilter = {
params: { state: 0 },
where: {
house_style: type,
user_id: ctx.userId
}
}
await ctx.realestateModel.SearchHistory.edit(updateFilter);
}
return ret;
}
}
module.exports = searchHistoryService;
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