Commit e62be838 authored by Hsinli's avatar Hsinli

addd

parent 02a2bfed
Pipeline #8897 passed with stage
in 21 seconds
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
const Service = require('egg').Service; const Service = require('egg').Service;
const moment = require('moment'); const moment = require('moment');
const _ = require('lodash');
const HOUSE_TYPE = [ const HOUSE_TYPE = [
{ name: '不限', min: 0, max: 0, value: 0, }, { name: '不限', min: 0, max: 0, value: 0, },
{ name: '1室', min: 1, max: 1, value: 1, }, { name: '1室', min: 1, max: 1, value: 1, },
...@@ -367,14 +368,27 @@ class NewHouseService extends Service { ...@@ -367,14 +368,27 @@ class NewHouseService extends Service {
if (condition.total_price && condition.total_price.hasOwnProperty('min') && condition.total_price.hasOwnProperty('max')) {//总价 if (condition.total_price && condition.total_price.hasOwnProperty('min') && condition.total_price.hasOwnProperty('max')) {//总价
filter.where.reference_total_price = { $between: [condition.total_price.min, condition.total_price.max] }; filter.where.reference_total_price = { $between: [condition.total_price.min, condition.total_price.max] };
} }
//根据户型的面积筛选 TODO //根据户型的面积筛选
// if (condition.area && condition.area.hasOwnProperty('min') && condition.area.hasOwnProperty('max')) { //根据户型筛选
// filter.where.area = { $between: [condition.area.min, condition.area.max] }; if ((condition.area && condition.area.hasOwnProperty('min') && condition.area.hasOwnProperty('max')) || condition.house_type) {
// } let newHouseTypeFilter = {
//户型 TODO attributes: ['new_house_id'],
// if (condition.house_type) { where: {
// filter.where.type = condition.house_type; status: 'online',
// } valid: 1
}
}
if (condition.house_type) {
newHouseTypeFilter.where.type = condition.house_type;
}
if ((condition.area && condition.area.hasOwnProperty('min') && condition.area.hasOwnProperty('max'))) {
newHouseTypeFilter.where.area = { $between: [condition.area.min, condition.area.max] };
}
let newHouseIds = await ctx.realestateModel.NewHouseType.all(newHouseTypeFilter);
let matchIds = _.uniq(_.map(newHouseIds, 'new_house_id'));
filter.where.id = { $in: matchIds };
}
if (condition.name) {//关键词搜索 模糊查询 if (condition.name) {//关键词搜索 模糊查询
//增加搜索历史 //增加搜索历史
let addHistory = { let addHistory = {
......
...@@ -68,27 +68,7 @@ class searchHistoryService extends Service { ...@@ -68,27 +68,7 @@ class searchHistoryService extends Service {
return ret; return ret;
} }
//用户的搜索记录 //用户的搜索记录
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss'); let list = await this.getSearchHistory(type);
let filter = {
limit: 50,
attributes: ['key_word'],
where: {
state: 1,
user_id: ctx.userId,
house_style: type,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']],
}
let searchHistoryList = await ctx.realestateModel.SearchHistory.findAll(filter);
let list = [];
if (searchHistoryList.length > 0) {
for (let i in searchHistoryList) {
if (list.indexOf(searchHistoryList[i].key_word) === -1) {
list.push(searchHistoryList[i].key_word);
}
}
}
ret.search_history = { ret.search_history = {
results: list, results: list,
count: list.length count: list.length
...@@ -127,8 +107,51 @@ class searchHistoryService extends Service { ...@@ -127,8 +107,51 @@ class searchHistoryService extends Service {
await ctx.realestateModel.SearchHistory.edit(updateFilter); await ctx.realestateModel.SearchHistory.edit(updateFilter);
} }
return ret; return ret;
}
/**
* 搜索历史
* 历史记录取用户最近6个月的搜索记录,去重处理,条数不超过50条
* 排序根据搜索时间逆序排列,距离当前时间近的排在前面,重复搜索的关键词取最近一次的搜索时间进行排序
* @param {*} type
*/
async getSearchHistory(type) {
const { ctx } = this;
let ret = {
results: [],
count: 0
};
if (!ctx.userId) {
//如果没有登录就返回
return ret;
}
//用户的搜索记录
let endDate = moment().subtract(6, 'months').format('YYYY-MM-DD HH:mm:ss');
let filter = {
limit: 50,
attributes: ['key_word'],
where: {
state: 1,
user_id: ctx.userId,
house_style: type,
created_at: { $gt: endDate }
},
order: [['created_at', 'desc']],
}
let searchHistoryList = await ctx.realestateModel.SearchHistory.findAll(filter);
let list = [];
if (searchHistoryList.length > 0) {
for (let i in searchHistoryList) {
if (list.indexOf(searchHistoryList[i].key_word) === -1) {
list.push(searchHistoryList[i].key_word);
}
}
}
ret = {
results: list,
count: list.length
};
return ret;
} }
} }
......
...@@ -17,7 +17,7 @@ module.exports = appInfo => { ...@@ -17,7 +17,7 @@ module.exports = appInfo => {
domainWhiteList: [], domainWhiteList: [],
}; };
config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ]; // config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ];
exports.multipart = { exports.multipart = {
// 不用steam用file // 不用steam用file
......
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