-
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
2 changed files
with
2 additions
and
53 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
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 |
---|---|---|
|
@@ -708,56 +708,6 @@ protected function fillFeedBaseData(Request $request, FeedModel $feed): FeedMode | |
return $feed; | ||
} | ||
|
||
/** | ||
* Delete comment. | ||
* | ||
* @param Request $request | ||
* @param ResponseContract $response | ||
* @param FeedRepository $repository | ||
* @param FeedModel $feed | ||
* @return mixed | ||
* @author Seven Du <[email protected]> | ||
*/ | ||
public function destroy( | ||
Request $request, | ||
ResponseContract $response, | ||
FeedModel $feed | ||
) { | ||
$user = $request->user(); | ||
if ($user->id !== $feed->user_id && ! $user->ability('[feed] Delete Feed')) { | ||
return $response->json(['message' => '你没有权限删除动态'])->setStatusCode(403); | ||
} | ||
$feed->getConnection()->transaction(function () use ($feed, $user) { | ||
if ($pinned = $feed->pinned()->where('user_id', $user->id)->where('expires_at', null)->first()) { // 存在未审核的置顶申请时退款 | ||
$charge = new WalletChargeModel(); | ||
$charge->user_id = $user->id; | ||
$charge->channel = 'user'; | ||
$charge->account = 0; | ||
$charge->action = 1; | ||
$charge->amount = $pinned->amount; | ||
$charge->subject = '动态申请置顶退款'; | ||
$charge->body = sprintf('退还申请置顶动态《%s》的款项', str_limit($feed->feed_content, 100)); | ||
$charge->status = 1; | ||
|
||
$user->wallet()->increment('balance', $charge->amount); | ||
$user->walletCharges()->save($charge); | ||
$pinned->delete(); | ||
} | ||
|
||
// 删除话题关联 | ||
$feed->topics->each(function ($topic) { | ||
$topic->feeds_count -= 1; | ||
$topic->save(); | ||
}); | ||
$feed->topics()->sync([]); | ||
|
||
$feed->delete(); | ||
$user->extra()->decrement('feeds_count', 1); | ||
}); | ||
|
||
return $response->json(null, 204); | ||
} | ||
|
||
/** | ||
* 新版删除动态接口,如有置顶申请讲退还相应积分. | ||
* | ||
|
@@ -773,8 +723,7 @@ public function newDestroy( | |
FeedModel $feed | ||
) { | ||
$user = $request->user(); | ||
|
||
if ($user->id !== $feed->user_id) { | ||
if ($user->id !== $feed->user_id && ! $user->ability('[feed] Delete Feed')) { | ||
return $response->json(['message' => '你没有权限删除动态'])->setStatusCode(403); | ||
} | ||
|
||
|