You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.2 KiB

<?php
namespace app\integral\logic;
use app\integral\model\IntegralSearchHistory;
use app\integral\model\IntegralSearchHot;
class Search extends Base
{
/**
* 获取热门搜索
* @date 2022-11-18
*/
public function listHotSearch()
{
$search_model = new IntegralSearchHot();
//获取商城热门搜索
$search_hot_list = $search_model->getAllData([
['uid', '=', $this->mid]
], 'id,content', 'sort desc');
return sendSuccessArray([
// 热门搜索列表
'search_hot_list' => $search_hot_list
]);
}
/**
* 获取历史搜索
* @date 2022-11-18
*/
public function listHistorySearch()
{
$search_model = new IntegralSearchHistory();
// 获取商城历史搜索
$search_history_list = $search_model->getAllData([
['uid', '=', $this->mid],
['user_id', '=', $this->userId],
], 'id,content', 'update_time desc', '10');
return sendSuccessArray([
// 历史搜索列表
'search_history_list' => $search_history_list
]);
}
/**
* 添加历史搜索
* @param string $keyword 关键字
* @date 2022-11-18
*/
public function insertHistorySearch($keyword)
{
$search_model = new IntegralSearchHistory();
// 添加历史搜索
$data = [
'uid' => $this->mid,
'user_agent' => $this->userAgent,
'user_id' => $this->userId,
'content' => $keyword
];
$res = $search_model->updateSearch($data);
if (!$res) {
return sendErrorArray(3001, '添加失败');
}
return sendSuccessArray();
}
/**
* 清空历史搜索
* @date 2022-11-18
*/
public function deleteAllHistorySearch()
{
$search_model = new IntegralSearchHistory();
// 删除商城历史搜索
$res = $search_model->dataDestory([
['uid', '=', $this->mid],
['user_id', '=', $this->userId],
]);
if (!$res) {
return sendErrorArray(3001, '删除失败');
}
return sendSuccessArray();
}
}