save(); return; } $this->index(); } public function index(): void { $s = new Setting(); $v = []; foreach (self::KEYS as $k) { $v[$k] = $s->get($k, ''); } // 布尔项默认值 if ($v['notify_lowstock_enabled'] === '') $v['notify_lowstock_enabled'] = 1; if ($v['notify_lowstock_threshold'] === '') $v['notify_lowstock_threshold'] = 20; $this->renderSubsys('psi', 'psi/notifications', ['v' => $v], \psi_nav(), 'notifications'); } public function save(): void { if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !csrf_check()) { $this->redirect('PSI/notifications'); } $s = new Setting(); $post = $_POST; $s->set('notify_enabled', isset($post['notify_enabled']) ? 1 : 0); $s->set('notify_email_enabled', isset($post['notify_email_enabled']) ? 1 : 0); $s->set('notify_email_smtp_host', trim((string) ($post['notify_email_smtp_host'] ?? ''))); $s->set('notify_email_smtp_port', (int) ($post['notify_email_smtp_port'] ?? 465)); $s->set('notify_email_smtp_user', trim((string) ($post['notify_email_smtp_user'] ?? ''))); $s->set('notify_email_smtp_pass', trim((string) ($post['notify_email_smtp_pass'] ?? ''))); $s->set('notify_email_from', trim((string) ($post['notify_email_from'] ?? ''))); $s->set('notify_email_to', trim((string) ($post['notify_email_to'] ?? ''))); $s->set('notify_wechat_enabled', isset($post['notify_wechat_enabled']) ? 1 : 0); $s->set('notify_wechat_webhook', trim((string) ($post['notify_wechat_webhook'] ?? ''))); $s->set('notify_wechat_mention', trim((string) ($post['notify_wechat_mention'] ?? ''))); $s->set('notify_lowstock_enabled', isset($post['notify_lowstock_enabled']) ? 1 : 0); $s->set('notify_lowstock_threshold', max(0, (float) ($post['notify_lowstock_threshold'] ?? 20))); $this->flash('通知设置已保存', 'ok'); $this->redirect('PSI/notifications'); } }