发布推送
This commit is contained in:
59
app/Http/Controllers/Follow/FollowController.php
Normal file
59
app/Http/Controllers/Follow/FollowController.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Follow;
|
||||
|
||||
use App\Exceptions\ModelException;
|
||||
use App\Http\Controllers\Base\BaseController;
|
||||
use App\Models\Follow\FollowHistoryModel;
|
||||
use App\Models\Follow\FollowModel;
|
||||
use App\Service\AuthService;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class FollowController extends BaseController
|
||||
{
|
||||
|
||||
public array $validateMethodParams = [
|
||||
'addFollow' => [
|
||||
'uid' => 'required|numeric|max:15',
|
||||
],
|
||||
'unFollow' => [
|
||||
'uid' => 'required|numeric|max:15',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ModelException
|
||||
*/
|
||||
function addFollow()
|
||||
{
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
|
||||
$follow_uid = request()->input('uid');
|
||||
if($aUser['id'] == $follow_uid) return $this->error('不能关注自己');
|
||||
|
||||
$oFollowModel = new FollowModel();
|
||||
$aFollow = $oFollowModel->isFollow($aUser['id'], $follow_uid);
|
||||
if($aFollow) return $this->error('已关注');
|
||||
|
||||
$oFollowModel->addFollow($aUser['id'], $follow_uid);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
function unFollow()
|
||||
{
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
|
||||
$follow_uid = request()->input('uid');
|
||||
$oFollowModel = new FollowModel();
|
||||
$oFollowModel->unFollow($aUser['id'], $follow_uid);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user