module(); return $module === 'admin'; } protected static $forcedId = 0; /** * Open API 绑定当前工厂(无会员登录) * @param int $factoryId */ public static function bindFactory($factoryId) { self::$forcedId = (int)$factoryId; } /** * 当前会员所属工厂 ID * @return int */ public static function id() { if (self::$forcedId > 0) { return self::$forcedId; } $auth = FrontendAuth::instance(); if (!$auth || !$auth->isLogin()) { return 0; } return (int)$auth->factory_id; } /** * 当前操作员会员 ID * @return int */ public static function userId() { $auth = FrontendAuth::instance(); if (!$auth || !$auth->isLogin()) { return 0; } return (int)$auth->id; } /** * 是否工厂管理员 * @return bool */ public static function isOwner() { $auth = FrontendAuth::instance(); return $auth && $auth->isLogin() && $auth->factory_role === 'owner'; } /** * Open API 已按 Key 绑定工厂(无会员登录) * @return bool */ public static function isApiBound() { return self::$forcedId > 0; } /** * 未入厂则抛业务异常给 API 基类处理 * @return int */ public static function requireId() { $id = self::id(); if ($id <= 0 && !self::bypass()) { throw new \think\Exception('账号未绑定工厂'); } return $id; } }