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

foot print added

parent 29a4a9da
Pipeline #5882 passed with stage
in 4 seconds
'use strict';
const Controller = require('egg').Controller;
class FootPrintController extends Controller {
/**
* 获取足迹列表
*/
async getFootPrintList() {
const { ctx } = this;
let ret = await ctx.service.house.footPrint.getFootPrintList();
ctx.success(ret);
}
}
module.exports = FootPrintController;
......@@ -16,7 +16,7 @@ class RentalHouseController extends Controller {
const device_login_id = ctx.device_login_id;
const headers = {
app_user_id: app_user_id,
device_id: device_id || '610d1ed6-b140-4edd-9f50-f4a7aee525b8',
device_id: device_id || 'f8b3b16b-6901-4a8e-95af-607ec7c47aa8',
device_login_id: device_login_id,
token: token,
uid: user_id,
......
......@@ -4,14 +4,15 @@ module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/house');
const loginAuth = app.middleware.loginAuth({ type: 'new' });//登录中间件
router.get('/tool/:city_code', 'house.tool.getMapPoint');//购房计划地图点位
router.post('/tool/plan', 'house.tool.generateBuyHousePlan');//生成购房计划
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('/tool/:city_code', 'house.tool.getMapPoint');//购房计划地图点位
router.post('/tool/plan', 'house.tool.generateBuyHousePlan');//生成购房计划
//租房
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');//租房列表
//新房
......@@ -30,5 +31,8 @@ module.exports = app => {
//搜索历史
router.get('/search_history', 'house.searchHistory.getsearchHistory');//收藏列表
//足迹
router.get('/foot_print/list', 'house.footPrint.getFootPrintList');//用户浏览记录列表
};
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class FootPrintService extends Service {
/**
* 添加足迹
* @param {object} inputParams {id: XX, type: XX, remark: XX}
*/
async addFootPrint(inputParams) {
const { ctx, service } = this;
const user_id = ctx.userId;
const app_user_id = ctx.appUserId;
if (!user_id || !app_user_id) {
return false;
}
let data = {
userId: user_id,
appUserId: app_user_id,
houseStyle: inputParams.type,
connectId: inputParams.id,
state: 1,
remark: inputParams.remark || ''
}
let ret = await service.houseCommon.footPrint.add(data);
return { id: ret.id };
}
/**
* 获取用户足迹列表 保留最近6个月的记录,条数不超过50条
* @param {object} condition
*/
async getFootPrintList() {
const { ctx, service } = this;
const user_id = ctx.userId;
if (!user_id) {
return {
results: [],
count: 0
};
}
const filter = {
pageIndex: 1,
pageSize: 50,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "userId",
value: user_id,
operator: "equal"
},
],
orderConditions: [{
key: 'createdAt',
orderSequence: 'desc',
},],
}
const foot_prints_results = await service.houseCommon.footPrint.all(filter);
const foot_prints = foot_prints_results.results;
const p_houses = [];
for (let i in foot_prints) {
let foot_print = foot_prints[i];
if (foot_print.houseStyle === 1) {//获取房源信息
p_houses[i] = service.houseCommon.newHouse.one(foot_print.connectId);
} else {
p_houses[i] = service.houseCommon.rentalHouse.one(foot_print.connectId);
}
}
const houses = await Promise.all(p_houses).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
const now_time = moment(new Date()).format('X');
//处理足迹数据
const foot_print_records = [];
for (let j in houses) {
const house = houses[j];
const foot_print = foot_prints[j];
const type = foot_print.houseStyle === 1 ? 'new_house' : 'rental_house';
const create_time = moment(foot_print.createdAt).format('X');
let time = moment(foot_print.createdAt).format('YYYY-MM-DD');
const du_time = now_time - create_time;
if (du_time < 86400) {
const hours = parseInt(du_time / 3600);
const mins = parseInt(du_time / 60);
time = hours ? `${hours}小时前` : (mins > 5 ? `${mins}分钟前` : '刚刚');
}
foot_print_records.push({
id: foot_print.id,
name: house.name,
time: time,
type: type,
});
}
return { results: foot_print_records, count: foot_prints_results.rowCount };
}
}
module.exports = FootPrintService;
......@@ -20,8 +20,9 @@ const HOUSE_TYPE = [
{ 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: 5, max: 10000, value: 5, },
{ name: '别墅', min: 10000, max: 10000000, value: 6, },
{ name: '5室', min: 4, max: 4, value: 5, },
{ name: '5室以上', min: 5, max: 10000, value: 6, },
{ name: '别墅', min: 10000, max: 10000000, value: 7, },
]
class OptionService extends Service {
......
......@@ -4,27 +4,6 @@
const Service = require('egg').Service;
const R = require('ramda');
const PRICE_RANGE = {
1: { name: '2000元以下', min: 0, max: 2000 },
2: { name: '2000元-3000元', min: 2000, max: 3000 },
3: { name: '3000元-4000元', min: 3000, max: 4000 },
4: { name: '4000元-5000元', min: 4000, max: 5000 },
5: { name: '5000元-6000元', min: 5000, max: 6000 },
6: { name: '6000元-7000元', min: 6000, max: 7000 },
7: { name: '7000元-8000元', min: 7000, max: 8000 },
8: { name: '8000元-10000元', min: 8000, max: 10000 },
9: { name: '10000元以上', min: 10000, max: 10000000000000 },
}
const HOUSE_TYPE = {
1: { name: '1室', min: 1, max: 1 },
2: { name: '2室', min: 2, max: 2 },
3: { name: '3室', min: 3, max: 3 },
4: { name: '4室', min: 4, max: 4 },
5: { name: '5室以上', min: 5, max: 10000 },
6: { name: '别墅', min: 10000, max: 10000000 },
}
class RentalHouseService extends Service {
async getRentalHousesByFilter(condition) {
......@@ -89,16 +68,28 @@ class RentalHouseService extends Service {
}
rental_house_id = house_basic_result.id;
//获取房源图片信息
const house_images = await this.getRentalHouseImages(rental_house_id);
const p_house_images = this.getRentalHouseImages(rental_house_id);
//获取房源类型
const house_types = await this.getRentalHouseTypes(rental_house_id);
const p_house_types = this.getRentalHouseTypes(rental_house_id);
const p_ret = await Promise.all([p_house_images, p_house_types]).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
const house_images = p_ret[0];
const house_types = p_ret[1];
//处理房源基本信息格式
let house_basic = await this.formatRentalHouseBasic([house_basic_result]);
house_basic = house_basic[0];
ctx.service.house.footPrint.addFootPrint({ id: rental_house_id, type: 2 });//添加用户足迹记录
return { house_basic, house_images, house_types };
}
......
'use strict';
const Service = require('egg').Service;
class FootPrintService extends Service {
async one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/footprint/' + 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/footprint/' + 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;
}
async delete(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/footprint/' + 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('footprint_list_params: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/footprint/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;
ctx.logger.info('add_footprint_params: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/footprint/', data, { method: 'POST' });
ctx.logger.info('add_footprint_results: ' + JSON.stringify(result));
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 = FootPrintService;
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