prepare('INSERT INTO invite_codes (code, max_uses) VALUES (?, ?)'); for ($i = 0; $i < $count; $i++) { $code = strtoupper(bin2hex(random_bytes(4))); try { $stmt->execute([$code, $maxUses]); $inserted++; } catch (PDOException $e) { } } $_SESSION['flash_msg'] = '成功生成 ' . $inserted . ' 个邀请码(最大使用次数: ' . ($maxUses === 0 ? '不限' : $maxUses) . ')'; $_SESSION['flash_type'] = 'success'; header('Location: admin_settings.php'); exit; } // 修改邀请码次数 if (isset($_POST['edit_max_uses'])) { if (!verifyCsrf($_POST['csrf_token'] ?? '')) { die('CSRF token无效'); } $id = (int)($_POST['id'] ?? 0); $maxUses = max(0, (int)($_POST['max_uses'] ?? 1)); $stmt = $pdo->prepare('UPDATE invite_codes SET max_uses = ? WHERE id = ?'); $stmt->execute([$maxUses, $id]); $_SESSION['flash_msg'] = '已更新最大使用次数'; $_SESSION['flash_type'] = 'success'; header('Location: admin_settings.php'); exit; } // 删除邀请码(仅可删未使用的) if (isset($_GET['del_invite']) && is_numeric($_GET['del_invite'])) { if (!verifyCsrf($_GET['csrf_token'] ?? '')) { $msg = '
| ID | 用户名 | 角色 | 状态 | 可管理产品 | 备注 | 注册时间 | 操作 |
|---|---|---|---|---|---|---|---|
| = $u['id'] ?> | = h($u['username']) ?> | 管理员 普通用户 | 已禁用 正常 | $p['name'], array_filter($allProducts, fn($p) => in_array((int)$p['id'], $upIds))); echo $upNames ? h(implode(', ', $upNames)) : '-'; ?> | = h(mb_substr($u['remark'], 0, 20)) ?>= mb_strlen($u['remark']) > 20 ? '...' : '' ?> - ✏️ | = formatDateTime($u['created_at']) ?> |
通过远程接口查询兑换码的使用状态,并将已使用的兑换码更新到本地。