更新
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use app\adminapi\logic\firstvisit\WecomAcquisitionCustomerLogic;
|
||||
use app\common\service\DataScope\DataScopeService;
|
||||
use app\common\service\qywx\QywxCustomerAcquisitionApiService;
|
||||
use app\common\service\qywx\QywxCustomerAcquisitionCustomerService;
|
||||
use think\facade\Db;
|
||||
@@ -34,6 +35,15 @@ $linkId = '__smoke_link_' . $suffix;
|
||||
$externalUserId = '__smoke_external_' . $suffix;
|
||||
$userId = '__smoke_user_' . $suffix;
|
||||
$eventTime = time();
|
||||
$scopedAdmin = null;
|
||||
foreach (Db::name('admin')->where('root', 0)->whereNull('delete_time')->select()->toArray() as $candidate) {
|
||||
$candidateVisibleIds = DataScopeService::getVisibleAdminIds((int) $candidate['id'], $candidate);
|
||||
if (is_array($candidateVisibleIds) && $candidateVisibleIds !== []) {
|
||||
$scopedAdmin = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$api = new class($linkId, $externalUserId, $userId) extends QywxCustomerAcquisitionApiService {
|
||||
public function __construct(
|
||||
private string $testLinkId,
|
||||
@@ -49,7 +59,7 @@ $api = new class($linkId, $externalUserId, $userId) extends QywxCustomerAcquisit
|
||||
'external_userid' => $this->testExternalUserId,
|
||||
'userid' => $this->testUserId,
|
||||
'chat_status' => 2,
|
||||
'state' => 'smoke-sync',
|
||||
'state' => '',
|
||||
]],
|
||||
'next_cursor' => '',
|
||||
];
|
||||
@@ -72,6 +82,21 @@ $service = new QywxCustomerAcquisitionCustomerService($api);
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$linkOwnerId = (int) ($scopedAdmin['id'] ?? $admin['id']);
|
||||
$localLinkId = (int) Db::name('qywx_promotion_link')->insertGetId([
|
||||
'pool_id' => 0,
|
||||
'account_id' => 0,
|
||||
'name' => '空来源统计冒烟链接',
|
||||
'group_name' => '测试',
|
||||
'wecom_url' => 'https://work.weixin.qq.com/ca/smoke',
|
||||
'remote_link_id' => $linkId,
|
||||
'remote_status' => 1,
|
||||
'owner_admin_id' => $linkOwnerId,
|
||||
'dept_id' => 0,
|
||||
'create_time' => $eventTime,
|
||||
'update_time' => $eventTime,
|
||||
]);
|
||||
|
||||
$startMessage = [
|
||||
'MsgId' => 'smoke-start-' . $suffix,
|
||||
'ChangeType' => 'customer_start_chat',
|
||||
@@ -104,6 +129,9 @@ try {
|
||||
$assert((int) ($customer['chat_status'] ?? -1) === 1, '列表同步错误回退了已确认的聊天状态');
|
||||
$assert((int) ($customer['recv_msg_cnt'] ?? -1) === 5, '累计接收消息数不正确或被重复累加');
|
||||
$assert((int) ($customer['message_count_known'] ?? 0) === 1, '精确消息次数标识未保存');
|
||||
$assert((string) ($customer['state'] ?? 'missing') === '', '企业微信返回空来源时客户未按原样保存');
|
||||
$assert((int) ($customer['promotion_link_id'] ?? 0) === $localLinkId, '客户未关联本地获客链接');
|
||||
$assert((int) ($customer['owner_admin_id'] ?? -1) === 0, '冒烟客户应保持为未匹配成员');
|
||||
|
||||
$stats = WecomAcquisitionCustomerLogic::statistics(
|
||||
['keyword' => $externalUserId, 'page_size' => 20],
|
||||
@@ -119,6 +147,19 @@ try {
|
||||
$assert(!array_key_exists('external_userid', $row), '接口不应返回原始客户 ExternalUserID');
|
||||
$assert(str_contains((string) ($row['external_userid_masked'] ?? ''), '*'), '客户标识没有脱敏');
|
||||
|
||||
if ($scopedAdmin !== null) {
|
||||
$scopedStats = WecomAcquisitionCustomerLogic::statistics(
|
||||
['keyword' => $externalUserId, 'page_size' => 20],
|
||||
(int) $scopedAdmin['id'],
|
||||
$scopedAdmin
|
||||
);
|
||||
$assert(
|
||||
(int) ($scopedStats['summary']['customer_count'] ?? 0) === 1,
|
||||
'空来源且成员未匹配时,链接归属范围内仍应显示企微返回的客户'
|
||||
);
|
||||
$assert(count($scopedStats['lists'] ?? []) === 1, '空来源客户未进入有限权限账号的统计列表');
|
||||
}
|
||||
|
||||
$eventKeys = [
|
||||
QywxCustomerAcquisitionCustomerService::eventKey($startMessage, 'customer_start_chat', '', $eventTime),
|
||||
QywxCustomerAcquisitionCustomerService::eventKey(
|
||||
|
||||
Reference in New Issue
Block a user