83 lines
3.0 KiB
PHP
83 lines
3.0 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, "'del_external_contact'")
|
|
&& str_contains($methodSource, 'surviving_del.event_time >= surviving_e.event_time'),
|
|
'加粉统计必须继续识别区间内已删除客户'
|
|
);
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, "['add_external_contact', \$startTimestamp]"),
|
|
'加粉统计必须继续排除区间开始前已添加的重加客户'
|
|
);
|
|
conversionFanRuleExpect(
|
|
str_contains($methodSource, "->group('e.user_id, e.external_userid')"),
|
|
'加粉统计必须继续按员工和客户去重'
|
|
);
|
|
|
|
$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, '区间新增加粉(含已删除)'),
|
|
'页面口径须说明加粉包含已删除客户,且不能继续宣称依赖会话存档同意'
|
|
);
|
|
|
|
echo "Conversion fan event rule: OK\n";
|