On this page
移出黑名单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;
}