where(['is_show' => 1, 'is_recommend' => 1, 'del' => 0]) ->order(['sort' => 'desc', 'id' => 'desc']) ->limit(10) ->select()->toArray(); // 用户历史搜索记录 $history = []; if ($userId) { $where = [ 'del' => 0, 'user_id' => $userId ]; $sort = [ 'update_time' => 'desc', 'id' => 'desc' ]; $history = CommunitySearchRecord::where($where) ->order($sort) ->limit(10) ->column('keyword'); } return [ 'history' => $history, 'topic' => $topic ]; } /** * @notes 清空搜索记录 * @param $userId * @author 段誉 * @date 2022/5/9 16:58 */ public static function clear($userId) { CommunitySearchRecord::where('user_id', $userId)->update([ 'del' => 1, 'update_time' => time() ]); } /** * @notes 搜索记录 * @param $keyword * @param $user_id * @return CommunitySearchRecord|mixed|\think\Model * @author 段誉 * @date 2022/5/9 16:20 */ public static function recordKeyword($keyword, $user_id) { $record = CommunitySearchRecord::where([ 'user_id' => $user_id, 'keyword' => $keyword, 'del' => 0 ])->findOrEmpty(); if ($record->isEmpty()) { return CommunitySearchRecord::create([ 'user_id' => $user_id, 'keyword' => $keyword, ]); } return CommunitySearchRecord::incCount($record['id']); } }