This commit is contained in:
2026-03-06 13:51:25 +08:00
parent 43022b8ff6
commit 3ad6b05bf8
5 changed files with 218 additions and 2 deletions
+22
View File
@@ -71,4 +71,26 @@ abstract class BaseController
}
return $userId;
}
/**
* 获取当前用户的公司ID
*/
protected function getCompanyId(Request $request): ?int
{
$token = $request->header('Authorization');
if ($token) {
$token = str_replace('Bearer ', '', $token);
}
if (!$token) {
return null;
}
$payload = \app\Util\JwtUtil::decode($token);
if (!$payload) {
return null;
}
return (int) ($payload['company_id'] ?? null);
}
}