修复A2C工单蜘蛛
This commit is contained in:
@@ -7,12 +7,16 @@ namespace app\common\service;
|
||||
use app\admin\model\split\Link;
|
||||
|
||||
/**
|
||||
* 分流链接随机打乱配置读取
|
||||
* 分流链接随机打乱配置与落地页选号
|
||||
*
|
||||
* - random_shuffle=0:跨工单合并号码池,按 id 顺序严格轮转
|
||||
* - random_shuffle=1:跨工单合并号码池,每次访问完全随机选号
|
||||
* - 同步写入时 random_shuffle=1 还会打乱新号码 insert 顺序(影响 id 分布)
|
||||
*/
|
||||
class SplitNumberWeighService
|
||||
{
|
||||
/**
|
||||
* 链接是否开启随机打乱(新号码按随机插入顺序写入,跳转按 id 顺序轮转)
|
||||
* 链接是否开启随机打乱
|
||||
*/
|
||||
public static function isRandomShuffleEnabled(int $linkId): bool
|
||||
{
|
||||
@@ -21,4 +25,30 @@ class SplitNumberWeighService
|
||||
}
|
||||
return (int) Link::where('id', $linkId)->value('random_shuffle') === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析本次访问应使用的号码下标(0 .. numberCount-1)
|
||||
*
|
||||
* @param int $linkId 分流链接 ID
|
||||
* @param int $numberCount 可用号码数量
|
||||
* @param SplitRoundRobinStore $roundRobinStore 关闭随机打乱时的轮转计数器
|
||||
*/
|
||||
public static function resolvePickIndex(
|
||||
int $linkId,
|
||||
int $numberCount,
|
||||
SplitRoundRobinStore $roundRobinStore
|
||||
): int {
|
||||
if ($numberCount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if ($numberCount === 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self::isRandomShuffleEnabled($linkId)) {
|
||||
return random_int(0, $numberCount - 1);
|
||||
}
|
||||
|
||||
return $roundRobinStore->nextIndex($linkId, $numberCount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user