修改自动推广的相关任务 退订相关

This commit is contained in:
wangjinlei
2026-04-27 14:53:46 +08:00
parent 1ff6bef655
commit 5645b87669
7 changed files with 362 additions and 6 deletions

View File

@@ -74,6 +74,18 @@ class PromotionService
return ['done' => false, 'skipped' => $logEntry['email_to'], 'reason' => 'expert_invalid'];
}
// 退订过滤(防止准备 → 发送之间窗口期内退订的人被误发)
if (!empty($expert['unsubscribed'])) {
Db::name('promotion_email_log')->where('log_id', $logEntry['log_id'])->update([
'state' => 2,
'error_msg' => 'Expert unsubscribed',
'send_time' => time(),
]);
Db::name('promotion_task')->where('task_id', $taskId)->update(['utime' => time()]);
$this->enqueueNextEmail($taskId, 2);
return ['done' => false, 'skipped' => $logEntry['email_to'], 'reason' => 'expert_unsubscribed'];
}
$account = $this->pickSmtpAccountForTask($task);
if (!$account) {
$this->enqueueNextEmail($taskId, 600);
@@ -285,6 +297,15 @@ class PromotionService
$this->tryFinalizeTask($task['task_id']);
return ['code' => 1, 'msg' => 'expert_not_found', 'llm_status' => 0];
}
if (!empty($expert['unsubscribed'])) {
Db::name('promotion_email_log')->where('log_id', $logId)->update([
'state' => 2,
'error_msg' => 'Expert unsubscribed',
'send_time' => time(),
]);
$this->tryFinalizeTask($task['task_id']);
return ['code' => 1, 'msg' => 'expert_unsubscribed', 'llm_status' => 0];
}
$expert_fields = Db::name('expert_field')
->where('expert_id', $expert['expert_id'])
@@ -792,6 +813,15 @@ class PromotionService
{
$llm = $expert['llm_description'] ?? '';
$advised = $expert['ai_advised_topics'] ?? '';
$unsubUrl = '';
if (!empty($expert['expert_id']) && !empty($expert['email'])) {
$unsubUrl = \app\common\UnsubscribeService::buildUrl(
intval($expert['expert_id']),
(string)$expert['email']
);
}
return [
'expert_title' => "Ph.D",
'expert_name' => $expert['name'] ?? '',
@@ -803,6 +833,7 @@ class PromotionService
'ai_content_analysis' => $llm,
'ai_advised_topics' => $advised,
'llm_advised_topics' => $advised,
'unsubscribe_url' => $unsubUrl,
];
}