From 48b2335063527dd8b2c4a793a613b4d40de64fdd Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Thu, 23 Apr 2026 11:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E6=8E=A8?= =?UTF-8?q?=E5=B9=BF=E7=9A=84=E7=9B=B8=E5=85=B3=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/EmailClient.php | 19 +++++++++++++++---- .../api/controller/PromotionFactory.php | 2 +- application/common/PromotionService.php | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 9 deletions(-) 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 ====================