Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
bcf50197
Commit
bcf50197
authored
Apr 11, 2019
by
Hsinli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add search history
parent
0e0e053e
Pipeline
#5866
passed with stage
in 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
1 deletion
+122
-1
search_history.js
app/controller/house/search_history.js
+26
-0
house.js
app/router/house.js
+2
-1
search_history.js
app/service/house/search_history.js
+94
-0
No files found.
app/controller/house/search_history.js
0 → 100644
View file @
bcf50197
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
searchHistoryController
extends
Controller
{
/**
* 获取预约列表
*/
async
getsearchHistory
()
{
const
{
ctx
}
=
this
;
//获取租房2和新房1的搜索记录
let
ret
=
{};
let
type
=
[
1
,
2
];
for
(
let
i
in
type
)
{
let
tag
=
type
[
i
]
===
1
?
'new_house'
:
'rental_house'
;
ret
[
tag
]
=
await
ctx
.
service
.
house
.
searchHistory
.
getSearchHistoryList
(
type
[
i
]);
}
ctx
.
success
(
ret
);
}
}
module
.
exports
=
searchHistoryController
;
app/router/house.js
View file @
bcf50197
...
@@ -27,7 +27,8 @@ module.exports = app => {
...
@@ -27,7 +27,8 @@ module.exports = app => {
router
.
post
(
'/collection'
,
loginAuth
,
'house.collection.addCollection'
);
//收藏
router
.
post
(
'/collection'
,
loginAuth
,
'house.collection.addCollection'
);
//收藏
router
.
get
(
'/collection/list'
,
loginAuth
,
'house.collection.getCollectionList'
);
//收藏列表
router
.
get
(
'/collection/list'
,
loginAuth
,
'house.collection.getCollectionList'
);
//收藏列表
//搜索历史
router
.
get
(
'/search_history'
,
'house.searchHistory.getsearchHistory'
);
//收藏列表
};
};
app/service/house/search_history.js
0 → 100644
View file @
bcf50197
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
moment
=
require
(
'moment'
);
class
searchHistoryService
extends
Service
{
/**
* 添加预约信息
* @param {object} inputParams
*/
async
addSearchHistory
(
inputParams
)
{
const
{
ctx
,
service
}
=
this
;
let
data
=
{
userId
:
ctx
.
userId
,
appUserId
:
ctx
.
appUserId
,
keyWord
:
inputParams
.
key_word
,
houseStyle
:
inputParams
.
type
,
state
:
1
,
};
let
ret
=
await
service
.
houseCommon
.
searchHistory
.
add
(
data
);
return
{
id
:
ret
.
id
};
}
/**
* 获取搜索历史
* 历史记录取用户最近6个月的搜索记录,去重处理,条数不超过50条
* 排序根据搜索时间逆序排列,距离当前时间近的排在前面,重复搜索的关键词取最近一次的搜索时间进行排序
* 如果没有搜索记录的就不显示搜索词
*/
async
getSearchHistoryList
(
type
)
{
const
{
ctx
,
service
}
=
this
;
let
ret
=
{
results
:
[],
count
:
0
};
if
(
!
ctx
.
appUserId
||
!
ctx
.
deviceId
||
!
ctx
.
deviceLoginId
||
!
ctx
.
userId
)
{
//如果没有登录就返回空
return
ret
;
}
let
endDate
=
moment
().
subtract
(
180
,
'days'
).
format
(
'YYYY-MM-DD HH:mm:ss'
);
let
filter
=
{
pageIndex
:
1
,
pageSize
:
50
,
queryConditions
:
[{
key
:
"state"
,
value
:
1
,
operator
:
"equal"
},
{
key
:
"userId"
,
value
:
ctx
.
userId
,
operator
:
"equal"
},
// {
// key: "createdAt",
// value: endDate,
// operator: "greater"
// },
],
orderConditions
:
[{
key
:
'createdAt'
,
orderSequence
:
'desc'
,
},],
}
if
(
type
)
{
let
typeCondition
=
{
key
:
"houseStyle"
,
value
:
type
,
operator
:
"equal"
};
filter
.
queryConditions
.
push
(
typeCondition
);
}
let
list
=
[];
let
searchHistoryList
=
await
service
.
houseCommon
.
searchHistory
.
all
(
filter
);
if
(
searchHistoryList
.
rowCount
>
0
)
{
for
(
let
i
in
searchHistoryList
.
results
)
{
if
(
list
.
indexOf
(
searchHistoryList
.
results
[
i
].
keyWord
)
===
-
1
)
{
list
.
push
(
searchHistoryList
.
results
[
i
].
keyWord
);
}
}
}
ctx
.
logger
.
info
(
list
);
ret
=
{
results
:
list
,
count
:
list
.
length
};
return
ret
;
}
}
module
.
exports
=
searchHistoryService
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment