更新
This commit is contained in:
@@ -52,8 +52,12 @@ $service = new QywxCustomerAcquisitionApiService(new Client([
|
||||
|
||||
$list = $service->listLinks('', 100);
|
||||
$detail = $service->getLink('link_1');
|
||||
$created = $service->createLink(['link_name' => '官网获客', 'range' => ['user_list' => ['zhangsan']]]);
|
||||
$service->updateLink(['link_id' => 'link_1', 'link_name' => '官网获客-更新']);
|
||||
$created = $service->createLink(['link_name' => '官网获客', 'range' => ['user_list' => ['zhangsan', 'lisi']]]);
|
||||
$service->updateLink([
|
||||
'link_id' => 'link_1',
|
||||
'link_name' => '官网获客-更新',
|
||||
'range' => ['user_list' => ['lisi', 'zhangsan']],
|
||||
]);
|
||||
$service->deleteLink('link_1');
|
||||
$customers = $service->listCustomers('link_1', '', 1000);
|
||||
$chat = $service->getChatInfo('chat_key_1');
|
||||
@@ -88,7 +92,11 @@ $actualPaths = array_map(static fn (array $entry): string => $entry['request']->
|
||||
$assert($actualPaths === $expectedPaths, '请求端点不正确:' . implode(', ', $actualPaths));
|
||||
|
||||
$createPayload = json_decode((string) $history[2]['request']->getBody(), true);
|
||||
$assert(($createPayload['range']['user_list'][0] ?? '') === 'zhangsan', 'create_link 成员范围请求体不正确');
|
||||
$assert(($createPayload['range']['user_list'] ?? []) === ['zhangsan', 'lisi'], 'create_link 多人成员范围请求体不正确');
|
||||
$updatePayload = json_decode((string) $history[3]['request']->getBody(), true);
|
||||
$assert(($updatePayload['range']['user_list'] ?? []) === ['lisi', 'zhangsan'], 'update_link 多人成员范围请求体不正确');
|
||||
$deletePayload = json_decode((string) $history[4]['request']->getBody(), true);
|
||||
$assert(($deletePayload['link_id'] ?? '') === 'link_1', 'delete_link 请求体缺少官方 link_id');
|
||||
$customerPayload = json_decode((string) $history[5]['request']->getBody(), true);
|
||||
$assert(($customerPayload['link_id'] ?? '') === 'link_1' && ($customerPayload['limit'] ?? 0) === 1000, 'customer 请求体不正确');
|
||||
$chatPayload = json_decode((string) $history[6]['request']->getBody(), true);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use app\common\service\qywx\QywxPromotionMemberSchedulerService;
|
||||
use app\common\service\qywx\QywxPromotionWeightedRandom;
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$today = '2026-08-25';
|
||||
$now = strtotime($today . ' 12:00:00');
|
||||
$members = [
|
||||
['id' => 1, 'enabled' => 1, 'weight' => 2, 'current_weight' => 9, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today],
|
||||
['id' => 2, 'enabled' => 1, 'weight' => 1, 'current_weight' => -3, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today],
|
||||
['id' => 3, 'enabled' => 1, 'weight' => 1, 'current_weight' => 4, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today],
|
||||
];
|
||||
|
||||
$assert(QywxPromotionWeightedRandom::select($members, $today, $now, 1)['selected_id'] === 1, '权重 2 的第一个区间映射错误');
|
||||
$assert(QywxPromotionWeightedRandom::select($members, $today, $now, 2)['selected_id'] === 1, '权重 2 的第二个区间映射错误');
|
||||
$assert(QywxPromotionWeightedRandom::select($members, $today, $now, 3)['selected_id'] === 2, '第二名成员的随机区间映射错误');
|
||||
$fourth = QywxPromotionWeightedRandom::select($members, $today, $now, 4);
|
||||
$assert($fourth['selected_id'] === 3, '第三名成员的随机区间映射错误');
|
||||
$assert($fourth['total_weight'] === 4 && $fourth['eligible_count'] === 3, '随机池权重合计错误');
|
||||
$assert(array_column($fourth['members'], 'current_weight') === [0, 0, 0], '旧版平滑游标没有归零');
|
||||
|
||||
$limited = QywxPromotionWeightedRandom::select([
|
||||
['id' => 1, 'enabled' => 0, 'weight' => 10, 'current_weight' => 0, 'daily_limit' => 0, 'today_count' => 0, 'today_date' => $today],
|
||||
['id' => 2, 'enabled' => 1, 'weight' => 5, 'current_weight' => 0, 'daily_limit' => 3, 'today_count' => 3, 'today_date' => $today],
|
||||
['id' => 3, 'enabled' => 1, 'weight' => 1, 'current_weight' => 0, 'daily_limit' => 0, 'today_count' => 8, 'today_date' => $today],
|
||||
], $today, $now, 1);
|
||||
$assert($limited['selected_id'] === 3 && $limited['eligible_count'] === 1, '禁用成员或达到上限的成员仍进入随机池');
|
||||
|
||||
$reset = QywxPromotionWeightedRandom::select([
|
||||
['id' => 4, 'enabled' => 1, 'weight' => 1, 'current_weight' => 0, 'daily_limit' => 1, 'today_count' => 1, 'today_date' => '2026-08-24'],
|
||||
], $today, $now, 1);
|
||||
$assert($reset['selected_id'] === 4 && $reset['members'][0]['today_count'] === 0, '跨日数量没有自动重置');
|
||||
$assert(QywxPromotionMemberSchedulerService::poolIdFromState('zyt_pool:123') === 123, 'customer_channel 方案 ID 解析失败');
|
||||
$assert(QywxPromotionMemberSchedulerService::poolIdFromState('qywx_ca:123') === 0, '不应接管其他系统的 customer_channel');
|
||||
|
||||
echo "QYWX_PROMOTION_WEIGHTED_RANDOM_OK\n";
|
||||
Reference in New Issue
Block a user