0){ $data_title = $data['title']; $data_content = $data['content']; } $article['content'] = get_file_domain($data_content); $article['title'] = $data_title; unset($article['langs']); return $article; } /** * @notes 提示内容详情 * @param $params * @return array * @author 段誉 * @date 2022/9/20 17:09 */ public static function hintDetail($params) { //未传语言,则默认使用首个语言 if($params['lang'] == ''){ $first_lang = UtilsService::get_first_lang(); $params['lang'] = $first_lang['symbol']; } $hint = DecorateHint::field(['content','langs'])->findOrEmpty($params['id'])->toArray(); //多语言替换 $data = UtilsService::get_langs_data($hint['langs'],$params['lang']); $data_content = ''; if(count($data) > 0){ $data_content = $data['content']; } $hint['content'] = get_file_domain($data_content); unset($hint['langs']); return $hint; } /** * @notes 加入收藏 * @param $userId * @param $articleId * @author 段誉 * @date 2022/9/20 16:52 */ public static function addCollect($articleId, $userId) { $where = ['user_id' => $userId, 'article_id' => $articleId]; $collect = ArticleCollect::where($where)->findOrEmpty(); if ($collect->isEmpty()) { ArticleCollect::create([ 'user_id' => $userId, 'article_id' => $articleId, 'status' => YesNoEnum::YES ]); } else { ArticleCollect::update([ 'id' => $collect['id'], 'status' => YesNoEnum::YES ]); } } /** * @notes 取消收藏 * @param $articleId * @param $userId * @author 段誉 * @date 2022/9/20 16:59 */ public static function cancelCollect($articleId, $userId) { ArticleCollect::update(['status' => YesNoEnum::NO], [ 'user_id' => $userId, 'article_id' => $articleId, 'status' => YesNoEnum::YES ]); } /** * @notes 文章分类 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/9/23 14:11 */ public static function cate() { return ArticleCate::field('id,name') ->where('is_show', '=', 1) ->order(['sort' => 'desc', 'id' => 'desc']) ->select()->toArray(); } }