修改自动推广的相关任务

This commit is contained in:
wangjinlei
2026-04-23 11:37:49 +08:00
parent 5f724217c0
commit 48b2335063
3 changed files with 31 additions and 9 deletions

View File

@@ -528,14 +528,25 @@ class PromotionService
if (!is_string($tpl) || $tpl === '') return '';
if (!is_array($vars) || empty($vars)) return $tpl;
$replace = [];
$map = [];
foreach ($vars as $k => $v) {
$key = trim((string)$k);
if ($key === '') continue;
$replace['{{' . $key . '}}'] = (string)$v;
$replace['{' . $key . '}'] = (string)$v;
$map[$key] = (string)$v;
}
return str_replace(array_keys($replace), array_values($replace), $tpl);
if (empty($map)) return $tpl;
// 双大括号:允许内部有空格,如 {{ var }} / {{ var }}
$tpl = preg_replace_callback('/\{\{\s*([A-Za-z0-9_\-\.]+)\s*\}\}/', function ($m) use ($map) {
return array_key_exists($m[1], $map) ? $map[$m[1]] : $m[0];
}, $tpl);
// 单大括号:保持严格匹配(不允许内部空格),避免误伤正文
$single = [];
foreach ($map as $k => $v) {
$single['{' . $k . '}'] = $v;
}
return str_replace(array_keys($single), array_values($single), $tpl);
}
// ==================== Logging ====================