Skip to content

Commit

Permalink
fix(动态): 修复动态删除扣除删除者数量问题
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Nov 27, 2018
1 parent 2134e48 commit f76e758
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/slimkit-plus-feed/src/API2/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,19 +710,28 @@ protected function fillFeedBaseData(Request $request, FeedModel $feed): FeedMode
/**
* 新版删除动态接口,如有置顶申请讲退还相应积分.
*
* @param Request $request
* @param ResponseContract $response
* @param FeedModel $feed
* @return mixed
* @author BS <[email protected]>
*/
public function newDestroy(
Request $request,
ResponseContract $response,
FeedModel $feed
) {
$user = $request->user();
if ($user->id !== $feed->user_id && ! $user->ability('[feed] Delete Feed')) {
$user = $feed->user;
if (! $user) {
// 删除话题关联
$feed->topics->each(function ($topic) {
$topic->feeds_count -= 1;
$topic->save();
});
$feed->topics()->sync([]);

$feed->delete();

return $response->json(null, 204);
} elseif ($user->id !== $feed->user_id && ! $user->ability('[feed] Delete Feed')) {
return $response->json(['message' => '你没有权限删除动态'])->setStatusCode(403);
}

Expand Down

0 comments on commit f76e758

Please sign in to comment.