setAccessible(true); $assertDispatchReady = new ReflectionMethod(WecomPromotionLogic::class, 'assertMemberDispatchReady'); $assertDispatchReady->setAccessible(true); $today = date('Y-m-d'); $members = [ ['id' => 1, 'admin_id' => 11, 'userid' => 'A', 'enabled' => 1, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today], ['id' => 2, 'admin_id' => 12, 'userid' => 'B', 'enabled' => 1, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today], ]; $result = $preview->invoke(null, $members, [11], 0, []); $assert($result['matched_ids'] === [1], '批量下线没有正确匹配员工规则'); $assert($result['update_ids'] === [1], '批量下线没有标记需要更新的规则'); $assert((int) $result['members'][0]['enabled'] === 0, '批量下线预览没有更新目标状态'); $assert((int) $result['members'][1]['enabled'] === 1, '批量下线错误修改了未选员工'); $result = $preview->invoke(null, [ [ 'id' => 3, 'admin_id' => 13, 'userid' => 'C', 'enabled' => 0, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today, 'active_start' => time() + 3600, ], ], [13], 1, []); $assert( $result['update_ids'] === [3] && (int) $result['members'][0]['enabled'] === 1, '尚未到生效时间的员工也应允许提前批量上线' ); try { $preview->invoke(null, $members, [11, 12], 0, [], '全员方案'); throw new RuntimeException('批量下线不应允许方案变成零上线员工'); } catch (ReflectionException $error) { throw $error; } catch (Throwable $error) { $assert(str_contains($error->getMessage(), '至少需要保留一名上线员工'), '零上线员工错误提示不正确'); } try { $preview->invoke(null, [ ['id' => 4, 'admin_id' => 14, 'userid' => 'D', 'enabled' => 1, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today], ['id' => 5, 'admin_id' => 15, 'userid' => 'E', 'enabled' => 1, 'daily_limit' => 1, 'today_count' => 1, 'today_date' => $today], ], [14], 0, [], '额度方案'); throw new RuntimeException('批量下线不应保留零个当前可用员工'); } catch (ReflectionException $error) { throw $error; } catch (Throwable $error) { $assert(str_contains($error->getMessage(), '当前可用'), '零可用员工错误提示不正确'); } $result = $preview->invoke(null, $members, [999], 0, []); $assert($result['matched_ids'] === [] && $result['update_ids'] === [], '不存在的员工不应产生状态更新'); $assertDispatchReady->invoke(null, ['blocked' => false, 'queued' => true]); try { $assertDispatchReady->invoke(null, ['blocked' => true, 'queued' => false]); throw new RuntimeException('同步阻塞时不应提交员工状态'); } catch (ReflectionException $error) { throw $error; } catch (Throwable $error) { $assert(str_contains($error->getMessage(), '无法同步'), '同步阻塞错误提示不正确'); } echo "WECOM_PROMOTION_BATCH_MEMBER_STATUS_OK\n";