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

移出黑名单api


controller层:application\api\controller\v1\Blacklist.php

php
// 移除黑名单
public function removeBlack(){
    (new BlacklistValidate())->goCheck();
    (new BlacklistModel())->removeBlack();
    return self::showResCodeWithOutData('移除黑名单成功');
}

route层:route\route.php

php
// 用户操作(绑定手机)
Route::group('api/:v1/',function(){
	// 移出黑名单
    Route::post('removeblack','api/:v1.Blacklist/removeBlack');
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);

model层:application\common\model\Blacklist.php

php
// 移出黑名单
public function removeBlack(){
    $param = request()->param();
    $user_id = request()->userId;
    $black_id = $param['id'];
    // 不能拉黑自己
    if ($user_id == $black_id) TApiException('非法操作',50000,200); 
    $black = $this->where([ 
        'user_id'=>$user_id, 
        'black_id'=>$black_id 
    ])->find();
    // 记录不存在
    if (!$black) TApiException('对方已不在你的黑名单内',40002,200);
    // 直接删除
    if (!$black->delete()) TApiException();
    return true;
}