Commit 437898d7 authored by 李尚科's avatar 李尚科

add house analysis

parent 30636dc0
'use strict';
const Controller = require('egg').Controller;
class HouseAnalysisController extends Controller {
//购房解析列表
async getHouseAnalysisList() {
const { ctx } = this;
const input_params = ctx.request.body;
if (!input_params.city_code) {
ctx.failed('city_code error');
}
let results = await ctx.service.house.v2.houseAnalysis.getHouseAnalysisByFilter(input_params);
const format_rows = await ctx.service.house.v2.houseAnalysis.formatHouseAnalysis(results.results);
results.results = format_rows;
ctx.success(results);
}
//购房解析详情
async getHouseAnalysisInfo() {
const { ctx } = this;
const house_analysis_id = ctx.params.house_analysis_id;
const city_code = ctx.query.city_code;
const results = await ctx.service.house.v2.houseAnalysis.getHouseAnalysis(house_analysis_id);
//推荐楼盘
let where = { corner: { $ne: '' } };
if (city_code) {
where.option_city_code = city_code;
}
let new_houses_rows = await ctx.realestateModel.NewHouse.list({ page: 1, limit: 3, where: where, order: [['order_id', 'asc']] });
const similar_list = [];
for (let i in new_houses_rows.rows) {
const new_house = new_houses_rows.rows[i];
similar_list.push({
id: new_house.id,
name: new_house.name,
image: new_house.image,
corner: new_house.corner,
});
}
ctx.success({ results: { info: results, similar_list } });
}
async uploadHouseAnalysis() {
const { ctx } = this;
const input_params = ctx.request.body;
const rule = {
name: { type: 'string', required: true },
city_code: { type: 'string', required: true },
house_type: { type: 'string', required: true },
area: { type: 'string', required: true },
image: { type: 'string', required: true },
}
ctx.validate(rule, input_params);
const result = await ctx.service.house.v2.houseAnalysis.addHouseAnalysis(input_params);
ctx.success({ result });
}
async getUserHouseAnalysis() {
const { ctx } = this;
const input_params = ctx.query;
const results = await ctx.service.house.v2.houseAnalysis.getMineHouseAnalysis(input_params);
const format_rows = await ctx.service.house.v2.houseAnalysis.formatHouseAnalysis(results.rows);
ctx.success({ page: results.page, count: results.count, results: format_rows });
}
}
module.exports = HouseAnalysisController;
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const HouseAnalysis = app.realestateModel.define('house_analysis', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
residential: STRING,
city: STRING,
house_type: STRING,
house_area: STRING,
image: STRING,
text: STRING,
status: ENUM('pass', 'refuse', 'wait'),
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'house_analysis',
});
HouseAnalysis.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseAnalysis.findOne({
attributes: attributes,
where: where,
});
}
HouseAnalysis.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await HouseAnalysis.findAll({
attributes: attributes,
where: where,
order,
});
}
HouseAnalysis.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await HouseAnalysis.findAndCountAll(condition);
return { page, count, rows };
}
HouseAnalysis.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HouseAnalysis.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
HouseAnalysis.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await HouseAnalysis.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return HouseAnalysis;
};
......@@ -48,6 +48,14 @@ module.exports = app => {
//房产v2
router.get('/v2/tool/:house_style/:area_code/:level', 'house.tool.getMapPoint');//购房计划地图点位
router.post('/v2/tool/plan', 'house.tool.generateBuyHousePlan');//生成购房计划
router.get('/v2/tool/:type/:area_code', 'house.tool.getHousePriceFeature');//房价指数 房价涨跌 购房资格、贷款额度问答
router.post('/v2/tool/calculate_price', 'house.tool.calculateHousePrice');//房产估价
router.get('/v2/tool/qfang_area_list', 'house.tool.getQFangAreaList');//房产估价模糊匹配到的小区列表
router.get('/v2/tool/map_houses', 'house.tool.getMapHouses');//房产估价模糊匹配到的小区列表
//租房列表
router.get('/v2/rental_house/home', 'house.v2.rentalHouse.home');//租房首页信息
router.get('/v2/rental_house/list', 'house.v2.rentalHouse.getRentalHouses');//租房列表
......@@ -81,7 +89,14 @@ module.exports = app => {
router.get('/v2/mine', 'house.v2.mine.getMineInfo');//获取用户的头像昵称和关注等信息
//
router.get('/tool/gjj/loan/measure/:area', 'house.v2.tool.gjjLoanMeasureInfo');//貸款測算
router.get('add', '/v2/tool/gjj/loan/measure/:area', 'house.v2.tool.gjjLoanMeasureInfo');//貸款測算
//户型解析
router.get('add', '/v2/house_analysis/list', 'house.v2.houseAnalysis.getHouseAnalysisList');//户型解析列表
router.post('/v2/house_analysis/list', 'house.v2.houseAnalysis.getHouseAnalysisList');//户型解析列表
router.get('/v2/house_analysis/info/:house_analysis_id', 'house.v2.houseAnalysis.getHouseAnalysisInfo');//户型解析列表
router.post('/v2/house_analysis/', loginAuth, 'house.v2.houseAnalysis.uploadHouseAnalysis');//上传户型信息
router.get('add', '/v2/house_analysis/mine', loginAuth, 'house.v2.houseAnalysis.getUserHouseAnalysis');//我的户型
//点赞
router.get('/v2/like/:id', 'house.v2.like.like');//点赞
......
'use strict';
const Service = require('egg').Service;
const R = require('ramda');
const moment = require('moment');
class HouseAnalysisService extends Service {
//户型解析列表
async getHouseAnalysisByFilter(condition) {
const { ctx } = this;
let { city_code, keyword, page } = condition;
page = page ? page : 1;
let where = { status: 'pass' };
if (city_code) {
where.city = city_code;
}
if (keyword && keyword.length !== 0) {
where.residential = { $like: `%${keyword}%` }
}
const house_analysis_rows = await ctx.realestateModel.HouseAnalysis.list({ page: page, where: where, order: [['id', 'desc']] });
const house_analysis = R.project(['id', 'image', 'residential', 'house_type', 'house_area', 'text'])(house_analysis_rows.rows);
return { page: page, count: house_analysis_rows.count, results: house_analysis };
}
//户型解析详情
async getHouseAnalysis(house_analysis_id) {
const { ctx } = this;
const house_analysis = await ctx.realestateModel.HouseAnalysis.one({ where: { id: house_analysis_id } });
return {
id: house_analysis.id,
image: house_analysis.image,
name: house_analysis.residential,
house_type: house_analysis.house_type,
area: house_analysis.house_area,
description: house_analysis.text,
status: house_analysis.status,
}
}
async addHouseAnalysis(params) {
const { ctx } = this;
const user_id = ctx.userId;
const app_user_id = ctx.appUserId;
const app_id = ctx.appId;
const app_type_id = ctx.appTypeId;
if (!user_id || !app_user_id || !app_id || !app_type_id) {
ctx.failed('login error');
}
const data = {
user_id,
app_user_id,
app_id,
app_type_id,
residential: params.name,
house_type: params.house_type,
city: params.city_code,
house_area: params.area,
image: params.image,
created_at: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
}
const ret = await ctx.realestateModel.HouseAnalysis.add(data);
return ret;
}
async getMineHouseAnalysis(condition) {
const { ctx } = this;
const page = condition.page ? condition.page : 1;
const limit = condition.page_size ? condition.page_size : 10;
const user_id = ctx.userId;
const app_type_id = ctx.appTypeId;
if (!user_id || !app_type_id) {
ctx.failed('login error');
}
const results = await ctx.realestateModel.HouseAnalysis.list({ page: page, limit: limit, where: { user_id: user_id, app_type_id: app_type_id }, order: [['id', 'desc']] });
return results;
}
async formatHouseAnalysis(house_analysis) {
const { ctx } = this;
if (!Array.isArray(house_analysis) || house_analysis.length === 0) {
return [];
}
const ret = house_analysis.map(item => { return { id: item.id, status: item.status, house_type: item.house_type, area: item.house_area, description: item.text, image: item.image } });
return ret;
}
}
module.exports = HouseAnalysisService;
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