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

add controller v2

parent 4bd643a3
Pipeline #8591 passed with stage
in 3 seconds
'use strict';
const Controller = require('egg').Controller;
class RentalHouseController extends Controller {
//租房首页信息
async home() {
const { ctx } = this;
const input_params = ctx.query;
const city_code = input_params.city_code ? input_params.city_code : 330100;
//banners
const headers = {
cookie: ctx.request.headers.cookie
}
const banners_result = await ctx.helper.send_request(this.config.NODE_BASE_URL + '/51app/api/block/all', { alias: '51fangc_rental_home_banners' }, { method: 'GET', dataType: 'json', headers: headers });
let banners = [];
if (banners_result.status === 200) {
banners = banners_result.data.results;
}
const developers = await ctx.service.house.option.getDevelopers(city_code);//品牌信息
ctx.success({ banners, developers });
}
//租房列表
async getRentalHouses() {
const { ctx } = this;
const input_params = ctx.request.body;
const rule = {
brand: { type: 'string', required: false },//品牌
area_code: { type: 'object', required: false },//区域
price: { type: 'object', required: false },//价格
house_type: { type: 'string', required: false },//房型
name: { type: 'string', required: false },//楼盘名称
page: { type: 'string', required: false },
page_size: { type: 'string', required: false },
};
ctx.validate(rule, input_params);
const ret = await ctx.service.house.v2.rentalHouse.getRentalHousesByFilter(input_params);
ctx.success({ input_params, results: ret.results, count: ret.count });
}
//租房详情
async getRentalHouse() {
const { ctx } = this;
const input_params = ctx.params;
if (!input_params.rental_house_id) {
ctx.failed('rental_house_id error');
}
const rental_house_id = input_params.rental_house_id;
const ret = await ctx.service.house.v2.rentalHouse.getRentalHouse(rental_house_id);
ctx.success(ret);
}
}
module.exports = RentalHouseController;
...@@ -46,4 +46,12 @@ module.exports = app => { ...@@ -46,4 +46,12 @@ module.exports = app => {
//房产v2
//租房列表
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');//住房详情
}; };
'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 } = 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;
}
const data = {
user_id: user_id,
app_type_id: app_type_id,
app_id: app_id,
house_style: inputParams.type,
connectId: inputParams.id,
state: 1,
remark: inputParams.remark || '',
}
let ret = await ctx.realestateModel.footPrint.add(data);
return { id: ret.id };
}
/**
* 获取用户足迹列表 保留最近6个月的记录,条数不超过50条
* @param {object} condition
*/
async getFootPrintList() {
const { ctx } = this;
const user_id = ctx.userId;
const app_type_id = ctx.appTypeId;
if (!user_id || !app_type_id) {
return {
results: [],
count: 0
};
}
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);
}
}
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.house_style === 1 ? 'new_house' : 'rental_house';
const create_time = moment(foot_print.created_at).format('X');
let time = moment(foot_print.created_at).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,
house_id: house.id,
name: house.name,
time: time,
type: type,
});
}
return { results: foot_print_records, count: foot_prints_results.rowCount };
}
/**
* 我的-获取用户足迹个数
*/
async getFootPrintCount() {
const { ctx, service } = this;
if (!ctx.userId) {
return { count: 0 };
}
const filter = {
pageIndex: 1,
pageSize: 50,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "userId",
value: ctx.userId,
operator: "equal"
},
],
orderConditions: [{
key: 'createdAt',
orderSequence: 'desc',
},],
}
const foot_prints_results = await service.houseCommon.footPrint.all(filter);
let ret = {
count: foot_prints_results.rowCount
};
return ret;
}
}
module.exports = FootPrintService;
This diff is collapsed.
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