lotteryAdmin(); abort_if($admin === null, 401); if ($denied = AdminSiteScope::denyUnlessPlayerAccessible($admin, $player)) { return $denied; } $hasWallets = Player::query() ->whereKey($player->getKey()) ->whereHas('wallets', static fn (HasMany $q) => $q->whereRaw('balance != 0')) ->exists(); if ($hasWallets) { return ApiResponse::error( '该玩家钱包仍有余额,请先清空后再删除', ErrorCode::ValidationFailed->value, null, 422, ); } $hasTickets = Player::query() ->whereKey($player->getKey()) ->whereHas('ticketOrders') ->exists(); if ($hasTickets) { return ApiResponse::error( '该玩家存在注单记录,无法删除', ErrorCode::ValidationFailed->value, null, 422, ); } $player->wallets()->delete(); $player->delete(); return ApiResponse::success(['deleted' => true]); } }