Skip to content

Commit

Permalink
chore: 解决前端通知问题 #774
Browse files Browse the repository at this point in the history
  • Loading branch information
boxshadow committed Aug 7, 2019
1 parent ee1fa0b commit e93025f
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]>
*/
Expand Down Expand Up @@ -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();
Expand All @@ -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,
]);
Expand All @@ -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();

Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit e93025f

Please sign in to comment.