initialize(); $admin = Db::name('admin')->where('root', 1)->whereNull('delete_time')->find(); if (!$admin) { throw new RuntimeException('未找到 root 管理员,无法执行数据范围冒烟测试'); } $overview = WecomPromotionLogic::overview((int) $admin['id'], $admin, 'https://example.test'); foreach (['meta', 'config', 'summary', 'pools', 'links', 'member_options'] as $key) { if (!array_key_exists($key, $overview)) { throw new RuntimeException("overview 缺少 {$key}"); } } if (!str_ends_with((string) ($overview['config']['callback_url'] ?? ''), '/api/qywx/external-contact/notify')) { throw new RuntimeException('overview 未返回正确的获客消息回调地址'); } foreach ($overview['member_options'] as $member) { if (empty($member['id']) || empty($member['userid'])) { throw new RuntimeException('member_options 返回了未绑定企业微信 userid 的成员'); } } $scopedAdmin = Db::name('admin')->where('root', 0)->whereNull('delete_time')->order('id', 'asc')->find(); if ($scopedAdmin) { $visibleIds = DataScopeService::getVisibleAdminIds((int) $scopedAdmin['id'], $scopedAdmin); $scopedOverview = WecomPromotionLogic::overview((int) $scopedAdmin['id'], $scopedAdmin, 'https://example.test'); if ($visibleIds !== null) { foreach ($scopedOverview['member_options'] as $member) { if (!in_array((int) $member['id'], $visibleIds, true)) { throw new RuntimeException('member_options 泄露了当前角色或部门范围外的成员'); } } foreach ($scopedOverview['pools'] as $pool) { if (!in_array((int) $pool['owner_admin_id'], $visibleIds, true)) { throw new RuntimeException('pools 泄露了当前角色或部门范围外的数据'); } } } } echo sprintf( "WECOM_PROMOTION_OVERVIEW_SMOKE_OK configured=%d callback=%d pools=%d links=%d members=%d\n", !empty($overview['config']['ready']) ? 1 : 0, !empty($overview['config']['callback_ready']) ? 1 : 0, count($overview['pools']), count($overview['links']), count($overview['member_options']) );