-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
179 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,17 @@ | |
|
||
use DB; | ||
use Carbon\Carbon; | ||
use Exception; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\JsonResponse; | ||
use Zhiyi\Plus\Models\User; | ||
use Illuminate\Http\Request; | ||
use Zhiyi\Plus\Models\Comment; | ||
use Zhiyi\Plus\Models\UserCount; | ||
use Illuminate\Database\QueryException; | ||
use Zhiyi\Plus\Http\Controllers\Controller; | ||
use Zhiyi\Component\ZhiyiPlus\PlusComponentFeed\Models\Feed; | ||
use Zhiyi\Plus\Notifications\System as SystemNotification; | ||
use Zhiyi\Plus\Packages\Currency\Processes\User as UserProcess; | ||
use Zhiyi\Component\ZhiyiPlus\PlusComponentFeed\Models\FeedPinned; | ||
use Zhiyi\Component\ZhiyiPlus\PlusComponentFeed\Traits\PaginatorPage; | ||
|
@@ -40,7 +44,11 @@ class CommentController extends Controller | |
/** | ||
* 获取评论列表. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param Request $request | ||
* @param Comment $commentModel | ||
* @param Carbon $datetime | ||
* @param FeedPinned $feedPinned | ||
* @param User $user | ||
* @return mixed | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
|
@@ -191,13 +199,14 @@ public function show(Request $request, Comment $commentModel, Carbon $datetime, | |
* | ||
* @param Comment $comment | ||
* @return mixed | ||
* @throws Exception | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function delete(Comment $comment) | ||
{ | ||
DB::beginTransaction(); | ||
try { | ||
$pinnedComment = FeedPinned::whereNull('expires_at') | ||
$pinnedComment = FeedPinned::query()->whereNull('expires_at') | ||
->where('target', $comment->id) | ||
->where('channel', 'comment') | ||
->first(); | ||
|
@@ -207,11 +216,11 @@ public function delete(Comment $comment) | |
$pinnedComment->delete(); | ||
} | ||
// 统计被评论用户未操作的动态评论置顶 | ||
$unReadCount = FeedPinned::whereNull('expires_at') | ||
$unReadCount = FeedPinned::query()->whereNull('expires_at') | ||
->where('channel', 'comment') | ||
->where('target_user', $comment->target_user) | ||
->count(); | ||
$userCount = UserCount::firstOrNew([ | ||
$userCount = UserCount::query()->firstOrNew([ | ||
'type' => 'user-feed-comment-pinned', | ||
'user_id' => $comment->target_user, | ||
]); | ||
|
@@ -222,15 +231,23 @@ public function delete(Comment $comment) | |
$feed = new Feed(); | ||
$feed->where('id', $comment->commentable_id)->decrement('feed_comment_count'); // 统计相关动态评论数量 | ||
|
||
// TODO 用户评论统计,积分减少 | ||
|
||
// 通知用户评论被删除 | ||
$comment->user->notify(new SystemNotification('动态评论被管理员删除', [ | ||
'type' => 'delete:feed/comment', | ||
'comment' => [ | ||
'contents' => $comment->body, | ||
], | ||
'feed' => [ | ||
'id' => $comment->commentable_id, | ||
'type' => $comment->commentable_type | ||
] | ||
])); | ||
$comment->delete(); | ||
|
||
} catch (QueryException $e) { | ||
DB::rollBack(); | ||
|
||
return response()->json([ | ||
'message' => $e->formatMessage(), | ||
])->setStatusCode(500); | ||
throw $e; | ||
} | ||
DB::commit(); | ||
|
||
|
@@ -239,10 +256,10 @@ public function delete(Comment $comment) | |
|
||
/** | ||
* 同意评论置顶申请. | ||
* @param Request $request [description] | ||
* @param FeedPinned $pinned [description] | ||
* @param Carbon $datetime [description] | ||
* @return [type] [description] | ||
* @param Comment $comment | ||
* @param FeedPinned $pinned [description] | ||
* @param Carbon $datetime [description] | ||
* @return JsonResponse [type] [description] | ||
*/ | ||
public function accept(Comment $comment, FeedPinned $pinned, Carbon $datetime) | ||
{ | ||
|
@@ -309,7 +326,9 @@ public function set(Request $request, Comment $comment, FeedPinned $pinned, Carb | |
|
||
/** | ||
* 驳回评论置顶. | ||
* @param FeedPinned $pinned | ||
* @param FeedPinned $pinned | ||
* @return JsonResponse | ||
* @throws Exception | ||
*/ | ||
public function reject(FeedPinned $pinned) | ||
{ | ||
|
Oops, something went wrong.