$params['title'], 'desc' => $params['desc'] ?? '', 'author' => $params['author'] ?? '', //作者 'sort' => $params['sort'] ?? 0, // 排序 'abstract' => $params['abstract'], // 文章摘要 'click_virtual' => $params['click_virtual'] ?? 0, 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '', 'cid' => $params['cid'], 'is_show' => $params['is_show'], 'is_popup' => $params['is_popup'], 'is_notice' => $params['is_notice'], 'is_sys_notice' => $params['is_sys_notice'], 'content' => $params['content'] ?? '', 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE), ]); if($params['is_sys_notice'] == 1){ $users = User::select()->toArray(); foreach ($users as &$user) { UserNotice::create([ 'user_id' => $user['id'], 'article_id' => $article['id'], 'title' => $article['title'], 'content' => $article['content'] ?? '', 'langs' => $article['langs'], ]); } } } /** * @notes 编辑资讯 * @param array $params * @return bool * @author heshihu * @date 2022/2/22 10:12 */ public static function edit(array $params) : bool { try { $langs = $params['langs']; foreach ($langs as &$content_lang) { $content_lang['image'] = FileService::setFileUrl($content_lang['image']); $content_lang['content'] = clear_file_domain($content_lang['content']); } $article = Article::update([ 'id' => $params['id'], 'title' => $params['title'], 'desc' => $params['desc'] ?? '', // 简介 'author' => $params['author'] ?? '', //作者 'sort' => $params['sort'] ?? 0, // 排序 'abstract' => $params['abstract'], // 文章摘要 'click_virtual' => $params['click_virtual'] ?? 0, 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '', 'cid' => $params['cid'], 'is_show' => $params['is_show'], 'is_popup' => $params['is_popup'], 'is_notice' => $params['is_notice'], 'is_sys_notice' => $params['is_sys_notice'], 'content' => $params['content'] ?? '', 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE), ]); if($params['is_sys_notice'] == 1){ $notices = UserNotice::where(['article_id' => $params['id']])->select()->toArray(); foreach ($notices as &$notice) { UserNotice::update([ 'id' => $notice['id'], 'title' => $article['title'], 'content' => $article['content'] ?? '', 'langs' => $article['langs'], ]); } } return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } /** * @notes 删除资讯 * @param array $params * @author heshihu * @date 2022/2/22 10:17 */ public static function delete(array $params) { Article::destroy($params['id']); } /** * @notes 查看资讯详情 * @param $params * @return array * @author heshihu * @date 2022/2/22 10:15 */ public static function detail($params) : array { $article = Article::findOrEmpty($params['id'])->toArray(); $langs = json_decode($article['langs'], true); if(!empty($langs)){ foreach ($langs as &$content_lang) { $content_lang['image'] = FileService::getFileUrl($content_lang['image']); $content_lang['content'] = get_file_domain($content_lang['content']); } }else{ $langs = []; } $article['langs'] = $langs; return $article; } /** * @notes 更改资讯状态 * @param array $params * @return bool * @author heshihu * @date 2022/2/22 10:18 */ public static function updateStatus(array $params) { Article::update([ 'id' => $params['id'], 'is_show' => $params['is_show'] ]); return true; } /** * @notes 资讯列表 * @param $params * @return array * @author BD * @date 2024/03/17 17:01 */ public static function all($params) : array { $field = ['id', 'title']; $articles = Article::field($field) ->where(['cid' => $params['cid'],'is_show' => 1]) ->order(['sort' => 'desc','id' => 'desc']) ->select()->toArray(); return $articles; } }