diff --git a/application/api/controller/EmailClient.php b/application/api/controller/EmailClient.php index 2ae06b1..274d685 100644 --- a/application/api/controller/EmailClient.php +++ b/application/api/controller/EmailClient.php @@ -2624,14 +2624,25 @@ class EmailClient extends Base 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); } private function renderFromTemplate($templateId, $journalId, $varsJson, $styleId = 0) diff --git a/application/api/controller/PromotionFactory.php b/application/api/controller/PromotionFactory.php index b258728..95c0167 100644 --- a/application/api/controller/PromotionFactory.php +++ b/application/api/controller/PromotionFactory.php @@ -221,7 +221,7 @@ class PromotionFactory extends Base return jsonError('Factory not found'); } - Db::name('promotion_factory')->where('promotion_factory_id', $id)->update(['state' => 1]); + Db::name('promotion_factory')->where('promotion_factory_id', $id)->delete(); return jsonSuccess([]); } diff --git a/application/common/PromotionService.php b/application/common/PromotionService.php index c68f3ac..5f04c70 100644 --- a/application/common/PromotionService.php +++ b/application/common/PromotionService.php @@ -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 ====================