- 基础环境:Docker 部署配置,源码挂载实时同步 - 修复:super_admin 权限补全、登录重定向循环 - 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单) - 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单) - 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单) - 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器 - 各平台独立表结构和视图,互不影响
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Traits\Companies;
|
|
use App\Traits\Modules;
|
|
use App\Traits\Users;
|
|
use Closure;
|
|
use Illuminate\Auth\AuthenticationException;
|
|
|
|
class IdentifyCompany
|
|
{
|
|
use Companies, Modules, Users;
|
|
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @param string[] ...$guards
|
|
* @return mixed
|
|
*
|
|
* @throws \Illuminate\Auth\AuthenticationException
|
|
*/
|
|
public function handle($request, Closure $next, ...$guards)
|
|
{
|
|
$this->request = $request;
|
|
|
|
$company_id = $this->getCompanyId();
|
|
|
|
if (empty($company_id)) {
|
|
if (request_is_mcp($this->request) || $this->request->bearerToken()) {
|
|
throw new AuthenticationException('Unauthenticated.', $guards);
|
|
}
|
|
|
|
abort(400, 'Missing company');
|
|
}
|
|
|
|
// Check if user can access company
|
|
if ($this->request->isNotSigned($company_id) && $this->isNotUserCompany($company_id)) {
|
|
throw new AuthenticationException('Unauthenticated.', $guards);
|
|
}
|
|
|
|
// Set company as current
|
|
$company = company($company_id);
|
|
|
|
if (empty($company)) {
|
|
abort(404, 'Company not found');
|
|
}
|
|
|
|
$company->makeCurrent();
|
|
|
|
// Load company-specific modules (event listeners, providers)
|
|
$this->registerModules();
|
|
|
|
// Fix file/folder paths
|
|
config(['filesystems.disks.' . config('filesystems.default') . '.url' => url('/' . $company_id) . '/uploads']);
|
|
|
|
// Fix routes
|
|
if ($this->request->isNotApi()) {
|
|
app('url')->defaults(['company_id' => $company_id]);
|
|
$this->request->route()->forgetParameter('company_id');
|
|
}
|
|
|
|
return $next($this->request);
|
|
}
|
|
}
|