From d0697ac6580efbedfd98295581c1ec41d1a7d65c Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Sat, 4 Sep 2021 20:18:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Command/InstallCommand.php | 1 - app/Command/TestCommand.php | 1 - app/Exception/ResponseException.php | 1 + app/Listener/DbQueryExecutedListener.php | 2 +- app/Listener/QueueHandleListener.php | 2 +- .../ValidatorFactoryResolvedListener.php | 1 + app/Middleware/CorsMiddleware.php | 1 + app/Service/ArticleService.php | 110 +++++++++--------- app/Service/EmoticonService.php | 12 +- app/Service/MailerService.php | 13 ++- app/Service/Message/FormatMessageService.php | 2 +- app/Support/{Mail.php => Mailer.php} | 2 +- app/Support/SendEmailCode.php | 1 + app/Support/UserRelation.php | 3 +- app/helper.php | 4 +- doc/README.md | 1 + .../sql/LumenIM 同步SQL.sql | 0 更新计划.md | 0 18 files changed, 80 insertions(+), 77 deletions(-) rename app/Support/{Mail.php => Mailer.php} (99%) create mode 100644 doc/README.md rename LumenIM 同步SQL.sql => doc/sql/LumenIM 同步SQL.sql (100%) delete mode 100644 更新计划.md diff --git a/app/Command/InstallCommand.php b/app/Command/InstallCommand.php index e6f3bdf..85df9b1 100644 --- a/app/Command/InstallCommand.php +++ b/app/Command/InstallCommand.php @@ -1,5 +1,4 @@ where('user_id', $user_id)->where('status', 1)->groupBy(['class_id']); + return ArticleClass::leftJoinSub($subJoin, 'sub_join', function ($join) { $join->on('article_class.id', '=', 'sub_join.class_id'); - })->where('article_class.user_id', $user_id) - ->orderBy('article_class.sort') - ->get($fields) - ->toArray(); + })->where('article_class.user_id', $user_id)->orderBy('article_class.sort')->get($fields)->toArray(); } /** @@ -49,7 +48,7 @@ class ArticleService extends BaseService * @param int $user_id 用户ID * @return array */ - public function getUserTags(int $user_id) + public function getUserTags(int $user_id): array { $items = ArticleTag::where('user_id', $user_id)->orderBy('id', 'desc')->get(['id', 'tag_name', Db::raw('0 as count')])->toArray(); foreach ($items as $k => $item) { @@ -68,47 +67,40 @@ class ArticleService extends BaseService * @param array $params 查询参数 * @return array */ - public function getUserArticleList(int $user_id, int $page, int $page_size, $params = []) + public function getUserArticleList(int $user_id, int $page, int $page_size, $params = []): array { $filed = ['article.id', 'article.class_id', 'article.title', 'article.image', 'article.abstract', 'article.updated_at', 'article_class.class_name', 'article.status']; - $countSqlObj = Article::select(); - $rowsSqlObj = Article::select($filed) + $model = Article::select($filed) ->leftJoin('article_class', 'article_class.id', '=', 'article.class_id'); - $countSqlObj->where('article.user_id', $user_id); - $rowsSqlObj->where('article.user_id', $user_id); + $model->where('article.user_id', $user_id); if ($params['find_type'] == 3) { - $countSqlObj->where('article.class_id', $params['class_id']); - $rowsSqlObj->where('article.class_id', $params['class_id']); + $model->where('article.class_id', $params['class_id']); } else if ($params['find_type'] == 4) { - $countSqlObj->whereRaw("FIND_IN_SET({$params['class_id']},tags_id)"); - $rowsSqlObj->whereRaw("FIND_IN_SET({$params['class_id']},tags_id)"); + $model->whereRaw("FIND_IN_SET({$params['class_id']},tags_id)"); } else if ($params['find_type'] == 2) { - $countSqlObj->where('article.is_asterisk', 1); - $rowsSqlObj->where('article.is_asterisk', 1); + $model->where('article.is_asterisk', 1); } - $countSqlObj->where('article.status', $params['find_type'] == 5 ? 2 : 1); - $rowsSqlObj->where('article.status', $params['find_type'] == 5 ? 2 : 1); + $model->where('article.status', $params['find_type'] == 5 ? 2 : 1); - if (isset($params['keyword'])) { - $countSqlObj->where('article.title', 'like', "%{$params['keyword']}%"); - $rowsSqlObj->where('article.title', 'like', "%{$params['keyword']}%"); + if (isset($params['keyword']) && !empty($params['keyword'])) { + $model->where('article.title', 'like', "%{$params['keyword']}%"); } - $count = $countSqlObj->count(); + $count = $model->count(); $rows = []; if ($count > 0) { if ($params['find_type'] == 1) { - $rowsSqlObj->orderBy('updated_at', 'desc'); + $model->orderBy('updated_at', 'desc'); $page_size = 20; } else { - $rowsSqlObj->orderBy('id', 'desc'); + $model->orderBy('id', 'desc'); } - $rows = $rowsSqlObj->forPage($page, $page_size)->get()->toArray(); + $rows = $model->forPage($page, $page_size)->get()->toArray(); } return $this->getPagingRows($rows, $count, $page, $page_size); @@ -121,18 +113,15 @@ class ArticleService extends BaseService * @param int $user_id 用户ID * @return array */ - public function getArticleDetail(int $article_id, $user_id = 0) + public function getArticleDetail(int $article_id, $user_id = 0): array { $info = Article::where('id', $article_id)->where('user_id', $user_id)->first(['id', 'class_id', 'tags_id', 'title', 'status', 'is_asterisk', 'created_at', 'updated_at']); - if (!$info) { - return []; - } + + if (!$info) return []; // 关联文章详情 $detail = $info->detail; - if (!$detail) { - return []; - } + if (!$detail) return []; $tags = []; if ($info->tags_id) { @@ -159,9 +148,9 @@ class ArticleService extends BaseService * * @param int $user_id 用户ID * @param int $article_id 笔记ID - * @return mixed + * @return array */ - public function findArticleAnnexAll(int $user_id, int $article_id) + public function findArticleAnnexAll(int $user_id, int $article_id): array { return ArticleAnnex::where([ ['user_id', '=', $user_id], @@ -220,7 +209,7 @@ class ArticleService extends BaseService * @return bool * @throws Exception */ - public function delArticleClass(int $user_id, int $class_id) + public function delArticleClass(int $user_id, int $class_id): bool { $result = ArticleClass::where('id', $class_id)->where('user_id', $user_id)->first(['id', 'sort']); if (!$result) return false; @@ -244,7 +233,7 @@ class ArticleService extends BaseService * @param int $sort_type 排序方式 * @return bool */ - public function articleClassSort(int $user_id, int $class_id, int $sort_type) + public function articleClassSort(int $user_id, int $class_id, int $sort_type): bool { if (!$info = ArticleClass::select(['id', 'sort'])->where('id', $class_id)->where('user_id', $user_id)->first()) { return false; @@ -308,7 +297,7 @@ class ArticleService extends BaseService * @param int $to_class_id 笔记分类ID * @return bool */ - public function mergeArticleClass(int $user_id, int $class_id, int $to_class_id) + public function mergeArticleClass(int $user_id, int $class_id, int $to_class_id): bool { $count = ArticleClass::whereIn('id', [$class_id, $to_class_id])->where('user_id', $user_id)->count(); if ($count < 2) { @@ -316,7 +305,8 @@ class ArticleService extends BaseService } return (bool)Article::where('class_id', $class_id)->where('user_id', $user_id)->update([ - 'class_id' => $to_class_id + 'class_id' => $to_class_id, + 'updated_at' => date('Y-m-d H:i:s') ]); } @@ -357,7 +347,7 @@ class ArticleService extends BaseService * @param int $tag_id 标签ID * @return bool */ - public function delArticleTags(int $uid, int $tag_id) + public function delArticleTags(int $uid, int $tag_id): bool { if (!ArticleTag::where('id', $tag_id)->where('user_id', $uid)->exists()) { return false; @@ -446,14 +436,18 @@ class ArticleService extends BaseService * @param int $status 笔记状态 1:正常 2:已删除 * @return bool */ - public function updateArticleStatus(int $user_id, int $article_id, int $status) + public function updateArticleStatus(int $user_id, int $article_id, int $status): bool { - $data = ['status' => $status]; + $data = [ + 'status' => $status, + 'updated_at' => date('Y-m-d H:i:s') + ]; + if ($status == 2) { $data['deleted_at'] = date('Y-m-d H:i:s'); } - return Article::where('id', $article_id)->where('user_id', $user_id)->update($data); + return (bool)Article::where('id', $article_id)->where('user_id', $user_id)->update($data); } /** @@ -464,9 +458,12 @@ class ArticleService extends BaseService * @param int $class_id 笔记分类ID * @return bool */ - public function moveArticle(int $user_id, int $article_id, int $class_id) + public function moveArticle(int $user_id, int $article_id, int $class_id): bool { - return (bool)Article::where('id', $article_id)->where('user_id', $user_id)->update(['class_id' => $class_id]); + return (bool)Article::where('id', $article_id)->where('user_id', $user_id)->update([ + 'class_id' => $class_id, + 'updated_at' => date('Y-m-d H:i:s') + ]); } /** @@ -477,10 +474,11 @@ class ArticleService extends BaseService * @param int $type 1:标记星号 2:取消星号标记 * @return bool */ - public function setAsteriskArticle(int $user_id, int $article_id, int $type) + public function setAsteriskArticle(int $user_id, int $article_id, int $type): bool { return (bool)Article::where('id', $article_id)->where('user_id', $user_id)->update([ - 'is_asterisk' => $type == 1 ? 1 : 0 + 'is_asterisk' => $type == 1 ? 1 : 0, + 'updated_at' => date('Y-m-d H:i:s') ]); } @@ -492,9 +490,12 @@ class ArticleService extends BaseService * @param array $tags 关联标签ID * @return bool */ - public function updateArticleTag(int $uid, int $article_id, array $tags) + public function updateArticleTag(int $uid, int $article_id, array $tags): bool { - return (bool)Article::where('id', $article_id)->where('user_id', $uid)->update(['tags_id' => implode(',', $tags), 'updated_at' => date('Y-m-d H:i:s')]); + return (bool)Article::where('id', $article_id)->where('user_id', $uid)->update([ + 'tags_id' => implode(',', $tags), + 'updated_at' => date('Y-m-d H:i:s') + ]); } /** @@ -553,7 +554,7 @@ class ArticleService extends BaseService * @param int $status 附件状态 1:正常 2:已删除 * @return bool */ - public function updateArticleAnnexStatus(int $user_id, int $annex_id, int $status) + public function updateArticleAnnexStatus(int $user_id, int $annex_id, int $status): bool { $data = ['status' => $status]; if ($status == 2) { @@ -569,7 +570,7 @@ class ArticleService extends BaseService * @param int $uid 用户ID * @return array */ - public function recoverAnnexList(int $uid) + public function recoverAnnexList(int $uid): array { return ArticleAnnex::join('article', 'article.id', '=', 'article_annex.article_id') ->where('article_annex.user_id', $uid) @@ -598,11 +599,6 @@ class ArticleService extends BaseService return false; } - // 将文件从磁盘中删除 - //if (!Storage::disk('uploads')->delete($info->save_dir)) { - // return false; - //} - return $info->delete(); } @@ -612,7 +608,7 @@ class ArticleService extends BaseService * @param int $user_id 用户id * @param int $article_id 笔记ID * @param array $annex 笔记附件信息 - * @return bool + * @return bool|int */ public function insertArticleAnnex(int $user_id, int $article_id, array $annex) { diff --git a/app/Service/EmoticonService.php b/app/Service/EmoticonService.php index 64a1a85..2a9f929 100644 --- a/app/Service/EmoticonService.php +++ b/app/Service/EmoticonService.php @@ -1,4 +1,5 @@ where('user_id', $user_id)->first(); if (!$info) { @@ -51,7 +52,7 @@ class EmoticonService extends BaseService * @param int $emoticon_id 表情包ID * @return bool */ - public function removeSysEmoticon(int $user_id, int $emoticon_id) + public function removeSysEmoticon(int $user_id, int $emoticon_id): bool { $info = UsersEmoticon::select(['id', 'user_id', 'emoticon_ids'])->where('user_id', $user_id)->first(); if (!$info || !in_array($emoticon_id, $info->emoticon_ids)) { @@ -78,9 +79,10 @@ class EmoticonService extends BaseService * @param int $user_id 用户ID * @return array */ - public function getInstallIds(int $user_id) + public function getInstallIds(int $user_id): array { $result = UsersEmoticon::where('user_id', $user_id)->value('emoticon_ids'); + return $result ? array_filter($result) : []; } @@ -91,7 +93,7 @@ class EmoticonService extends BaseService * @param int $record_id 聊天消息ID * @return array */ - public function collect(int $user_id, int $record_id) + public function collect(int $user_id, int $record_id): array { $result = TalkRecords::where([ ['id', '=', $record_id], @@ -153,7 +155,7 @@ class EmoticonService extends BaseService * @param array $where * @return array */ - public function getDetailsAll(array $where = []) + public function getDetailsAll(array $where = []): array { $items = EmoticonItem::where($where)->get(['id as media_id', 'url as src'])->toArray(); foreach ($items as $k => $item) { diff --git a/app/Service/MailerService.php b/app/Service/MailerService.php index ed43328..270b060 100644 --- a/app/Service/MailerService.php +++ b/app/Service/MailerService.php @@ -1,4 +1,5 @@ queueSwitch) { @@ -44,7 +45,7 @@ class MailerService * @param string $template 对应邮件模板 * @return bool */ - public function realSend(string $email, string $subject, string $template) + public function realSend(string $email, string $subject, string $template): bool { try { return $this->mail($email, $subject, $template); @@ -67,10 +68,10 @@ class MailerService $config = config('mail'); $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; - $mail->IsSMTP(); // 设定使用SMTP服务 - $mail->SMTPDebug = 0; // 关闭SMTP调试功能 - $mail->SMTPAuth = true; // 启用 SMTP 验证功能 - $mail->SMTPSecure = 'ssl'; // 使用安全协议 + $mail->IsSMTP(); // 设定使用SMTP服务 + $mail->SMTPDebug = 0; // 关闭SMTP调试功能 + $mail->SMTPAuth = true; // 启用 SMTP 验证功能 + $mail->SMTPSecure = 'ssl'; // 使用安全协议 $mail->Host = $config['host']; $mail->Port = $config['port']; $mail->Username = $config['username']; diff --git a/app/Service/Message/FormatMessageService.php b/app/Service/Message/FormatMessageService.php index b67479a..9d0a52f 100644 --- a/app/Service/Message/FormatMessageService.php +++ b/app/Service/Message/FormatMessageService.php @@ -181,7 +181,7 @@ class FormatMessageService ]; if ($rows[$k]['invite']['type'] == 1 || $rows[$k]['invite']['type'] == 3) { - $rows[$k]['invite']['users'] = User::select('id', 'nickname')->whereIn('id', parse_ids($invites[$row['id']]['user_ids']))->get()->toArray(); + $rows[$k]['invite']['users'] = User::select(['id', 'nickname'])->whereIn('id', parse_ids($invites[$row['id']]['user_ids']))->get()->toArray(); } else { $rows[$k]['invite']['users'] = $rows[$k]['invite']['operate_user']; } diff --git a/app/Support/Mail.php b/app/Support/Mailer.php similarity index 99% rename from app/Support/Mail.php rename to app/Support/Mailer.php index e0a56cb..4e243cc 100644 --- a/app/Support/Mail.php +++ b/app/Support/Mailer.php @@ -10,7 +10,7 @@ use PHPMailer\PHPMailer\PHPMailer; * * @package App\Support */ -class Mail +class Mailer { /** * @param string $address diff --git a/app/Support/SendEmailCode.php b/app/Support/SendEmailCode.php index d79151e..63b20e1 100644 --- a/app/Support/SendEmailCode.php +++ b/app/Support/SendEmailCode.php @@ -1,4 +1,5 @@ get(UserFriendService::class)->isFriend($user_id, $receiver_id, true); diff --git a/app/helper.php b/app/helper.php index 8e5ce4a..51a5f0c 100644 --- a/app/helper.php +++ b/app/helper.php @@ -132,11 +132,11 @@ function response() /** * 获取邮件助手 * - * @return \App\Support\Mail|mixed + * @return \App\Support\Mailer|mixed */ function email() { - return di()->get(App\Support\Mail::class); + return di()->get(App\Support\Mailer::class); } /** diff --git a/doc/README.md b/doc/README.md new file mode 100644 index 0000000..cd480c5 --- /dev/null +++ b/doc/README.md @@ -0,0 +1 @@ +# 文档说明 diff --git a/LumenIM 同步SQL.sql b/doc/sql/LumenIM 同步SQL.sql similarity index 100% rename from LumenIM 同步SQL.sql rename to doc/sql/LumenIM 同步SQL.sql diff --git a/更新计划.md b/更新计划.md deleted file mode 100644 index e69de29..0000000