Commit e471087a authored by 李尚科's avatar 李尚科
parents f8911a7f 4a808024
Pipeline #14938 passed with stage
in 7 seconds
'use strict';
const Controller = require('egg').Controller;
class AbroadHouseController extends Controller {
/**
* 获取海外房列表
*/
async list() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
name: { type: 'string', required: false },
};
ctx.validate(rule, inputParams);
let ret = await ctx.service.house.v2.abroadHouse.abroadHouseList(inputParams);
ctx.success(ret);
}
}
module.exports = AbroadHouseController;
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
class FootPrintController extends Controller { class FootPrintController extends Controller {
/** /**
* 获取足迹列表 * 获取足迹列表
*/ */
...@@ -13,6 +13,22 @@ class FootPrintController extends Controller { ...@@ -13,6 +13,22 @@ class FootPrintController extends Controller {
ctx.success(ret); ctx.success(ret);
} }
/**
* 海外房的足迹记录需要额外记录
*/
async addAbroadFootPrint() {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
id: { type: 'int', required: true },
};
ctx.validate(rule, inputParams);
inputParams.type = 4;
let ret = await ctx.service.house.v2.footPrint.addFootPrint(inputParams);
ctx.success(ret);
}
} }
module.exports = FootPrintController; module.exports = FootPrintController;
'use strict'; 'use strict';
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
const ConfigType = {
1: 'new_house',
2: 'rental_house',
4: 'abroad_house',
}
class searchHistoryController extends Controller { class searchHistoryController extends Controller {
...@@ -19,9 +24,9 @@ class searchHistoryController extends Controller { ...@@ -19,9 +24,9 @@ class searchHistoryController extends Controller {
}; };
ctx.validate(rule, inputParams); ctx.validate(rule, inputParams);
let ret = {}; let ret = {};
let type = [1, 2]; let type = [1, 2, 4];
for (let i in type) { for (let i in type) {
let tag = type[i] === 1 ? 'new_house' : 'rental_house'; let tag = ConfigType[type[i]];
ret[tag] = await ctx.service.house.v2.searchHistory.getSearchHistoryList({ type: type[i], city_code: Number(inputParams.city_code) }); ret[tag] = await ctx.service.house.v2.searchHistory.getSearchHistoryList({ type: type[i], city_code: Number(inputParams.city_code) });
} }
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT, DECIMAL } = app.Sequelize;
const AbroadHouse = app.realestateModel.define('abroad_house', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: STRING,
allowNull: true
},
images: {
type: TEXT,
allowNull: true
},
tags: {
type: STRING,
allowNull: true
},
total_price: {
type: DECIMAL,
allowNull: true
},
url: {
type: STRING,
allowNull: true
},
order: {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
status: {
type: STRING,
allowNull: true
},
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: 'abroad_house',
});
return AbroadHouse;
};
...@@ -129,6 +129,12 @@ module.exports = app => { ...@@ -129,6 +129,12 @@ module.exports = app => {
router.post('/v2/answer/like/:id', loginAuth, 'house.v2.like.like');//点赞 router.post('/v2/answer/like/:id', loginAuth, 'house.v2.like.like');//点赞
router.put('/v2/answer/like/:id', loginAuth, 'house.v2.like.unLike');//取消点赞 router.put('/v2/answer/like/:id', loginAuth, 'house.v2.like.unLike');//取消点赞
//海外房列表
router.post('/v2/abroad_house/list', 'house.v2.abroadHouse.list');
//海外房足迹记录
router.post('/v2/foot_print/abroad_house', 'house.v2.footPrint.addAbroadFootPrint');
}; };
\ No newline at end of file
...@@ -429,7 +429,6 @@ class InstitutionService extends Service { ...@@ -429,7 +429,6 @@ class InstitutionService extends Service {
const sort = function(a, b) { const sort = function(a, b) {
return a.distance - b.distance; return a.distance - b.distance;
}; };
ret = R.sort(sort)(ret);
const institutions = []; const institutions = [];
for (const v of ret) { for (const v of ret) {
...@@ -438,13 +437,23 @@ class InstitutionService extends Service { ...@@ -438,13 +437,23 @@ class InstitutionService extends Service {
} }
} }
const results = []; let results = [];
let debugs = [];
for (const v of institutions) { for (const v of institutions) {
if (!ctx.isEmpty(v)) { if (!ctx.isEmpty(v)) {
results.push(v); results.push(v);
debugs.push(
{
id: v.id,
name: v.name,
distance: v.distance,
}
)
} }
} }
results = R.sort(sort)(results);
if (results.length <= (page - 1) * 10) { if (results.length <= (page - 1) * 10) {
return { count: 0, rows: [] }; return { count: 0, rows: [] };
} }
......
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
const _ = require('lodash');
class AbroadHouseService extends Service {
/**
* 海外房列表
*/
async abroadHouseList(condition) {
const { ctx } = this;
let filter = {
where: {
valid: 1,
status: 'online',
},
order: [['order', 'asc']]
}
if (condition.name) {//关键词搜索 模糊查询
//增加搜索历史
let addHistory = {
type: 4,
key_word: condition.name
};
await ctx.service.house.v2.searchHistory.addSearchHistory(addHistory);
filter.where.name = { $like: '%' + condition.name + '%' }
}
let list = await ctx.realestateModel.AbroadHouse.findAll(filter);
let data = [];
for (let i in list) {
data[i] = {
id: list[i].id,
name: list[i].name || '',
images: list[i].images ? JSON.parse(list[i].images) : [],
tags: list[i].tags ? JSON.parse(list[i].tags) : [],
total_price: list[i].total_price === '0.00' ? '--' : list[i].total_price,
url: list[i].url || '',
}
}
let ret = {
results: data,
count: data.length
};
return ret;
}
}
module.exports = AbroadHouseService;
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
'use strict'; 'use strict';
const Service = require('egg').Service; const Service = require('egg').Service;
const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
const ConfigType = {
1: 'new_house',
2: 'rental_house',
4: 'abroad_house',
}
class FootPrintService extends Service { class FootPrintService extends Service {
...@@ -29,8 +35,7 @@ class FootPrintService extends Service { ...@@ -29,8 +35,7 @@ class FootPrintService extends Service {
state: 1, state: 1,
remark: inputParams.remark || '', remark: inputParams.remark || '',
} }
let ret = await ctx.realestateModel.FootPrint.add(data); let ret = await ctx.realestateModel.FootPrint.create(data);
return { id: ret.id }; return { id: ret.id };
} }
...@@ -57,7 +62,6 @@ class FootPrintService extends Service { ...@@ -57,7 +62,6 @@ class FootPrintService extends Service {
limit: 50, limit: 50,
where: { where: {
user_id: user_id, user_id: user_id,
// app_type_id: app_type_id,
state: 1, state: 1,
created_at: { $gt: endDate }, created_at: { $gt: endDate },
}, },
...@@ -69,10 +73,13 @@ class FootPrintService extends Service { ...@@ -69,10 +73,13 @@ class FootPrintService extends Service {
for (let i in foot_prints) { for (let i in foot_prints) {
let foot_print = foot_prints[i]; let foot_print = foot_prints[i];
if (foot_print.house_style === 1) {//获取房源信息 if (foot_print.house_style === 1) {//获取房源信息
p_houses[i] = ctx.realestateModel.NewHouse.one({ where: { id: foot_print.connect_id } }); p_houses[i] = ctx.realestateModel.NewHouse.one({ attributes: ['id', 'name', 'status', 'valid'], where: { id: foot_print.connect_id } });
} else if (foot_print.house_style === 2) { } else if (foot_print.house_style === 2) {
p_houses[i] = ctx.realestateModel.RentalHouse.one({ where: { id: foot_print.connect_id } }); p_houses[i] = ctx.realestateModel.RentalHouse.one({ attributes: ['id', 'name', 'status', 'valid'], where: { id: foot_print.connect_id } });
} else if (foot_print.house_style === 4) {
p_houses[i] = ctx.realestateModel.AbroadHouse.findOne({ attributes: ['id', 'name', 'url', 'status', 'valid'], where: { id: foot_print.connect_id } });
} }
} }
const houses = await Promise.all(p_houses).then(result => {//等待所有异步内容获取完成 const houses = await Promise.all(p_houses).then(result => {//等待所有异步内容获取完成
return result; return result;
...@@ -89,7 +96,7 @@ class FootPrintService extends Service { ...@@ -89,7 +96,7 @@ class FootPrintService extends Service {
} }
const house = houses[j]; const house = houses[j];
const foot_print = foot_prints[j]; const foot_print = foot_prints[j];
const type = foot_print.house_style === 1 ? 'new_house' : 'rental_house'; const type = ConfigType[foot_print.house_style];
const create_time = moment(foot_print.created_at).format('X'); const create_time = moment(foot_print.created_at).format('X');
let time = moment(foot_print.created_at).format('YYYY-MM-DD'); let time = moment(foot_print.created_at).format('YYYY-MM-DD');
const du_time = now_time - create_time; const du_time = now_time - create_time;
...@@ -105,10 +112,11 @@ class FootPrintService extends Service { ...@@ -105,10 +112,11 @@ class FootPrintService extends Service {
name: house.name, name: house.name,
time: time, time: time,
type: type, type: type,
url: type === 'abroad_house' ? house.url : '',
}); });
} }
return { results: foot_print_records, count: foot_prints_rows.count }; return { results: foot_print_records, count: foot_print_records.length };
} }
...@@ -122,7 +130,6 @@ class FootPrintService extends Service { ...@@ -122,7 +130,6 @@ class FootPrintService extends Service {
} }
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss'); let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
const filter = { const filter = {
page: 1,
limit: 50, limit: 50,
attributes: ['connect_id', 'house_style'], attributes: ['connect_id', 'house_style'],
where: { where: {
...@@ -135,29 +142,55 @@ class FootPrintService extends Service { ...@@ -135,29 +142,55 @@ class FootPrintService extends Service {
const list = await ctx.realestateModel.FootPrint.findAll(filter); const list = await ctx.realestateModel.FootPrint.findAll(filter);
let count = 0; let count = 0;
if (list.length > 0) { if (list.length > 0) {
let taskList = []; let newIds = [];
let rentalIds = [];
let abroadIds = [];
for (let i in list) { for (let i in list) {
let taskFilter = {
attributes: ['id'],
where: {
status: 'online',
valid: 1,
id: list[i].connect_id
}
}
if (Number(list[i].house_style) === 1) { if (Number(list[i].house_style) === 1) {
taskList[i] = ctx.realestateModel.NewHouse.one(taskFilter); newIds.push(list[i].connect_id);
} }
if (Number(list[i].house_style) === 2) { if (Number(list[i].house_style) === 2) {
taskList[i] = ctx.realestateModel.RentalHouse.one(taskFilter); rentalIds.push(list[i].connect_id);
}
if (Number(list[i].house_style) === 4) {
abroadIds.push(list[i].connect_id);
} }
} }
let newTaskFilter = {
attributes: ['id'], where: { status: 'online', valid: 1, id: { $in: newIds } }
}
let rentalTaskFilter = {
attributes: ['id'], where: { status: 'online', valid: 1, id: { $in: rentalIds } }
}
let abroadTaskFilter = {
attributes: ['id'], where: { status: 'online', valid: 1, id: { $in: abroadIds } }
}
let taskList = [
ctx.realestateModel.NewHouse.findAll(newTaskFilter),
ctx.realestateModel.RentalHouse.findAll(rentalTaskFilter),
ctx.realestateModel.AbroadHouse.findAll(abroadTaskFilter),
];
const retList = await Promise.all(taskList).then(result => { const retList = await Promise.all(taskList).then(result => {
return result; return result;
}).catch(error => { }).catch(error => {
ctx.failed(error); ctx.failed(error);
}); });
count = Number(retList.length);
let validNewIds = _.map(retList[0], 'id');
let validRentalIds = _.map(retList[1], 'id');
let validAbroadIds = _.map(retList[2], 'id');
for (let i in list) {
if (Number(list[i].house_style) === 1 && validNewIds.includes(Number(list[i].connect_id))) {
count++;
}
if (Number(list[i].house_style) === 2 && validRentalIds.includes(Number(list[i].connect_id))) {
count++;
}
if (Number(list[i].house_style) === 4 && validAbroadIds.includes(Number(list[i].connect_id))) {
count++;
}
}
} }
let ret = { let ret = {
count: count count: count
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
'use strict'; 'use strict';
const Service = require('egg').Service; const Service = require('egg').Service;
const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
class searchHistoryService extends Service { class searchHistoryService extends Service {
...@@ -50,7 +51,9 @@ class searchHistoryService extends Service { ...@@ -50,7 +51,9 @@ class searchHistoryService extends Service {
} }
}; };
//不管有没有登录获取城市相关的热门搜索 //不管有没有登录获取城市相关的热门搜索
ret.hot_search.results = await ctx.service.house.v2.hotSearch.getHotSearch(condition); if (condition.type && [1, 2].includes(condition.type)) {
ret.hot_search.results = await ctx.service.house.v2.hotSearch.getHotSearch(condition);
}
if (!ctx.appUserId || !ctx.userId) { if (!ctx.appUserId || !ctx.userId) {
//如果没有登录就返回 //如果没有登录就返回
...@@ -124,14 +127,7 @@ class searchHistoryService extends Service { ...@@ -124,14 +127,7 @@ class searchHistoryService extends Service {
order: [['created_at', 'desc']], order: [['created_at', 'desc']],
} }
let searchHistoryList = await ctx.realestateModel.SearchHistory.findAll(filter); let searchHistoryList = await ctx.realestateModel.SearchHistory.findAll(filter);
let list = []; let list = _.uniq(_.map(searchHistoryList, 'key_word'));
if (searchHistoryList.length > 0) {
for (let i in searchHistoryList) {
if (list.indexOf(searchHistoryList[i].key_word) === -1) {
list.push(searchHistoryList[i].key_word);
}
}
}
ret = { ret = {
results: list, results: list,
count: list.length count: list.length
......
...@@ -139,8 +139,8 @@ module.exports = appInfo => { ...@@ -139,8 +139,8 @@ module.exports = appInfo => {
}; };
config.PHP_URL = 'https://kaifa.jianbing.com'; config.PHP_URL = 'https://kaifa.jianbing.com';
config.NODE_URL = 'https://uat-nginx.jianbing.com/user_api/v1'; config.NODE_URL = 'https://dev-nginx.jianbing.com/user_api/v1';
config.NODE_BASE_URL = 'https://uat-nginx.jianbing.com'; config.NODE_BASE_URL = 'https://dev-nginx.jianbing.com';
config.HOUSE_SERVICE_API = 'https://uat-nginx.jianbing.com/house-service'; config.HOUSE_SERVICE_API = 'https://uat-nginx.jianbing.com/house-service';
config.CDN_BASE_URL = 'https://r.51gjj.com/image/'; config.CDN_BASE_URL = 'https://r.51gjj.com/image/';
......
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