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

add house image

parent 7b1d1133
Pipeline #5754 passed with stage
in 2 seconds
......@@ -4,17 +4,28 @@ const Controller = require('egg').Controller;
class RentalHouseController extends Controller {
async getRentHouses() {
async getRentalHouses() {
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'] },//价格
// 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);
const ret = await ctx.service.house.rentalHouse.getRentalHousesByFilter(input_params);
ctx.success(ret);
}
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.rentalHouse.getRentalHouse(rental_house_id);
ctx.success(ret);
}
......
......@@ -5,6 +5,7 @@ module.exports = app => {
// const loginAuth = app.middleware.loginAuth({type: 'new'});//登录中间件
router.get('/options/:city_code', 'house.options.getOptions');//筛选项信息
router.get('/rental_house', 'house.rentalHouse.getRentHouses');//租房列表
router.get('/rental_house', 'house.rentalHouse.getRentalHouses');//租房列表
router.get('/rental_house/:rental_house_id', 'house.rentalHouse.getRentalHouse');//租房列表
};
......@@ -30,25 +30,70 @@ class RentalHouseService extends Service {
const { ctx } = this;
const queryConditions = [];
if(condition.brand){
if (condition.brand) {
queryConditions.push();
}
const filter = {
pageSize: 30,
queryConditions: [{
key: "State",
key: "state",
value: 1,
operator: "equal"
}, {
key: "price",
value: 19000,
operator: "greater"
}, {
key: "price",
value: 29000,
operator: "less"
},],
orderConditions: [{
key: 'Price',
key: 'price',
orderSequence: 'asc',
},],
}
const rental_houses_results = await ctx.service.houseCommon.rentalHouse.all({});
const rental_houses_results = await ctx.service.houseCommon.rentalHouse.all(filter);
return rental_houses_results;
}
async getRentalHouse(rental_house_id) {
const { ctx } = this;
//获取房源基本信息
const house_basic = await ctx.service.houseCommon.rentalHouse.one(rental_house_id);
if(!house_basic || !house_basic.id){
ctx.failed('house not found');
}
//获取房源图片信息
const house_image_filter = {
queryConditions: [
{
key: 'state',
value: 1,
operator: 'equal'
},
{
key: 'type',
value: 0,
operator: 'equal'
},
{
key: 'connectId',
value: house_basic.id,
operator: 'equal'
},
],
};
const house_images_results = await ctx.service.houseCommon.houseImage.all(house_image_filter);
const house_images = house_images_results.results;
return {house_basic, house_images};
}
}
module.exports = RentalHouseService;
'use strict';
const Service = require('egg').Service;
class HouseImageService 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 || [];
data.queryConditions = queryConditions;
data.orderConditions = orderConditions;
data.pageIndex = pageIndex;
data.pageSize = pageSize;
ctx.logger.info('houseimage_list_conditions: ' + JSON.stringify(data));
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/houseimage/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/houseimage/' + id, {}, { method: 'GET', dataType: 'json' });
ctx.logger.info('house_image_result: ' + JSON.stringify(result));
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;
}
}
module.exports = HouseImageService;
......@@ -46,7 +46,8 @@ class RentalHouseService extends Service {
async one(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/rentalhouse/' + id, {}, {});
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/rentalhouse/' + id, {}, { method: 'GET', dataType: 'json' });
ctx.logger.info('rentalhouse_result: ' + JSON.stringify(result));
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
......@@ -56,6 +57,9 @@ class RentalHouseService extends Service {
}
ctx.failed(err);
}
ctx.logger.info('rental_house_result: ' + JSON.stringify(result));
return result.data;
}
......
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