下号比率恢复 + 触线降权 + 同步裁决
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\admin\model\split\Number;
|
||||
use app\admin\model\split\Ticket;
|
||||
|
||||
/**
|
||||
* 落地页访问侧下号比率规则:更新连续无进线点击 streak,触线时仅降权(ratio_deferred),不关闭 status
|
||||
*
|
||||
* 最终关号由同步后 SplitTicketRuleService::applyNumberRules 裁决。
|
||||
*/
|
||||
class SplitNumberVisitRuleService
|
||||
{
|
||||
/**
|
||||
* 访问计数已递增后调用:累加 streak,达到 assign_ratio 时标记 ratio_deferred=1
|
||||
*/
|
||||
public function recordVisitAfterRedirect(int $numberId): void
|
||||
{
|
||||
if ($numberId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Number|null $number */
|
||||
$number = Number::get($numberId);
|
||||
if ($number === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Ticket|null $ticket */
|
||||
$ticket = Ticket::where('admin_id', (int) $number['admin_id'])
|
||||
->where('split_link_id', (int) $number['split_link_id'])
|
||||
->where('ticket_name', (string) $number['ticket_name'])
|
||||
->find();
|
||||
if ($ticket === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assignRatio = (int) ($ticket['assign_ratio'] ?? 0);
|
||||
$inboundCount = (int) $number['inbound_count'];
|
||||
$lastInbound = (int) ($number['last_sync_inbound_count'] ?? 0);
|
||||
$streak = (int) ($number['no_inbound_click_streak'] ?? 0);
|
||||
|
||||
// 自上次同步检查点以来进线未增长,则本次访问计入 streak
|
||||
if ($inboundCount <= $lastInbound) {
|
||||
$streak++;
|
||||
} else {
|
||||
$streak = 0;
|
||||
}
|
||||
|
||||
$update = [
|
||||
'no_inbound_click_streak' => $streak,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
|
||||
// 非手动号码且达到下号比率:触线降权,不关 status,等待同步确认
|
||||
if ((int) $number['manual_manage'] === 0 && $assignRatio > 0 && $streak >= $assignRatio) {
|
||||
$update['ratio_deferred'] = 1;
|
||||
$update['ratio_deferred_at'] = time();
|
||||
}
|
||||
|
||||
Number::where('id', $numberId)->update($update);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user