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 f91ac6e commit 76a20d9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/slimkit-plus-feed/routes/api2.php
Expand Up @@ -45,9 +45,9 @@

// 动态
Route::post('/', 'FeedController@store')->middleware('sensitive:feed_content');
Route::delete('/{feed}', 'FeedController@destroy');
Route::patch('/{feed}/comment-paid', 'FeedPayController@commentPaid');

// 删除动态
Route::delete('/{feed}/currency', 'FeedController@newDestroy');

// 评论
Expand Down
53 changes: 1 addition & 52 deletions packages/slimkit-plus-feed/src/API2/FeedController.php
Expand Up @@ -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 <shiweidu@outlook.com>
*/
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);
}

/**
* 新版删除动态接口,如有置顶申请讲退还相应积分.
*
Expand All @@ -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);
}

Expand Down

0 comments on commit 76a20d9

Please sign in to comment.