Commit 165e7b57 authored by 李尚科's avatar 李尚科

add house

parent ba1e0152
'use strict';
const Controller = require('egg').Controller;
class OptionsController extends Controller {
async getOptions() {
const { ctx } = this;
const input_parmas = ctx.params;
const rule = {
city_code: { type: 'string', required: true }
}
ctx.validate(rule, input_parmas);
const city_code = input_parmas.city_code;
const ret = await ctx.service.house.option.getOptions(city_code);
ctx.success(ret);
}
}
module.exports = OptionsController;
'use strict';
const Controller = require('egg').Controller;
class RentalHouseController extends Controller {
async getRentHouses() {
const { ctx } = this;
const input_params = ctx.query;
const rule = {
brand: { type: 'string', required: false },//品牌
district: { type: 'string', required: false },//区域
price: { type: 'enum', required: false, values: ['1', '2', '4', '5', '6', '7', '8', '9'] },//价格
house_type: { type: 'enum', required: false, values: ['1', '2', '4', '5', '6'] },//房型
};
ctx.validate(rule, input_params);
const ret = await ctx.service.house.rentalHouse.getRentalHouses(input_params);
ctx.success(ret);
}
}
module.exports = RentalHouseController;
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/house');
// const loginAuth = app.middleware.loginAuth({type: 'new'});//登录中间件
router.get('/options', 'house.options.getOptions');//首页信息
router.get('/rental_house', 'house.rentalHouse.getRentHouses');//首页信息
};
'use strict';
const Service = require('egg').Service;
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 OptionService extends Service {
async getOptions(city_code) {
const { ctx } = this;
const city = ctx.blockModel.City.one({ where: { code: city_code } });
if (!city || !city.name) {
ctx.failed('city code error');
}
const district = ctx.blockModel.District.all({ where: { city_id: city.code } });
if(!district || district){
ctx.failed('district error');
}
const bizcircle = ctx.blockModel.Bizcircle.all({where: {}});
const developers_results = await ctx.service.houseCommon.developer.all({});
const developers = developers_results.results;
const brands = [];
for (let i in developers) {
const developer = developers[i];
brands.push({
id: developer.id,
name: developer.name,
image: developer.logo,
});
}
const house_types = HOUSE_TYPE;
const prices = PRICE_RANGE;
return { brands, prices, house_types };
}
}
module.exports = OptionService;
'use strict';
const Service = require('egg').Service;
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) {
const { ctx } = this;
const queryConditions = [];
if(condition.brand){
queryConditions.push();
}
const filter = {
pageSize: 30,
queryConditions: [{
key: "State",
value: 1,
operator: "equal"
},],
orderConditions: [{
key: 'Price',
orderSequence: 'asc',
},],
}
const rental_houses_results = await ctx.service.houseCommon.rentalHouse.all({});
return rental_houses_results;
}
}
module.exports = RentalHouseService;
'use strict';
const Service = require('egg').Service;
class DeveloperService extends Service {
async all(data) {
const { ctx } = this;
const pageIndex = data.page || 1;
const pageSize = data.pageSize || 10;
const queryConditions = data.queryConditions || [];
const orderConditions = data.orderConditions || [];
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(orderConditions).length === 0) {
data.orderConditions = [{
key: 'OrderNum',
orderSequence: 'asc',
}];
}
data.orderConditions = orderConditions;
data.pageIndex = pageIndex;
data.pageSize = pageSize;
console.info(data);
ctx.logger.info('developer_list_conditions: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/developer/list', data, { method: 'POST', dataType: 'json' });
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 one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/developer/' + id, {}, {});
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;
}
}
module.exports = DeveloperService;
'use strict';
const Service = require('egg').Service;
class RentalHouseService extends Service {
async all(data) {
const { ctx } = this;
const pageIndex = data.page || 1;
const pageSize = data.pageSize || 10;
const queryConditions = data.queryConditions || [];
const orderConditions = data.orderConditions || [];
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(orderConditions).length === 0) {
data.orderConditions = [{
key: 'OrderNum',
orderSequence: 'asc',
}];
}
data.orderConditions = orderConditions;
data.pageIndex = pageIndex;
data.pageSize = pageSize;
console.info(data);
ctx.logger.info('rentalhouse_list_conditions: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/rentalhouse/list', data, { method: 'POST', dataType: 'json' });
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 one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/rentalhouse/' + id, {}, {});
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;
}
}
module.exports = RentalHouseService;
...@@ -19,7 +19,7 @@ module.exports = appInfo => { ...@@ -19,7 +19,7 @@ module.exports = appInfo => {
config.projectRootPath = '/51business/api'; config.projectRootPath = '/51business/api';
// add your middleware config here // add your middleware config here
config.middleware = [ 'errorHandler', 'deviceInit' ]; config.middleware = [ 'errorHandler'];
// add your user config here // add your user config here
const userConfig = { const userConfig = {
......
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