On this page
取消关注api
controller层:application\api\controller\v1\User.php
php
// 取消关注
public function unfollow(){
(new UserValidate())->goCheck('unfollow');
(new UserModel())->ToUnFollow();
return self::showResCodeWithOutData('取消关注成功');
}
route层:route\route.php
php
// 用户操作(绑定手机)
Route::group('api/:v1/',function(){
// 取消关注
Route::post('unfollow','api/v1.User/unfollow');
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);
validate层:application\common\validate\UserValidate.php
php
protected $scene = [
'unfollow'=>['follow_id'],
];
model层:application\common\model\User.php
php
// 取消关注
public function ToUnFollow(){
// 获取所有参数
$params = request()->param();
// 获取用户id
$user_id = request()->userId;
$follow_id = $params['follow_id'];
// 不能取消关注自己
if($user_id == $follow_id) TApiException('非法操作',10000,200);
$followModel = $this->get($user_id)->withfollow();
$follow = $followModel->where('follow_id',$follow_id)->find();
if(!$follow) TApiException('暂未关注',10000,200);
$follow->delete();
}