Commit 1cf4541d authored by 李尚科's avatar 李尚科

tool fix

parent ae87de11
......@@ -238,6 +238,74 @@ class ToolController extends Controller {
ctx.success({ results: ret });
}
//生成购房计划
async generateBuyHousePlan_2_1() {
const { ctx } = this;
const input_parmas = ctx.request.body;
const rule = {
city_code: { type: 'string', required: true },
total_price: { type: 'object', required: true },
down_payment_rate: { type: 'string', required: true },//首付成数
down_payment: { type: 'string', required: true },//首付
invest_payment: { type: 'string', required: true },//现有现金
prepare_time: { type: 'string', required: true },
house_style: { type: 'string', required: false },
}
ctx.validate(rule, input_parmas);
if (!parseFloat(input_parmas.invest_payment)) {
ctx.failed('现有金额不能为0');
}
const city_code = input_parmas.city_code;
const total_price = input_parmas.total_price;
// const down_payment = parseFloat(input_parmas.down_payment);
const invest_payment = parseFloat(input_parmas.invest_payment);
const down_payment_rate = parseFloat(input_parmas.down_payment_rate);
if (!parseFloat(total_price.max) || !parseFloat(total_price.min)) {
ctx.failed('总价区间不能为0');
}
const house_plan = await ctx.service.house.v2.tool.generateHousePlan_2_1(input_parmas);//计算购房能力 生成购房计划
if (house_plan !== 2) {
total_price.max = invest_payment * 2 / down_payment_rate + 30;
total_price.min = invest_payment * 2 / down_payment_rate - 30;
}
let where = {
reference_total_price: { $between: [parseFloat(total_price.min), parseFloat(total_price.max)] },
option_city_code: city_code,
status: 'online',
valid: 1,
}
const recommend_houses_formats = [];
let recommend_houses = await ctx.realestateModel.NewHouse.list({ limit: 6, page: 1, where: where, order: [['order_id', 'desc']] });//推荐房源
for (let i in recommend_houses.rows) {
const recommend_house = recommend_houses.rows[i];
recommend_houses_formats.push(await ctx.service.house.v2.newHouse.formatNewHouseBasic(recommend_house));
}
recommend_houses = recommend_houses_formats.splice(0, 6);
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_tool_plan_banners' }, { method: 'GET', dataType: 'json', headers: headers });
let banners = [];
if (banners_result.status === 200) {
banners = banners_result.data.results;
}
const ret = {
house_plan,
banners,
recommend_houses,
}
ctx.success({ results: ret });
}
//购房计划城市区域列表
async planAreaList() {
......
......@@ -51,6 +51,7 @@ module.exports = app => {
//房产v2
router.get('/v2/tool/:house_style/:area_code/:level', 'house.v2.tool.getMapPoint');//购房计划地图点位(存钱罐地图)(房价地图)
router.post('/v2/tool/plan', 'house.v2.tool.generateBuyHousePlan');//生成购房计划
router.post('/v2.1/tool/plan', 'house.v2.tool.generateBuyHousePlan_2_1');//生成购房计划
router.get('/v2/tool/plan_area_list', 'house.v2.tool.planAreaList');//购房计划页面 区域列表接口
router.get('/v2/tool/:type/:city_code', 'house.v2.tool.getHousePriceFeature');//房价走势图 房价涨跌图 购房资格图、贷款额度问答、供需趋势图
router.post('/v2/tool/calculate_price', 'house.tool.calculateHousePrice');//房产估价
......
......@@ -111,6 +111,42 @@ class ToolService extends Service {
return { status, notice, invest_items };
}
//存钱罐计算完毕后 生成购房计划
async generateHousePlan_2_1(input) {
const { ctx } = this;
const down_payment = input.down_payment || 0;//首付金额
const invest_payment = input.invest_payment || 0;//投资金额
const prepare_time = input.prepare_time || 6;
const balance = down_payment - invest_payment;
let notice = '';
let status = 0;
let invest_items = [];
if (balance <= 0) {
status = 2;//完全有能力买到房
notice = '您的资金已满足本项目首付条件,还有更多项目在您预算范围内。一键预约,轻松看房!';
return { status, notice, invest_items };
}
const rate = balance / invest_payment;
if (rate > 10) {
status = 0;//完全没有希望能买到房
notice = '非常遗憾,您的首付预算距离购买该项目尚有较大差距,请修改购房计划,重新尝试!';
} else {
status = 1;//加把劲还是有希望买到房
notice = '恭喜您!依据以上计划,您即将完成此项目首付款准备。您现阶段首付预算可以购买以下项目房源:';
const invest_plans = await ctx.blockModel.HouseInvestPlan.one({ where: { condition_min: { $lt: rate }, condition_max: { $gte: rate }, status: 'online', valid: 1, period: prepare_time } });
if (Object.keys(invest_plans).length !== 0 && invest_plans.items) {
invest_items = invest_plans.items;
if (invest_items.length === 0) {//差距还是太大 投资期限过长 不宜买房
status = 0;
notice = '非常遗憾,您的首付预算距离购买该项目尚有较大差距,请修改购房计划,重新尝试!';
}
}
}
return { status, notice, invest_items };
}
}
module.exports = ToolService;
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