99 lines
3.9 KiB
PHP
99 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use app\adminapi\logic\stats\ConversionLogic;
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
function conversionFanRuleExpect(bool $condition, string $message): void
|
|
{
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
}
|
|
|
|
$method = new ReflectionMethod(ConversionLogic::class, 'loadFanDetailRows');
|
|
$sourceLines = file($method->getFileName());
|
|
if ($sourceLines === false) {
|
|
throw new RuntimeException('无法读取加粉统计源码');
|
|
}
|
|
$methodSource = implode('', array_slice(
|
|
$sourceLines,
|
|
$method->getStartLine() - 1,
|
|
$method->getEndLine() - $method->getStartLine() + 1
|
|
));
|
|
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, "->where('e.change_type', 'add_external_contact')"),
|
|
'加粉必须继续以企微 add_external_contact 事件为事实来源'
|
|
);
|
|
conversionFanRuleExpect(
|
|
!str_contains($methodSource, 'msg_audit_approved'),
|
|
'会话存档同意是独立能力,不能再次成为加粉统计的硬性条件'
|
|
);
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, 'surviving_del.change_type = ?')
|
|
&& str_contains($methodSource, 'surviving_del.id > surviving_e.id'),
|
|
'加粉统计必须继续识别员工+客户组合的期末删除状态'
|
|
);
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, 'e.id AS add_event_id')
|
|
&& str_contains($methodSource, 'e.event_time AS add_time'),
|
|
'加粉统计必须保留组合最早新增事件用于渠道和时间归属'
|
|
);
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, 'prev_e.user_id = e.user_id')
|
|
&& str_contains($methodSource, 'prev_e.external_userid = e.external_userid')
|
|
&& str_contains($methodSource, 'earlier_e.user_id = e.user_id')
|
|
&& str_contains($methodSource, 'earlier_e.external_userid = e.external_userid'),
|
|
'加粉统计必须以员工+客户为组合键,不能只按客户跨员工去重'
|
|
);
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, "['add_external_contact', \$startTimestamp]"),
|
|
'同一员工+客户在区间开始前已经存在时不能再次算新增组合'
|
|
);
|
|
conversionFanRuleExpect(
|
|
substr_count($methodSource, 'MediaChannelService::applyExternalUserEventChannelFilter(') === 2
|
|
&& str_contains($methodSource, "'e.id'")
|
|
&& str_contains($methodSource, "'e.external_userid'")
|
|
&& str_contains($methodSource, "'e.user_id'"),
|
|
'有效与已删加粉都必须按事件ID及同一员工读取渠道快照'
|
|
);
|
|
|
|
$excludeMethod = new ReflectionMethod(ConversionLogic::class, 'excludeUncountedFanPairs');
|
|
$excludeSource = implode('', array_slice(
|
|
$sourceLines,
|
|
$excludeMethod->getStartLine() - 1,
|
|
$excludeMethod->getEndLine() - $excludeMethod->getStartLine() + 1
|
|
));
|
|
conversionFanRuleExpect(
|
|
str_contains($excludeSource, '[1, 2, 3, 201, 202]'),
|
|
'取消会话存档条件后仍须排除扫一扫、搜手机号、名片分享及继承/分配客户'
|
|
);
|
|
|
|
$buildCountMethod = new ReflectionMethod(ConversionLogic::class, 'buildFanCountRows');
|
|
$buildCountSource = implode('', array_slice(
|
|
$sourceLines,
|
|
$buildCountMethod->getStartLine() - 1,
|
|
$buildCountMethod->getEndLine() - $buildCountMethod->getStartLine() + 1
|
|
));
|
|
conversionFanRuleExpect(
|
|
str_contains($buildCountSource, "++\$countsByUser[\$userId]['add_fans_count']")
|
|
&& str_contains($buildCountSource, "++\$countsByUser[\$userId]['deleted_fans_count']"),
|
|
'区间内已删除客户必须计入加粉总数,并同时计入已删除提示子集'
|
|
);
|
|
|
|
$pageSource = file_get_contents(
|
|
dirname(__DIR__, 2) . '/admin/src/views/first_visit/conversion/index.vue'
|
|
);
|
|
conversionFanRuleExpect(
|
|
is_string($pageSource)
|
|
&& !str_contains($pageSource, '须会话同意')
|
|
&& str_contains($pageSource, '同一员工的同一客户只计一次')
|
|
&& str_contains($pageSource, '同一客户进入不同员工分别计数'),
|
|
'页面口径须说明按员工+客户去重且不同员工分别计数'
|
|
);
|
|
|
|
echo "Conversion fan event rule: OK\n";
|