Commit e62be838 authored by Hsinli's avatar Hsinli

addd

parent 02a2bfed
Pipeline #8897 passed with stage
in 21 seconds
......@@ -3,6 +3,7 @@
const Service = require('egg').Service;
const moment = require('moment');
const _ = require('lodash');
const HOUSE_TYPE = [
{ name: '不限', min: 0, max: 0, value: 0, },
{ name: '1室', min: 1, max: 1, value: 1, },
......@@ -367,14 +368,27 @@ class NewHouseService extends Service {
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] };
}
//根据户型的面积筛选 TODO
// if (condition.area && condition.area.hasOwnProperty('min') && condition.area.hasOwnProperty('max')) {
// filter.where.area = { $between: [condition.area.min, condition.area.max] };
// }
//户型 TODO
// if (condition.house_type) {
// filter.where.type = condition.house_type;
// }
//根据户型的面积筛选
//根据户型筛选
if ((condition.area && condition.area.hasOwnProperty('min') && condition.area.hasOwnProperty('max')) || condition.house_type) {
let newHouseTypeFilter = {
attributes: ['new_house_id'],
where: {
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) {//关键词搜索 模糊查询
//增加搜索历史
let addHistory = {
......
......@@ -68,27 +68,7 @@ class searchHistoryService extends Service {
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);
}
}
}
let list = await this.getSearchHistory(type);
ret.search_history = {
results: list,
count: list.length
......@@ -127,8 +107,51 @@ class searchHistoryService extends Service {
await ctx.realestateModel.SearchHistory.edit(updateFilter);
}
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 => {
domainWhiteList: [],
};
config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ];
// config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ];
exports.multipart = {
// 不用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