Skip to content
关注公众号,获取新课通知
【重要通知】uniapp实战社区交友交流群更换为:602180461,靓仔/靓女可以重新申请加入哦~

取消关注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();
}