Commit 2f1b3c77 authored by 李尚科's avatar 李尚科

house fix

parent 98de7566
Pipeline #6521 passed with stage
in 3 seconds
'use strict';
const Controller = require('egg').Controller;
class Export20190425 extends Controller {
/**
* 关注
*/
async exportHouseImages() {
const { ctx } = this;
const house_images = await ctx.realestateModel.HouseImage.findAll();
let count = 0;
for (let i in house_images) {
const item = house_images[i];
const add_data = {
path: 'https://r.51gjj.com/' + item.path,
type: item.type,
connectId: item.connect_id,
remark: item.remark,
state: 1,
description: '',
};
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/houseimage', add_data, { method: 'POST' });
if (result.status === 201) count++;
}
ctx.success(count);
}
async exportResidential() {
const { ctx } = this;
const residentials = await ctx.realestateModel.Residential.findAll();
let count = 0;
let result;
for (let i in residentials) {
const residential = residentials[i];
const add_data = {
name: residential.name,
province: residential.province,
city: residential.city,
county: residential.county,
region: residential.region,
propertyRightYears: residential.property_right_years,
propertyFee: residential.property_fee,
propertyCompany: residential.property_company,
heatSupplyType: residential.heat_supply_type,
waterSupplyType: residential.water_suppler_type,
powerSupplyType: residential.power_suppler_type,
landArea: residential.land_area,
houseArea: residential.house_area,
areaRatio: residential.area_ratio,
greenRatio: residential.green_ratio,
archType: residential.arch_type,
nearBy: residential.nearby,
state: 1,
remark: '',
}
result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/residential', add_data, { method: 'POST' });
if (result.status === 201) {
count++;
}
// if(count === 1) break;
}
ctx.success(count);;
}
}
module.exports = Export20190425;
...@@ -154,10 +154,10 @@ module.exports = { ...@@ -154,10 +154,10 @@ module.exports = {
return ret; return ret;
}, },
async getGPS(address) { async getGPS(address, city) {
const baidu_url = `https://api.map.baidu.com/geocoder/v2/`; const baidu_url = `https://api.map.baidu.com/geocoder/v2/`;
const result = await this.send_request(baidu_url, { address: address, output: 'json', ak: '3TBenWOhPygtFFazaR5kSibU' }, { method: 'GET' }); const result = await this.send_request(baidu_url, { address: address, output: 'json', ak: '3TBenWOhPygtFFazaR5kSibU', city: city }, { method: 'GET' });
const ret = result.data; const ret = result.data;
if (ret && ret.status === 0) { if (ret && ret.status === 0) {
return ret; return ret;
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const HouseImage = app.realestateModel.define('house_image', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
path: STRING,
connect_id: INTEGER,
type: INTEGER,
remark: STRING,
status: ENUM('online', 'offline'),
valid: INTEGER,
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_image',
});
HouseImage.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseImage.findOne({
attributes: attributes,
where: where,
});
}
HouseImage.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await HouseImage.findAll({
attributes: attributes,
where: where,
});
}
HouseImage.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 HouseImage.findAndCountAll(condition);
return { page, count, rows };
}
HouseImage.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await HouseImage.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
}
HouseImage.edit = async (data) => {
const where = data.where;
const params = data.params;
HouseImage.update(params, {
where: where
}).catch(e => res.json({ status: 500, error: e }));
}
return HouseImage;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE, TEXT, DECIMAL } = app.Sequelize;
const Residential = app.realestateModel.define('residential', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
province: INTEGER,
city: INTEGER,
county: INTEGER,
region: INTEGER,
property_right_years: INTEGER,
property_fee: STRING,
property_company: STRING,
heat_supply_type: STRING,
water_suppler_type: STRING,
power_suppler_type: STRING,
land_area: DECIMAL,
house_area: DECIMAL,
area_ratio: DECIMAL,
green_ratio: DECIMAL,
arch_type: INTEGER,
nearby: TEXT,
remark: STRING,
status: ENUM('online', 'offline'),
valid: INTEGER,
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: 'residential',
});
Residential.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Residential.findOne({
attributes: attributes,
where: where,
});
}
Residential.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Residential.findAll({
attributes: attributes,
where: where,
});
}
Residential.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 Residential.findAndCountAll(condition);
return { page, count, rows };
}
Residential.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await Residential.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
}
Residential.edit = async (data) => {
const where = data.where;
const params = data.params;
Residential.update(params, {
where: where
}).catch(e => res.json({ status: 500, error: e }));
}
return Residential;
};
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/house/export20190425');
router.get('add', '/house_image', 'house.export20190425.exportHouseImages');//用户浏览记录列表
router.get('add', '/residential', 'house.export20190425.exportResidential');//用户浏览记录列表
};
...@@ -138,7 +138,7 @@ class OptionService extends Service { ...@@ -138,7 +138,7 @@ class OptionService extends Service {
return []; return [];
} }
const ret = [] const ret = [{ id: 0, name: '不限' }];
for (let j in districts) { for (let j in districts) {
const district = districts[j]; const district = districts[j];
const _children = [{ id: 0, name: '不限' }]; const _children = [{ id: 0, name: '不限' }];
......
...@@ -103,7 +103,6 @@ class RentalHouseService extends Service { ...@@ -103,7 +103,6 @@ class RentalHouseService extends Service {
async getRentalHouse(rental_house_id) { async getRentalHouse(rental_house_id) {
const { ctx } = this; const { ctx } = this;
//获取房源基本信息 //获取房源基本信息
let house_basic_result = await ctx.service.houseCommon.rentalHouse.one(rental_house_id); let house_basic_result = await ctx.service.houseCommon.rentalHouse.one(rental_house_id);
if (!house_basic_result || !house_basic_result.id) { if (!house_basic_result || !house_basic_result.id) {
...@@ -136,7 +135,23 @@ class RentalHouseService extends Service { ...@@ -136,7 +135,23 @@ class RentalHouseService extends Service {
const collection = await ctx.service.house.collection.getCollection(collectionFilter); const collection = await ctx.service.house.collection.getCollection(collectionFilter);
ctx.service.house.footPrint.addFootPrint({ id: rental_house_id, type: 2 });//添加用户足迹记录 ctx.service.house.footPrint.addFootPrint({ id: rental_house_id, type: 2 });//添加用户足迹记录
const city_name = await ctx.blockModel.City.one({ where: { code: house_basic_result.residential.city } });
const county_name = await ctx.blockModel.District.one({ where: { code: house_basic_result.residential.county } });
const region_name = await ctx.blockModel.Bizcircle.one({ where: { code: house_basic_result.residential.region } });
let address = city_name + county_name + region_name + house_basic.address;
let gps_result = await ctx.helper.getGPS(address, city_name);
if(!gps_result){
address = city_name + county_name + region_name;
await ctx.helper.getGPS(address, city_name);
}
let longitude = 0;
let latitude = 0;
if (gps_result) {
longitude = gps_result.location.lng;
latitude = gps_result.location.lat;
}
house_basic.longitude = longitude;
house_basic.latitude = latitude;
return { house_basic, house_images, house_types, collection: collection.rowCount > 0 ? true : false, }; return { house_basic, house_images, house_types, collection: collection.rowCount > 0 ? true : false, };
} }
...@@ -248,7 +263,7 @@ class RentalHouseService extends Service { ...@@ -248,7 +263,7 @@ class RentalHouseService extends Service {
price: rental_house.price,//价格 price: rental_house.price,//价格
discount: rental_house.discount,//折扣 discount: rental_house.discount,//折扣
// business_license: rental_house.businessLicense, // business_license: rental_house.businessLicense,
tags: rental_house.tags.split(','),//房源特点 tags: rental_house.tags ? eval(rental_house.tags) : [],//房源特点
favourable_info: rental_house.favourableInfo,//优惠信息 favourable_info: rental_house.favourableInfo,//优惠信息
introduce: rental_house.description || `该社区亮点: introduce: rental_house.description || `该社区亮点:
1、房源介绍:精装公寓,家电齐全,独立卫生间,南通北透,独门独户。 1、房源介绍:精装公寓,家电齐全,独立卫生间,南通北透,独门独户。
......
...@@ -83,6 +83,7 @@ class ToolService extends Service { ...@@ -83,6 +83,7 @@ class ToolService extends Service {
const { ctx } = this; const { ctx } = this;
const down_payment = input.down_payment || 0;//首付金额 const down_payment = input.down_payment || 0;//首付金额
const invest_payment = input.invest_payment || 0;//投资金额 const invest_payment = input.invest_payment || 0;//投资金额
const prepare_time = input.prepare_time || 6;
const balance = down_payment - invest_payment; const balance = down_payment - invest_payment;
let notice = ''; let notice = '';
let status = 0; let status = 0;
...@@ -99,7 +100,7 @@ class ToolService extends Service { ...@@ -99,7 +100,7 @@ class ToolService extends Service {
} else { } else {
status = 1;//j加把劲还是有希望买到房 status = 1;//j加把劲还是有希望买到房
notice = '恭喜您!依据以上计划,您即将完成XXX项目首付款准备。您现阶段首付预算可以购买以下项目房源:'; notice = '恭喜您!依据以上计划,您即将完成XXX项目首付款准备。您现阶段首付预算可以购买以下项目房源:';
const invest_plans = await ctx.blockModel.HouseInvestPlan.one({ where: { condition_min: { $lt: rate }, condition_max: { $gte: rate }, status: 'online', valid: 1 } }); 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) { if (Object.keys(invest_plans).length !== 0 && invest_plans.items) {
invest_items = invest_plans.items; invest_items = invest_plans.items;
} }
......
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