v1.1.0: 新增安装统计与版本推送
功能说明: - 安装统计: 每次安装独立计数(含已删除), 存活/已删除, 最后上线时间 - 版本推送: 上传安装包并推送客户端下载, 支持强制更新提示(不阻断授权) - 客户端接口: check-update / heartbeat, verify 成功附带更新字段 - 管理端: 安装统计页 + 版本推送页; agent 不可发布版本(仅只读) - 文档: README API 说明 + /docs 功能介绍与使用方法 + CHANGELOG 数据库: - 新表 ca_installations / ca_project_versions - 增量升级: backend/database/migrations/20261008_add_installations_and_versions.sql
This commit is contained in:
1 parent
af98618810
commit
e809b7a903
22 files changed
+3153
-32
No files matched your search
@@ -22,6 +22,8 @@
|
||||
/backend/tmp_*.php
|
||||
/backend/test_admin.txt
|
||||
/backend/public/uploads/avatars/*
|
||||
/backend/public/uploads/packages/*
|
||||
!/backend/public/uploads/packages/.gitkeep
|
||||
/frontend/vite.config.js.timestamp-*
|
||||
|
||||
# 系统文件
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# 更新日志
|
||||
|
||||
## v1.1.0 (2026-10-08)
|
||||
|
||||
### 新增功能:安装统计与版本推送
|
||||
|
||||
#### 安装统计
|
||||
- 新增 `ca_installations` 安装记录表:每次安装独立计数(含已删除)
|
||||
- 统计维度:总安装次数、存活安装、已删除、今日/本周新增、最后上线时间
|
||||
- 支持按项目汇总查看安装情况
|
||||
- 管理端页面:`安装统计`(列表 / 筛选 / 详情 / 软删除 / 恢复 / 批量删除 / 导出 CSV)
|
||||
- 权限:超级管理员、项目管理员(限绑定项目)、代理(限本人卡密相关)
|
||||
|
||||
#### 版本推送(安装包分发)
|
||||
- 新增 `ca_project_versions` 项目版本表
|
||||
- 管理端上传安装包(zip/tar/gz/7z/exe/dmg/apk/msi/pkg/rar/bin,≤200MB)
|
||||
- 支持更新说明、设为最新版本、禁用/启用、删除版本及文件
|
||||
- 管理端页面:`版本推送`
|
||||
- 权限:发布/修改/删除仅超级管理员与项目管理员;**代理仅只读**
|
||||
|
||||
#### 强制推送
|
||||
- 版本可开启 `is_force` 或设置 `min_client_version`
|
||||
- 客户端检查更新时返回 `update_required=true`,提示强制更新
|
||||
- **仅客户端提示,不阻断** `verify` 授权结果
|
||||
|
||||
#### 客户端接口(API Key)
|
||||
| 接口 | 说明 |
|
||||
|------|------|
|
||||
| `POST /api/public/installations/check-update` | 检查更新 + 登记安装/更新在线时间 |
|
||||
| `POST /api/public/installations/heartbeat` | 轻量心跳,更新 `last_online_at` |
|
||||
| `POST /api/public/verify` | 成功响应附带更新字段,并同步安装记录 |
|
||||
|
||||
`check-update` / `verify` 成功时返回:`update_available`、`update_required`、`latest_version`、`download_url`、`file_size`、`checksum`、`changelog`、`is_force`、`install_id` 等。
|
||||
|
||||
#### 管理端接口(JWT)
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/api/installations` | 安装列表 |
|
||||
| GET | `/api/installations/stats` | 安装统计(含已删除) |
|
||||
| GET | `/api/installations/export` | 导出 CSV |
|
||||
| DELETE | `/api/installations/{id}` | 标记已删除 |
|
||||
| POST | `/api/installations/{id}/restore` | 恢复安装 |
|
||||
| GET | `/api/projects/{projectId}/versions` | 版本列表 |
|
||||
| POST | `/api/projects/{projectId}/versions` | 发布版本(multipart) |
|
||||
| PUT | `/api/versions/{id}/force` | 强制推送开关 |
|
||||
| PUT | `/api/versions/{id}/latest` | 设为最新 |
|
||||
| DELETE | `/api/versions/{id}` | 删除版本 |
|
||||
|
||||
#### 文档
|
||||
- README 补充安装统计与版本推送 API 文档
|
||||
- 公开文档页 `/docs` 增加功能介绍、后台使用方法、客户端对接说明与 CURL 示例
|
||||
|
||||
#### 数据库升级
|
||||
- 已有库执行:`backend/database/migrations/20261008_add_installations_and_versions.sql`
|
||||
- 全新安装:`backend/database/schema.sql` 已包含新表
|
||||
|
||||
---
|
||||
|
||||
## v1.0.0
|
||||
|
||||
初始版本:卡密授权、项目/套餐/卡密管理、代理分销、在线支付商城、授权验证 API、黑名单、SMTP 到期提醒、Docker 部署。
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
一个轻量级的卡密(激活码)+ 机器授权管理系统,支持多项目管理、代理分销、在线支付购买,适用于软件授权、会员激活等场景。
|
||||
|
||||
> **当前版本:v1.1.0** · 更新日志见 [CHANGELOG.md](./CHANGELOG.md)
|
||||
|
||||
## 技术栈
|
||||
|
||||
| 层 | 技术 |
|
||||
|---|---|
|
||||
| 后端 | PHP 7.4+ 自研框架(Router + Middleware + Controller) |
|
||||
| 后端 | PHP 8.1+ 自研框架(Router + Middleware + Controller) |
|
||||
| 数据库 | MySQL 8.0+ |
|
||||
| 前端 | Vue 3 + Element Plus + Pinia + ECharts |
|
||||
| 构建 | Vite |
|
||||
@@ -26,6 +28,8 @@
|
||||
- 代理余额体系(充值记录、扣费追溯、额度查询)
|
||||
- 订单管理(代客手动完成 / 手动确认)
|
||||
- 在线购买商城(公开页面,支持 epay/codepay 支付回调)
|
||||
- **安装统计**:项目安装次数、存活/已删除、最后上线时间(v1.1.0)
|
||||
- **版本推送**:上传安装包并推送客户端下载,支持强制更新提示(v1.1.0)
|
||||
- 黑名单系统(机器码/IP 封禁,可配置封禁策略)
|
||||
- SMTP 邮件通知(授权快到期自动发送提醒到联系人 QQ 邮箱)
|
||||
- 仪表盘统计图表(收入趋势、授权趋势、套餐销售占比)
|
||||
@@ -37,6 +41,9 @@
|
||||
- `/agent/login` 代理登录
|
||||
- `/agent/register` 代理注册
|
||||
- `/shop` 自助购买(公开页面)
|
||||
- `/docs` 系统介绍与使用文档(含安装统计/版本推送说明)
|
||||
- `/installations` 安装统计(v1.1.0)
|
||||
- `/project-versions` 版本推送(v1.1.0)
|
||||
|
||||
## 快速开始
|
||||
|
||||
@@ -276,7 +283,87 @@ Content-Type: application/json
|
||||
}
|
||||
```
|
||||
|
||||
**响应格式同 1.2。**
|
||||
**响应格式同 1.2,并额外附带更新提示字段(成功时):**
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"data": {
|
||||
"valid": true,
|
||||
"message": "授权有效",
|
||||
"type": "月卡",
|
||||
"duration_days": 30,
|
||||
"expire_time": "2026-11-01 12:00:00",
|
||||
"is_permanent": false,
|
||||
"remaining_days": 24,
|
||||
"update_available": true,
|
||||
"update_required": false,
|
||||
"current_version": "1.0.0",
|
||||
"latest_version": "1.2.0",
|
||||
"version": "1.2.0",
|
||||
"download_url": "/uploads/packages/1/pkg_1_xxx.zip",
|
||||
"file_size": 10485760,
|
||||
"checksum": "sha256...",
|
||||
"changelog": "修复若干问题",
|
||||
"min_client_version": "",
|
||||
"is_force": 0,
|
||||
"install_id": 123
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> 说明:`update_required` 仅作客户端强制更新提示,不阻断授权结果。
|
||||
|
||||
### 1.3.1 安装检查更新 / 心跳(客户端)
|
||||
|
||||
```
|
||||
POST /api/public/installations/check-update
|
||||
X-Api-Key: <项目的 API Key>
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"machine_id": "设备唯一指纹",
|
||||
"client_version": "1.0.0", // 可选
|
||||
"card_key": "CA-XXXX-XXXX", // 可选
|
||||
"device_info": "Windows 11" // 可选
|
||||
}
|
||||
```
|
||||
|
||||
**响应:**
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"data": {
|
||||
"update_available": true,
|
||||
"update_required": true,
|
||||
"current_version": "1.0.0",
|
||||
"latest_version": "2.0.0",
|
||||
"version": "2.0.0",
|
||||
"download_url": "/uploads/packages/1/pkg_1_xxx.zip",
|
||||
"file_size": 20971520,
|
||||
"checksum": "sha256...",
|
||||
"changelog": "重大更新",
|
||||
"min_client_version": "1.1.0",
|
||||
"is_force": 1,
|
||||
"install_id": 123
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
POST /api/public/installations/heartbeat
|
||||
X-Api-Key: <项目的 API Key>
|
||||
Content-Type: application/json
|
||||
|
||||
{ "machine_id": "设备唯一指纹", "client_version": "1.0.0", "card_key": "..." }
|
||||
```
|
||||
|
||||
**客户端接入建议:**
|
||||
- 启动/周期心跳时调用 `check-update`
|
||||
- `update_available=true` 且 `update_required=false` → 弹出「发现新版本,是否下载?」
|
||||
- `update_required=true` → 强制更新提示(不可关闭),引导下载 `download_url`
|
||||
- 授权验证 `verify` 时也会同步更新安装记录的 `last_online_at`,并附带相同更新字段
|
||||
|
||||
### 1.4 获取项目列表(商城用)
|
||||
|
||||
@@ -445,6 +532,87 @@ Content-Type: application/json
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 四之二、安装统计与版本推送
|
||||
|
||||
### 权限说明
|
||||
|
||||
| 功能 | admin | project_admin | agent |
|
||||
|------|-------|---------------|-------|
|
||||
| 查看安装统计 | 全部 | 仅绑定项目 | 仅本人卡密相关 |
|
||||
| 删除/恢复安装 | ✓ | ✓ | ✗ |
|
||||
| 发布/修改/删除版本 | ✓ | ✓ | ✗(仅只读列表) |
|
||||
| 强制推送开关 | ✓ | ✓ | ✗ |
|
||||
|
||||
### 安装统计
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/api/installations` | 安装列表(分页/筛选) |
|
||||
| GET | `/api/installations/stats` | 统计:总安装(含已删除)、存活、已删除、今日新增、最后上线 |
|
||||
| GET | `/api/installations/{id}` | 安装详情 |
|
||||
| DELETE | `/api/installations/{id}` | 标记已删除(软删除) |
|
||||
| POST | `/api/installations/{id}/restore` | 恢复为存活 |
|
||||
| POST | `/api/installations/batch-delete` | 批量删除 `{ids:[]}` |
|
||||
| GET | `/api/installations/export` | 导出 CSV |
|
||||
|
||||
**统计响应示例:**
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"data": {
|
||||
"total_installs": 1280,
|
||||
"active": 1150,
|
||||
"deleted": 130,
|
||||
"today_new": 12,
|
||||
"week_new": 80,
|
||||
"last_online_at": "2026-10-08 10:30:00",
|
||||
"projects": [
|
||||
{
|
||||
"project_id": 1,
|
||||
"project_name": "演示项目",
|
||||
"total_installs": 500,
|
||||
"active": 450,
|
||||
"deleted": 50,
|
||||
"today_new": 5,
|
||||
"last_online_at": "2026-10-08 10:00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
列表 query 参数:`project_id`、`status`(active/deleted)、`keyword`、`date_from`、`date_to`、`page`、`page_size`。
|
||||
|
||||
### 版本推送管理
|
||||
|
||||
| 方法 | 路径 | 角色 | 说明 |
|
||||
|------|------|------|------|
|
||||
| GET | `/api/projects/{projectId}/versions` | 三角色 | 版本列表 |
|
||||
| GET | `/api/projects/{projectId}/versions/{id}` | 三角色 | 版本详情 |
|
||||
| POST | `/api/projects/{projectId}/versions` | admin/project_admin | 上传发布(multipart) |
|
||||
| PUT | `/api/versions/{id}` | admin/project_admin | 更新说明/强制/最低版本/状态 |
|
||||
| PUT | `/api/versions/{id}/force` | admin/project_admin | 强制推送开关 |
|
||||
| PUT | `/api/versions/{id}/latest` | admin/project_admin | 设为最新版本 |
|
||||
| DELETE | `/api/versions/{id}` | admin/project_admin | 删除版本及文件 |
|
||||
|
||||
**发布版本(multipart/form-data):**
|
||||
|
||||
| 字段 | 必填 | 说明 |
|
||||
|------|------|------|
|
||||
| `version` | 是 | 版本号,同项目唯一 |
|
||||
| `file` | 是 | 安装包(zip/tar/gz/7z/exe/dmg/apk/msi/pkg/rar/bin,≤200MB) |
|
||||
| `changelog` | 否 | 更新说明 |
|
||||
| `is_force` | 否 | 0/1,默认 0;1=客户端强制更新提示 |
|
||||
| `min_client_version` | 否 | 低于此版本强制更新 |
|
||||
| `is_latest` | 否 | 默认 1;设为 1 时旧版本自动取消 latest |
|
||||
|
||||
强制推送语义:仅返回 `update_required=true` 提示客户端弹窗,**不阻断** `verify` 授权。
|
||||
|
||||
**安装次数口径:** `total_installs = COUNT(*)`(存活 + 已删除);每次安装独立记录,同机器删除后重装会再次计入。
|
||||
|
||||
### 创建套餐
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use App\Core\Database;
|
||||
use App\Services\InstallationService;
|
||||
use App\Services\PermissionService;
|
||||
|
||||
/**
|
||||
* 安装记录管理控制器
|
||||
*/
|
||||
class InstallationController extends Controller
|
||||
{
|
||||
/**
|
||||
* 安装列表
|
||||
* GET /api/installations
|
||||
*/
|
||||
public function list(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
$page = max(1, (int) ($_GET['page'] ?? 1));
|
||||
$pageSize = min((int) ($_GET['page_size'] ?? 20), 100);
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
|
||||
$filters = [
|
||||
'project_id' => $_GET['project_id'] ?? '',
|
||||
'status' => $_GET['status'] ?? '',
|
||||
'keyword' => trim($_GET['keyword'] ?? ''),
|
||||
'date_from' => $_GET['date_from'] ?? '',
|
||||
'date_to' => $_GET['date_to'] ?? '',
|
||||
];
|
||||
|
||||
$built = InstallationService::buildListWhere($user, $filters);
|
||||
$where = $built['where'];
|
||||
$params = $built['params'];
|
||||
|
||||
$total = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('installations')} i WHERE 1=1 {$where}",
|
||||
$params
|
||||
);
|
||||
|
||||
$list = $db->fetchAll(
|
||||
"SELECT i.*, p.name AS project_name
|
||||
FROM {$db->table('installations')} i
|
||||
LEFT JOIN {$db->table('projects')} p ON p.id = i.project_id
|
||||
WHERE 1=1 {$where}
|
||||
ORDER BY i.id DESC
|
||||
LIMIT {$offset}, {$pageSize}",
|
||||
$params
|
||||
);
|
||||
|
||||
$this->success([
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'page_size' => $pageSize,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装统计(含已删除)
|
||||
* GET /api/installations/stats
|
||||
*/
|
||||
public function stats(): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
$projectId = !empty($_GET['project_id']) ? (int) $_GET['project_id'] : null;
|
||||
|
||||
$this->success(InstallationService::stats($user, $projectId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装详情
|
||||
* GET /api/installations/{id}
|
||||
*/
|
||||
public function detail(int $id): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
|
||||
$row = $db->fetch(
|
||||
"SELECT i.*, p.name AS project_name
|
||||
FROM {$db->table('installations')} i
|
||||
LEFT JOIN {$db->table('projects')} p ON p.id = i.project_id
|
||||
WHERE i.id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('安装记录不存在', 404);
|
||||
}
|
||||
|
||||
if (!$this->canAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权访问该安装记录', 403);
|
||||
}
|
||||
|
||||
$this->success($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除安装(软删除)
|
||||
* DELETE /api/installations/{id}
|
||||
*/
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
$role = $user['role'] ?? '';
|
||||
|
||||
if (!in_array($role, ['admin', 'project_admin'], true)) {
|
||||
$this->error('无权删除安装记录', 403);
|
||||
}
|
||||
|
||||
$row = $db->fetch(
|
||||
"SELECT id, project_id, machine_id FROM {$db->table('installations')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('安装记录不存在', 404);
|
||||
}
|
||||
if (!$this->canAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权操作该项目的安装记录', 403);
|
||||
}
|
||||
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('installations')}
|
||||
SET status = 'deleted', deleted_at = NOW()
|
||||
WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
|
||||
logger('installation_delete', 'installation', $id, [
|
||||
'project_id' => (int) $row['project_id'],
|
||||
'machine_id' => $row['machine_id'],
|
||||
]);
|
||||
|
||||
$this->success(null, '已标记为已删除');
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复安装
|
||||
* POST /api/installations/{id}/restore
|
||||
*/
|
||||
public function restore(int $id): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
$role = $user['role'] ?? '';
|
||||
|
||||
if (!in_array($role, ['admin', 'project_admin'], true)) {
|
||||
$this->error('无权恢复安装记录', 403);
|
||||
}
|
||||
|
||||
$row = $db->fetch(
|
||||
"SELECT id, project_id, machine_id FROM {$db->table('installations')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('安装记录不存在', 404);
|
||||
}
|
||||
if (!$this->canAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权操作该项目的安装记录', 403);
|
||||
}
|
||||
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('installations')}
|
||||
SET status = 'active', deleted_at = NULL
|
||||
WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
|
||||
logger('installation_restore', 'installation', $id, [
|
||||
'project_id' => (int) $row['project_id'],
|
||||
'machine_id' => $row['machine_id'],
|
||||
]);
|
||||
|
||||
$this->success(null, '已恢复为存活');
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* POST /api/installations/batch-delete
|
||||
*/
|
||||
public function batchDelete(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
$role = $user['role'] ?? '';
|
||||
|
||||
if (!in_array($role, ['admin', 'project_admin'], true)) {
|
||||
$this->error('无权删除安装记录', 403);
|
||||
}
|
||||
|
||||
$input = $this->getJsonInput();
|
||||
$ids = $input['ids'] ?? [];
|
||||
if (empty($ids) || !is_array($ids)) {
|
||||
$this->error('请选择要删除的安装记录');
|
||||
}
|
||||
$ids = array_map('intval', $ids);
|
||||
|
||||
$deleted = 0;
|
||||
foreach ($ids as $id) {
|
||||
$row = $db->fetch(
|
||||
"SELECT id, project_id FROM {$db->table('installations')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row || !$this->canAccess((int) $row['project_id'], $user)) {
|
||||
continue;
|
||||
}
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('installations')} SET status = 'deleted', deleted_at = NOW() WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
$deleted++;
|
||||
}
|
||||
|
||||
logger('installation_batch_delete', 'installation', 0, ['count' => $deleted]);
|
||||
$this->success(['deleted' => $deleted], "已删除 {$deleted} 条");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出安装记录
|
||||
* GET /api/installations/export
|
||||
*/
|
||||
public function export(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
|
||||
$filters = [
|
||||
'project_id' => $_GET['project_id'] ?? '',
|
||||
'status' => $_GET['status'] ?? '',
|
||||
'keyword' => trim($_GET['keyword'] ?? ''),
|
||||
'date_from' => $_GET['date_from'] ?? '',
|
||||
'date_to' => $_GET['date_to'] ?? '',
|
||||
];
|
||||
$built = InstallationService::buildListWhere($user, $filters);
|
||||
|
||||
$list = $db->fetchAll(
|
||||
"SELECT i.id, i.project_id, p.name AS project_name, i.machine_id, i.card_key, i.ip,
|
||||
i.device_info, i.client_version, i.status, i.install_count,
|
||||
i.installed_at, i.last_online_at, i.deleted_at
|
||||
FROM {$db->table('installations')} i
|
||||
LEFT JOIN {$db->table('projects')} p ON p.id = i.project_id
|
||||
WHERE 1=1 {$built['where']}
|
||||
ORDER BY i.id DESC
|
||||
LIMIT 5000",
|
||||
$built['params']
|
||||
);
|
||||
|
||||
$headers = [
|
||||
'ID', '项目ID', '项目名称', '机器指纹', '卡密', 'IP', '设备信息',
|
||||
'客户端版本', '状态', '累计激活', '安装时间', '最后上线', '删除时间',
|
||||
];
|
||||
|
||||
header('Content-Type: text/csv; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename=installations_' . date('Ymd_His') . '.csv');
|
||||
echo "\xEF\xBB\xBF"; // UTF-8 BOM
|
||||
$out = fopen('php://output', 'w');
|
||||
fputcsv($out, $headers);
|
||||
foreach ($list as $row) {
|
||||
fputcsv($out, [
|
||||
$row['id'],
|
||||
$row['project_id'],
|
||||
$row['project_name'] ?? '',
|
||||
$row['machine_id'],
|
||||
$row['card_key'] ?? '',
|
||||
$row['ip'] ?? '',
|
||||
$row['device_info'] ?? '',
|
||||
$row['client_version'] ?? '',
|
||||
$row['status'],
|
||||
$row['install_count'],
|
||||
$row['installed_at'],
|
||||
$row['last_online_at'] ?? '',
|
||||
$row['deleted_at'] ?? '',
|
||||
]);
|
||||
}
|
||||
fclose($out);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限判断
|
||||
*/
|
||||
private function canAccess(int $projectId, array $user): bool
|
||||
{
|
||||
$role = $user['role'] ?? '';
|
||||
if ($role === 'admin') {
|
||||
return true;
|
||||
}
|
||||
if ($role === 'project_admin') {
|
||||
$projectIds = $user['project_ids'] ?? [];
|
||||
return in_array($projectId, array_map('intval', $projectIds), true);
|
||||
}
|
||||
if ($role === 'agent') {
|
||||
$db = Database::getInstance();
|
||||
$agentIds = PermissionService::getAgentIdsUnder((int) ($user['id'] ?? 0));
|
||||
if (empty($agentIds)) {
|
||||
return false;
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($agentIds), '?'));
|
||||
$count = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('cards')} WHERE project_id = ? AND use_user_id IN ({$placeholders})",
|
||||
array_merge([$projectId], $agentIds)
|
||||
);
|
||||
return $count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use App\Core\Database;
|
||||
use App\Services\VersionService;
|
||||
|
||||
/**
|
||||
* 项目版本/安装包管理控制器
|
||||
* 发布/修改仅 admin + project_admin;agent 只读
|
||||
*/
|
||||
class ProjectVersionController extends Controller
|
||||
{
|
||||
private const ALLOWED_EXT = ['zip', 'tar', 'gz', 'tgz', '7z', 'exe', 'dmg', 'apk', 'msi', 'pkg', 'rar', 'bin'];
|
||||
private const MAX_SIZE = 200 * 1024 * 1024; // 200MB
|
||||
|
||||
/**
|
||||
* 版本列表
|
||||
* GET /api/projects/{projectId}/versions
|
||||
*/
|
||||
public function list(int $projectId): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
if (!VersionService::assertProjectAccess($projectId, $user)) {
|
||||
$this->error('无权访问该项目', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$list = $db->fetchAll(
|
||||
"SELECT v.*, p.name AS project_name
|
||||
FROM {$db->table('project_versions')} v
|
||||
LEFT JOIN {$db->table('projects')} p ON p.id = v.project_id
|
||||
WHERE v.project_id = ?
|
||||
ORDER BY v.id DESC",
|
||||
[$projectId]
|
||||
);
|
||||
|
||||
$this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本详情
|
||||
* GET /api/projects/{projectId}/versions/{id}
|
||||
*/
|
||||
public function detail(int $projectId, int $id): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
if (!VersionService::assertProjectAccess($projectId, $user)) {
|
||||
$this->error('无权访问该项目', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT v.*, p.name AS project_name
|
||||
FROM {$db->table('project_versions')} v
|
||||
LEFT JOIN {$db->table('projects')} p ON p.id = v.project_id
|
||||
WHERE v.id = ? AND v.project_id = ?",
|
||||
[$id, $projectId]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('版本不存在', 404);
|
||||
}
|
||||
|
||||
$this->success($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传发布版本
|
||||
* POST /api/projects/{projectId}/versions (multipart)
|
||||
*/
|
||||
public function create(int $projectId): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
$role = $user['role'] ?? '';
|
||||
|
||||
if (!VersionService::canPublish($role)) {
|
||||
$this->error('代理账号不可发布版本', 403);
|
||||
}
|
||||
if (!VersionService::assertProjectAccess($projectId, $user)) {
|
||||
$this->error('无权操作该项目', 403);
|
||||
}
|
||||
|
||||
$version = trim($_POST['version'] ?? '');
|
||||
if ($version === '') {
|
||||
$this->error('版本号不能为空');
|
||||
}
|
||||
|
||||
if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
|
||||
$this->error('请上传安装包文件');
|
||||
}
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, self::ALLOWED_EXT, true)) {
|
||||
$this->error('仅支持 ' . implode('/', self::ALLOWED_EXT) . ' 格式的安装包');
|
||||
}
|
||||
if ($file['size'] > self::MAX_SIZE) {
|
||||
$this->error('安装包大小不能超过 200MB');
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$exists = $db->fetch(
|
||||
"SELECT id FROM {$db->table('project_versions')} WHERE project_id = ? AND version = ?",
|
||||
[$projectId, $version]
|
||||
);
|
||||
if ($exists) {
|
||||
$this->error('该版本号已存在');
|
||||
}
|
||||
|
||||
$uploadDir = BASE_PATH . '/public/uploads/packages/' . $projectId;
|
||||
if (!is_dir($uploadDir) && !mkdir($uploadDir, 0755, true) && !is_dir($uploadDir)) {
|
||||
$this->error('创建上传目录失败');
|
||||
}
|
||||
|
||||
// 安全文件名:随机 + 原扩展名
|
||||
$safeName = 'pkg_' . $projectId . '_' . time() . '_' . bin2hex(random_bytes(6)) . '.' . $ext;
|
||||
$filepath = $uploadDir . '/' . $safeName;
|
||||
if (!move_uploaded_file($file['tmp_name'], $filepath)) {
|
||||
$this->error('安装包上传失败,请重试');
|
||||
}
|
||||
|
||||
$checksum = '';
|
||||
if (is_file($filepath)) {
|
||||
$checksum = @hash_file('sha256', $filepath) ?: '';
|
||||
}
|
||||
|
||||
$fileSize = (int) $file['size'];
|
||||
$isLatest = isset($_POST['is_latest']) ? (int) $_POST['is_latest'] : 1;
|
||||
$isForce = isset($_POST['is_force']) ? (int) $_POST['is_force'] : 0;
|
||||
$isForce = $isForce === 1 ? 1 : 0;
|
||||
$isLatest = $isLatest === 0 ? 0 : 1;
|
||||
$minVersion = trim($_POST['min_client_version'] ?? '');
|
||||
$changelog = $_POST['changelog'] ?? '';
|
||||
$filePath = '/uploads/packages/' . $projectId . '/' . $safeName;
|
||||
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
if ($isLatest) {
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('project_versions')} SET is_latest = 0 WHERE project_id = ?",
|
||||
[$projectId]
|
||||
);
|
||||
}
|
||||
|
||||
$versionId = $db->insert(
|
||||
"INSERT INTO {$db->table('project_versions')}
|
||||
(project_id, version, file_name, file_path, file_size, checksum, changelog,
|
||||
min_client_version, is_force, is_latest, download_count, status, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 1, ?)",
|
||||
[
|
||||
$projectId,
|
||||
$version,
|
||||
$file['name'],
|
||||
$filePath,
|
||||
$fileSize,
|
||||
$checksum,
|
||||
$changelog !== '' ? $changelog : null,
|
||||
$minVersion,
|
||||
$isForce,
|
||||
$isLatest,
|
||||
(int) ($user['id'] ?? 0),
|
||||
]
|
||||
);
|
||||
$db->commit();
|
||||
} catch (\Throwable $e) {
|
||||
$db->rollback();
|
||||
@unlink($filepath);
|
||||
$this->error('版本发布失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
logger('version_publish', 'project_version', $versionId, [
|
||||
'project_id' => $projectId,
|
||||
'version' => $version,
|
||||
'is_force' => $isForce,
|
||||
'is_latest' => $isLatest,
|
||||
]);
|
||||
|
||||
$row = $db->fetch(
|
||||
"SELECT * FROM {$db->table('project_versions')} WHERE id = ?",
|
||||
[$versionId]
|
||||
);
|
||||
|
||||
$this->success($row, '版本发布成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新版本信息(changelog / force / min_version / status)
|
||||
* PUT /api/versions/{id}
|
||||
*/
|
||||
public function update(int $id): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
if (!VersionService::canPublish($user['role'] ?? '')) {
|
||||
$this->error('代理账号不可修改版本', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT * FROM {$db->table('project_versions')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('版本不存在', 404);
|
||||
}
|
||||
if (!VersionService::assertProjectAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权操作该项目的版本', 403);
|
||||
}
|
||||
|
||||
$input = $this->getJsonInput();
|
||||
|
||||
$changelog = array_key_exists('changelog', $input) ? $input['changelog'] : $row['changelog'];
|
||||
$minVersion = array_key_exists('min_client_version', $input) ? trim((string) $input['min_client_version']) : ($row['min_client_version'] ?? '');
|
||||
$isForce = array_key_exists('is_force', $input) ? ((int) $input['is_force'] === 1 ? 1 : 0) : (int) $row['is_force'];
|
||||
$status = array_key_exists('status', $input) ? ((int) $input['status'] === 1 ? 1 : 0) : (int) $row['status'];
|
||||
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('project_versions')}
|
||||
SET changelog = ?, min_client_version = ?, is_force = ?, status = ?
|
||||
WHERE id = ?",
|
||||
[
|
||||
$changelog !== '' ? $changelog : null,
|
||||
$minVersion,
|
||||
$isForce,
|
||||
$status,
|
||||
$id,
|
||||
]
|
||||
);
|
||||
|
||||
logger('version_update', 'project_version', $id, [
|
||||
'version' => $row['version'],
|
||||
'is_force' => $isForce,
|
||||
]);
|
||||
|
||||
$this->success($db->fetch("SELECT * FROM {$db->table('project_versions')} WHERE id = ?", [$id]), '更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换强制推送
|
||||
* PUT /api/versions/{id}/force
|
||||
*/
|
||||
public function toggleForce(int $id): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
if (!VersionService::canPublish($user['role'] ?? '')) {
|
||||
$this->error('代理账号不可修改强制推送', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT * FROM {$db->table('project_versions')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('版本不存在', 404);
|
||||
}
|
||||
if (!VersionService::assertProjectAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权操作该项目的版本', 403);
|
||||
}
|
||||
|
||||
$input = $this->getJsonInput();
|
||||
if (array_key_exists('is_force', $input)) {
|
||||
$isForce = ((int) $input['is_force'] === 1) ? 1 : 0;
|
||||
} else {
|
||||
$isForce = ((int) $row['is_force'] === 1) ? 0 : 1;
|
||||
}
|
||||
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('project_versions')} SET is_force = ? WHERE id = ?",
|
||||
[$isForce, $id]
|
||||
);
|
||||
|
||||
logger('version_force_toggle', 'project_version', $id, [
|
||||
'version' => $row['version'],
|
||||
'is_force' => $isForce,
|
||||
]);
|
||||
|
||||
$this->success(
|
||||
['id' => $id, 'is_force' => $isForce],
|
||||
$isForce ? '已开启强制推送' : '已关闭强制推送'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设为最新版本
|
||||
* PUT /api/versions/{id}/latest
|
||||
*/
|
||||
public function setLatest(int $id): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
if (!VersionService::canPublish($user['role'] ?? '')) {
|
||||
$this->error('代理账号不可设置最新版本', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT * FROM {$db->table('project_versions')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('版本不存在', 404);
|
||||
}
|
||||
if (!VersionService::assertProjectAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权操作该项目的版本', 403);
|
||||
}
|
||||
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('project_versions')} SET is_latest = 0 WHERE project_id = ?",
|
||||
[(int) $row['project_id']]
|
||||
);
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('project_versions')} SET is_latest = 1, status = 1 WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
$db->commit();
|
||||
} catch (\Throwable $e) {
|
||||
$db->rollback();
|
||||
$this->error('设置最新版本失败');
|
||||
}
|
||||
|
||||
logger('version_set_latest', 'project_version', $id, ['version' => $row['version']]);
|
||||
$this->success(null, '已设为最新版本');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除版本
|
||||
* DELETE /api/versions/{id}
|
||||
*/
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$user = $this->getCurrentUser() ?: [];
|
||||
if (!VersionService::canPublish($user['role'] ?? '')) {
|
||||
$this->error('代理账号不可删除版本', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT * FROM {$db->table('project_versions')} WHERE id = ?",
|
||||
[$id]
|
||||
);
|
||||
if (!$row) {
|
||||
$this->error('版本不存在', 404);
|
||||
}
|
||||
if (!VersionService::assertProjectAccess((int) $row['project_id'], $user)) {
|
||||
$this->error('无权操作该项目的版本', 403);
|
||||
}
|
||||
|
||||
$db->execute("DELETE FROM {$db->table('project_versions')} WHERE id = ?", [$id]);
|
||||
|
||||
// 删除物理文件
|
||||
$abs = BASE_PATH . '/public' . $row['file_path'];
|
||||
if (is_file($abs)) {
|
||||
@unlink($abs);
|
||||
}
|
||||
|
||||
logger('version_delete', 'project_version', $id, [
|
||||
'project_id' => (int) $row['project_id'],
|
||||
'version' => $row['version'],
|
||||
]);
|
||||
|
||||
$this->success(null, '版本已删除');
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,12 @@ namespace App\Controllers;
|
||||
use App\Core\Controller;
|
||||
use App\Core\Database;
|
||||
use App\Core\Validator;
|
||||
use App\Services\InstallationService;
|
||||
use App\Services\VersionService;
|
||||
|
||||
/**
|
||||
* 公开接口控制器
|
||||
* 包含:购买页、查询页、授权验证、支付回调
|
||||
* 包含:购买页、查询页、授权验证、安装上报、支付回调
|
||||
*/
|
||||
class PublicController extends Controller
|
||||
{
|
||||
@@ -23,6 +25,25 @@ class PublicController extends Controller
|
||||
$this->success($projects);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已启用的支付方式列表(前台购买页展示用)
|
||||
* GET /api/public/payment/options
|
||||
*/
|
||||
public function paymentOptions(): void
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT `value` FROM {$db->table('configs')} WHERE `key` = 'payment_pay_types'"
|
||||
);
|
||||
$types = $row ? json_decode($row['value'], true) : ['alipay', 'wxpay'];
|
||||
$valid = ['alipay', 'wxpay', 'qqpay'];
|
||||
$types = array_values(array_filter($types, fn($t) => in_array($t, $valid, true)));
|
||||
if (empty($types)) {
|
||||
$types = ['alipay', 'wxpay'];
|
||||
}
|
||||
$this->success(['pay_types' => $types, 'payment_enabled' => $row !== null]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目的卡密类型(套餐)列表
|
||||
*/
|
||||
@@ -66,6 +87,17 @@ class PublicController extends Controller
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
// 校验支付方式是否已勾选启用
|
||||
$payTypesRow = $db->fetch(
|
||||
"SELECT `value` FROM {$db->table('configs')} WHERE `key` = 'payment_pay_types'"
|
||||
);
|
||||
if ($payTypesRow) {
|
||||
$enabledPayTypes = json_decode($payTypesRow['value'], true) ?: [];
|
||||
if (!in_array($payType, $enabledPayTypes, true)) {
|
||||
$this->error('该支付方式未开启,请选择其他支付方式');
|
||||
}
|
||||
}
|
||||
|
||||
// 验证项目
|
||||
$project = $db->fetch(
|
||||
"SELECT id, name FROM {$db->table('projects')} WHERE id = ? AND status = 1 AND deleted_at IS NULL",
|
||||
@@ -484,20 +516,121 @@ class PublicController extends Controller
|
||||
$this->success($card);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查更新 + 上报安装/在线 (客户端调用)
|
||||
* Header: X-Api-Key: {project_api_key}
|
||||
* POST: {machine_id, client_version?, card_key?, device_info?}
|
||||
*/
|
||||
public function checkUpdate(): void
|
||||
{
|
||||
$projectId = (int) ($_SERVER['HTTP_X_PROJECT_ID'] ?? 0);
|
||||
$input = $this->getJsonInput();
|
||||
|
||||
$machineId = trim((string) ($input['machine_id'] ?? ''));
|
||||
$clientVersion = trim((string) ($input['client_version'] ?? ''));
|
||||
$cardKey = trim((string) ($input['card_key'] ?? ''));
|
||||
$deviceInfo = (string) ($input['device_info'] ?? '');
|
||||
$deviceIp = (string) ($input['ip'] ?? clientIp());
|
||||
|
||||
if ($machineId === '') {
|
||||
$this->error('缺少机器码 machine_id', 400);
|
||||
}
|
||||
|
||||
$cardId = null;
|
||||
if ($cardKey !== '') {
|
||||
$db = Database::getInstance();
|
||||
$card = $db->fetch(
|
||||
"SELECT id FROM {$db->table('cards')} WHERE card_key = ? AND project_id = ?",
|
||||
[$cardKey, $projectId]
|
||||
);
|
||||
if ($card) {
|
||||
$cardId = (int) $card['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$upsert = InstallationService::upsert(
|
||||
$projectId,
|
||||
$machineId,
|
||||
$deviceIp,
|
||||
$deviceInfo,
|
||||
$clientVersion,
|
||||
$cardId,
|
||||
$cardKey
|
||||
);
|
||||
|
||||
$payload = VersionService::buildUpdatePayload($projectId, $clientVersion);
|
||||
$payload['install_id'] = $upsert['install_id'];
|
||||
|
||||
// 有更新时累计下载提示次数
|
||||
if (!empty($payload['update_available']) && !empty($payload['version'])) {
|
||||
$db = Database::getInstance();
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('project_versions')} SET download_count = download_count + 1
|
||||
WHERE project_id = ? AND version = ?",
|
||||
[$projectId, $payload['version']]
|
||||
);
|
||||
}
|
||||
|
||||
$this->success($payload, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装心跳 (客户端调用)
|
||||
* Header: X-Api-Key: {project_api_key}
|
||||
* POST: {machine_id, client_version?, card_key?, device_info?}
|
||||
*/
|
||||
public function heartbeat(): void
|
||||
{
|
||||
$projectId = (int) ($_SERVER['HTTP_X_PROJECT_ID'] ?? 0);
|
||||
$input = $this->getJsonInput();
|
||||
|
||||
$machineId = trim((string) ($input['machine_id'] ?? ''));
|
||||
if ($machineId === '') {
|
||||
$this->error('缺少机器码 machine_id', 400);
|
||||
}
|
||||
|
||||
$cardKey = trim((string) ($input['card_key'] ?? ''));
|
||||
$cardId = null;
|
||||
if ($cardKey !== '') {
|
||||
$db = Database::getInstance();
|
||||
$card = $db->fetch(
|
||||
"SELECT id FROM {$db->table('cards')} WHERE card_key = ? AND project_id = ?",
|
||||
[$cardKey, $projectId]
|
||||
);
|
||||
if ($card) {
|
||||
$cardId = (int) $card['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$upsert = InstallationService::heartbeat(
|
||||
$projectId,
|
||||
$machineId,
|
||||
(string) ($input['ip'] ?? clientIp()),
|
||||
(string) ($input['device_info'] ?? ''),
|
||||
(string) ($input['client_version'] ?? ''),
|
||||
$cardId,
|
||||
$cardKey
|
||||
);
|
||||
|
||||
$this->success(['install_id' => $upsert['install_id']], 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权验证接口 (客户端调用)
|
||||
* Header: X-Api-Key: {project_api_key}
|
||||
* POST: {card_key, machine_id, ip, device_info}
|
||||
* POST: {card_key, machine_id, ip, device_info, client_version?}
|
||||
* 成功时附带更新提示字段,并更新安装 last_online_at
|
||||
*/
|
||||
public function verify(): void
|
||||
{
|
||||
$projectId = $_SERVER['HTTP_X_PROJECT_ID'] ?? 0;
|
||||
$projectId = (int) ($_SERVER['HTTP_X_PROJECT_ID'] ?? 0);
|
||||
$input = $this->getJsonInput();
|
||||
|
||||
$cardKey = $input['card_key'] ?? '';
|
||||
$machineId = $input['machine_id'] ?? '';
|
||||
$deviceIp = $input['ip'] ?? clientIp();
|
||||
$deviceInfo = $input['device_info'] ?? '';
|
||||
$clientVersion = (string) ($input['client_version'] ?? '');
|
||||
|
||||
if (empty($cardKey) || empty($machineId)) {
|
||||
$this->error('参数不完整', 400);
|
||||
@@ -546,6 +679,20 @@ class PublicController extends Controller
|
||||
[json_encode($bindInfo, JSON_UNESCAPED_UNICODE), $expireTime, $card['id']]
|
||||
);
|
||||
|
||||
// 登记安装记录
|
||||
$upsert = InstallationService::upsert(
|
||||
$projectId,
|
||||
(string) $machineId,
|
||||
(string) $deviceIp,
|
||||
(string) $deviceInfo,
|
||||
$clientVersion,
|
||||
(int) $card['id'],
|
||||
(string) $cardKey
|
||||
);
|
||||
|
||||
$updatePayload = VersionService::buildUpdatePayload($projectId, $clientVersion);
|
||||
$updatePayload['install_id'] = $upsert['install_id'];
|
||||
|
||||
$this->success([
|
||||
'valid' => true,
|
||||
'message' => '激活成功',
|
||||
@@ -553,7 +700,7 @@ class PublicController extends Controller
|
||||
'duration_days' => $card['duration_days'],
|
||||
'expire_time' => $expireTime,
|
||||
'is_permanent' => $card['duration_days'] == 0,
|
||||
], 'ok');
|
||||
] + $updatePayload, 'ok');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -572,6 +719,20 @@ class PublicController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
// 授权有效:更新安装 last_online_at
|
||||
$upsert = InstallationService::upsert(
|
||||
$projectId,
|
||||
(string) $machineId,
|
||||
(string) $deviceIp,
|
||||
(string) $deviceInfo,
|
||||
$clientVersion,
|
||||
(int) $card['id'],
|
||||
(string) $cardKey
|
||||
);
|
||||
|
||||
$updatePayload = VersionService::buildUpdatePayload($projectId, $clientVersion);
|
||||
$updatePayload['install_id'] = $upsert['install_id'];
|
||||
|
||||
$this->success([
|
||||
'valid' => true,
|
||||
'message' => '授权有效',
|
||||
@@ -581,9 +742,11 @@ class PublicController extends Controller
|
||||
'bound_at' => $card['bound_at'],
|
||||
'is_permanent' => $card['duration_days'] == 0,
|
||||
'remaining_days' => $card['expire_time'] ? max(0, ceil((strtotime($card['expire_time']) - time()) / 86400)) : null,
|
||||
], 'ok');
|
||||
] + $updatePayload, 'ok');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->success(['valid' => false, 'message' => '卡密状态异常'], 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -148,4 +148,23 @@ function logger(string $action, string $targetType = '', int $targetId = 0, arra
|
||||
} catch (\Throwable $e) {
|
||||
error_log('Logger error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 语义化版本比较
|
||||
* @return int -1 a<b, 0 a==b, 1 a>b
|
||||
*/
|
||||
function compareVersions(string $a, string $b): int
|
||||
{
|
||||
$normalize = static function (string $v): string {
|
||||
$v = trim($v);
|
||||
if ($v === '') {
|
||||
return '0.0.0';
|
||||
}
|
||||
if ($v[0] === 'v' || $v[0] === 'V') {
|
||||
$v = substr($v, 1);
|
||||
}
|
||||
return $v;
|
||||
};
|
||||
return version_compare($normalize($a), $normalize($b));
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
/**
|
||||
* 安装记录服务
|
||||
* 安装次数统计、存活/已删除、最后上线
|
||||
*/
|
||||
class InstallationService
|
||||
{
|
||||
/**
|
||||
* 上报/登记安装(check-update / verify 成功时调用)
|
||||
* 同项目同机器存在 active 记录则更新,否则新建(重装/新设备独立计数)
|
||||
*
|
||||
* @return array {install_id: int, is_new: bool}
|
||||
*/
|
||||
public static function upsert(
|
||||
int $projectId,
|
||||
string $machineId,
|
||||
string $ip = '',
|
||||
string $deviceInfo = '',
|
||||
string $clientVersion = '',
|
||||
?int $cardId = null,
|
||||
string $cardKey = ''
|
||||
): array {
|
||||
$db = Database::getInstance();
|
||||
|
||||
$existing = $db->fetch(
|
||||
"SELECT id FROM {$db->table('installations')}
|
||||
WHERE project_id = ? AND machine_id = ? AND status = 'active'
|
||||
ORDER BY id DESC LIMIT 1",
|
||||
[$projectId, $machineId]
|
||||
);
|
||||
|
||||
if ($existing) {
|
||||
$updateCardId = $cardId;
|
||||
$updateCardKey = $cardKey !== '' ? $cardKey : null;
|
||||
$updateDevice = $deviceInfo !== '' ? $deviceInfo : null;
|
||||
$updateVersion = $clientVersion !== '' ? $clientVersion : null;
|
||||
|
||||
$db->execute(
|
||||
"UPDATE {$db->table('installations')}
|
||||
SET ip = ?, device_info = ?, client_version = ?,
|
||||
last_online_at = NOW(),
|
||||
card_id = COALESCE(?, card_id),
|
||||
card_key = COALESCE(?, card_key)
|
||||
WHERE id = ?",
|
||||
[
|
||||
$ip !== '' ? $ip : null,
|
||||
$updateDevice,
|
||||
$updateVersion,
|
||||
$updateCardId,
|
||||
$updateCardKey,
|
||||
$existing['id'],
|
||||
]
|
||||
);
|
||||
return ['install_id' => (int) $existing['id'], 'is_new' => false];
|
||||
}
|
||||
|
||||
$installId = $db->insert(
|
||||
"INSERT INTO {$db->table('installations')}
|
||||
(project_id, card_id, card_key, machine_id, ip, device_info, client_version,
|
||||
status, install_count, last_online_at, installed_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 'active', 1, NOW(), NOW())",
|
||||
[
|
||||
$projectId,
|
||||
$cardId,
|
||||
$cardKey,
|
||||
$machineId,
|
||||
$ip !== '' ? $ip : null,
|
||||
$deviceInfo !== '' ? $deviceInfo : null,
|
||||
$clientVersion !== '' ? $clientVersion : null,
|
||||
]
|
||||
);
|
||||
|
||||
return ['install_id' => $installId, 'is_new' => true];
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅更新在线时间(心跳)
|
||||
*/
|
||||
public static function heartbeat(
|
||||
int $projectId,
|
||||
string $machineId,
|
||||
string $ip = '',
|
||||
string $deviceInfo = '',
|
||||
string $clientVersion = '',
|
||||
?int $cardId = null,
|
||||
string $cardKey = ''
|
||||
): array {
|
||||
return self::upsert($projectId, $machineId, $ip, $deviceInfo, $clientVersion, $cardId, $cardKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据范围过滤(admin / project_admin / agent)
|
||||
* @return array {where: string, params: array}
|
||||
*/
|
||||
public static function scope(array $user): array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$role = $user['role'] ?? '';
|
||||
|
||||
if ($role === 'admin') {
|
||||
return ['where' => '', 'params' => []];
|
||||
}
|
||||
|
||||
if ($role === 'project_admin') {
|
||||
$projectIds = $user['project_ids'] ?? [];
|
||||
if (empty($projectIds)) {
|
||||
return ['where' => ' AND 1=0', 'params' => []];
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($projectIds), '?'));
|
||||
return [
|
||||
'where' => " AND i.project_id IN ({$placeholders})",
|
||||
'params' => array_map('intval', $projectIds),
|
||||
];
|
||||
}
|
||||
|
||||
// 代理:仅本人及下级代理发放卡密相关的安装
|
||||
$agentIds = PermissionService::getAgentIdsUnder((int) ($user['id'] ?? 0));
|
||||
if (empty($agentIds)) {
|
||||
return ['where' => ' AND 1=0', 'params' => []];
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($agentIds), '?'));
|
||||
return [
|
||||
'where' => " AND i.card_id IN (SELECT c.id FROM {$db->table('cards')} c WHERE c.use_user_id IN ({$placeholders}))",
|
||||
'params' => array_map('intval', $agentIds),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建安装列表/统计 WHERE
|
||||
*/
|
||||
public static function buildListWhere(array $user, array $filters = []): array
|
||||
{
|
||||
$scope = self::scope($user);
|
||||
$where = $scope['where'];
|
||||
$params = $scope['params'];
|
||||
|
||||
if (!empty($filters['project_id'])) {
|
||||
$where .= ' AND i.project_id = ?';
|
||||
$params[] = (int) $filters['project_id'];
|
||||
}
|
||||
if (!empty($filters['status']) && in_array($filters['status'], ['active', 'deleted'], true)) {
|
||||
$where .= ' AND i.status = ?';
|
||||
$params[] = $filters['status'];
|
||||
}
|
||||
if (!empty($filters['keyword'])) {
|
||||
$where .= ' AND (i.machine_id LIKE ? OR i.card_key LIKE ? OR i.ip LIKE ?)';
|
||||
$kw = '%' . $filters['keyword'] . '%';
|
||||
$params[] = $kw;
|
||||
$params[] = $kw;
|
||||
$params[] = $kw;
|
||||
}
|
||||
if (!empty($filters['date_from'])) {
|
||||
$where .= ' AND i.installed_at >= ?';
|
||||
$params[] = $filters['date_from'] . ' 00:00:00';
|
||||
}
|
||||
if (!empty($filters['date_to'])) {
|
||||
$where .= ' AND i.installed_at <= ?';
|
||||
$params[] = $filters['date_to'] . ' 23:59:59';
|
||||
}
|
||||
|
||||
return ['where' => $where, 'params' => $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装统计(含已删除)
|
||||
*/
|
||||
public static function stats(array $user, ?int $projectId = null): array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$whereList = self::buildListWhere($user, $projectId ? ['project_id' => $projectId] : []);
|
||||
$where = $whereList['where'];
|
||||
$params = $whereList['params'];
|
||||
|
||||
$total = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('installations')} i WHERE 1=1 {$where}",
|
||||
$params
|
||||
);
|
||||
$active = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('installations')} i WHERE i.status = 'active' {$where}",
|
||||
$params
|
||||
);
|
||||
$deleted = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('installations')} i WHERE i.status = 'deleted' {$where}",
|
||||
$params
|
||||
);
|
||||
$todayNew = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('installations')} i WHERE DATE(i.installed_at) = CURDATE() {$where}",
|
||||
$params
|
||||
);
|
||||
$weekNew = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('installations')} i WHERE i.installed_at >= DATE_SUB(NOW(), INTERVAL 7 DAY) {$where}",
|
||||
$params
|
||||
);
|
||||
$lastOnline = $db->fetchColumn(
|
||||
"SELECT MAX(i.last_online_at) FROM {$db->table('installations')} i WHERE i.last_online_at IS NOT NULL {$where}",
|
||||
$params
|
||||
);
|
||||
|
||||
$projects = $db->fetchAll(
|
||||
"SELECT i.project_id, p.name AS project_name,
|
||||
COUNT(*) AS total_installs,
|
||||
SUM(CASE WHEN i.status = 'active' THEN 1 ELSE 0 END) AS active,
|
||||
SUM(CASE WHEN i.status = 'deleted' THEN 1 ELSE 0 END) AS deleted,
|
||||
SUM(CASE WHEN DATE(i.installed_at) = CURDATE() THEN 1 ELSE 0 END) AS today_new,
|
||||
MAX(i.last_online_at) AS last_online_at
|
||||
FROM {$db->table('installations')} i
|
||||
LEFT JOIN {$db->table('projects')} p ON p.id = i.project_id
|
||||
WHERE 1=1 {$where}
|
||||
GROUP BY i.project_id, p.name
|
||||
ORDER BY total_installs DESC",
|
||||
$params
|
||||
);
|
||||
|
||||
return [
|
||||
'total_installs' => $total,
|
||||
'active' => $active,
|
||||
'deleted' => $deleted,
|
||||
'today_new' => $todayNew,
|
||||
'week_new' => $weekNew,
|
||||
'last_online_at' => $lastOnline ?: null,
|
||||
'projects' => array_map(static function (array $row): array {
|
||||
return [
|
||||
'project_id' => (int) $row['project_id'],
|
||||
'project_name' => $row['project_name'],
|
||||
'total_installs' => (int) $row['total_installs'],
|
||||
'active' => (int) $row['active'],
|
||||
'deleted' => (int) $row['deleted'],
|
||||
'today_new' => (int) $row['today_new'],
|
||||
'last_online_at' => $row['last_online_at'],
|
||||
];
|
||||
}, $projects),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
/**
|
||||
* 项目版本/安装包服务
|
||||
*/
|
||||
class VersionService
|
||||
{
|
||||
/**
|
||||
* 语义化版本比较
|
||||
* @return int -1 a<b, 0 a==b, 1 a>b
|
||||
*/
|
||||
public static function compare(string $a, string $b): int
|
||||
{
|
||||
return version_compare(self::normalize($a), self::normalize($b));
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化版本号:剥离前缀 v/V,预发布后缀
|
||||
*/
|
||||
public static function normalize(string $version): string
|
||||
{
|
||||
$version = trim($version);
|
||||
if ($version === '') {
|
||||
return '0.0.0';
|
||||
}
|
||||
if ($version[0] === 'v' || $version[0] === 'V') {
|
||||
$version = substr($version, 1);
|
||||
}
|
||||
// 预发布:1.2.0-beta.1 -> 1.2.0-beta
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目最新可用版本
|
||||
*/
|
||||
public static function getLatest(int $projectId): ?array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch(
|
||||
"SELECT * FROM {$db->table('project_versions')}
|
||||
WHERE project_id = ? AND status = 1 AND is_latest = 1
|
||||
ORDER BY id DESC LIMIT 1",
|
||||
[$projectId]
|
||||
);
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造客户端更新提示载荷
|
||||
*
|
||||
* @return array {
|
||||
* update_available: bool, update_required: bool,
|
||||
* current_version: string, latest_version: string,
|
||||
* version: ?string, download_url: ?string, file_size: int,
|
||||
* checksum: string, changelog: ?string,
|
||||
* min_client_version: string, is_force: int
|
||||
* }
|
||||
*/
|
||||
public static function buildUpdatePayload(int $projectId, string $clientVersion = ''): array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$latest = self::getLatest($projectId);
|
||||
|
||||
$clientVersion = self::normalize($clientVersion);
|
||||
$hasClient = trim($clientVersion) !== '' && $clientVersion !== '0.0.0';
|
||||
|
||||
if (!$latest) {
|
||||
return [
|
||||
'update_available' => false,
|
||||
'update_required' => false,
|
||||
'current_version' => $clientVersion,
|
||||
'latest_version' => '',
|
||||
'version' => null,
|
||||
'download_url' => null,
|
||||
'file_size' => 0,
|
||||
'checksum' => '',
|
||||
'changelog' => null,
|
||||
'min_client_version' => '',
|
||||
'is_force' => 0,
|
||||
'install_id' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$latestVersion = self::normalize($latest['version']);
|
||||
$minVersion = self::normalize($latest['min_client_version'] ?? '');
|
||||
$isForce = (int) $latest['is_force'];
|
||||
|
||||
$updateAvailable = !$hasClient || self::compare($latestVersion, $clientVersion) > 0;
|
||||
$belowMin = $minVersion !== '' && $minVersion !== '0.0.0'
|
||||
&& self::compare($clientVersion, $minVersion) < 0;
|
||||
$updateRequired = ($isForce === 1 && $updateAvailable) || ($belowMin && $updateAvailable);
|
||||
|
||||
return [
|
||||
'update_available' => $updateAvailable,
|
||||
'update_required' => $updateRequired,
|
||||
'current_version' => $clientVersion,
|
||||
'latest_version' => $latest['version'],
|
||||
'version' => $latest['version'],
|
||||
'download_url' => $latest['file_path'],
|
||||
'file_size' => (int) $latest['file_size'],
|
||||
'checksum' => $latest['checksum'] ?? '',
|
||||
'changelog' => $latest['changelog'],
|
||||
'min_client_version' => $latest['min_client_version'] ?? '',
|
||||
'is_force' => $isForce,
|
||||
'install_id' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据范围:项目管理员/管理员可见;代理只读(由控制器限制写操作)
|
||||
*/
|
||||
public static function scope(array $user): array
|
||||
{
|
||||
$role = $user['role'] ?? '';
|
||||
if ($role === 'admin') {
|
||||
return ['where' => 'p.deleted_at IS NULL', 'params' => []];
|
||||
}
|
||||
if ($role === 'project_admin') {
|
||||
$projectIds = $user['project_ids'] ?? [];
|
||||
if (empty($projectIds)) {
|
||||
return ['where' => '1=0', 'params' => []];
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($projectIds), '?'));
|
||||
return [
|
||||
'where' => "p.deleted_at IS NULL AND p.id IN ({$placeholders})",
|
||||
'params' => array_map('intval', $projectIds),
|
||||
];
|
||||
}
|
||||
|
||||
// 代理:有卡密记录的项目
|
||||
$db = Database::getInstance();
|
||||
$agentIds = PermissionService::getAgentIdsUnder((int) ($user['id'] ?? 0));
|
||||
if (empty($agentIds)) {
|
||||
return ['where' => '1=0', 'params' => []];
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($agentIds), '?'));
|
||||
return [
|
||||
'where' => "p.deleted_at IS NULL AND p.id IN (
|
||||
SELECT DISTINCT c.project_id FROM {$db->table('cards')} c WHERE c.use_user_id IN ({$placeholders})
|
||||
)",
|
||||
'params' => array_map('intval', $agentIds),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许发布/修改版本(仅 admin / project_admin)
|
||||
*/
|
||||
public static function canPublish(?string $role): bool
|
||||
{
|
||||
return in_array($role, ['admin', 'project_admin'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验项目访问权限
|
||||
*/
|
||||
public static function assertProjectAccess(int $projectId, array $user): bool
|
||||
{
|
||||
$role = $user['role'] ?? '';
|
||||
if ($role === 'admin') {
|
||||
return true;
|
||||
}
|
||||
if ($role === 'project_admin') {
|
||||
$projectIds = $user['project_ids'] ?? [];
|
||||
return in_array($projectId, array_map('intval', $projectIds), true);
|
||||
}
|
||||
if ($role === 'agent') {
|
||||
$db = Database::getInstance();
|
||||
$agentIds = PermissionService::getAgentIdsUnder((int) ($user['id'] ?? 0));
|
||||
if (empty($agentIds)) {
|
||||
return false;
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($agentIds), '?'));
|
||||
$count = (int) $db->fetchColumn(
|
||||
"SELECT COUNT(*) FROM {$db->table('cards')} WHERE project_id = ? AND use_user_id IN ({$placeholders})",
|
||||
array_merge([$projectId], $agentIds)
|
||||
);
|
||||
return $count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
-- 安装记录表 + 项目版本/安装包表
|
||||
-- 适用于已有数据库的增量升级;新库直接使用 schema.sql
|
||||
|
||||
-- ============================================
|
||||
-- 安装记录表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `ca_installations` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`project_id` BIGINT UNSIGNED NOT NULL COMMENT '所属项目ID',
|
||||
`card_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '关联卡密ID(可空)',
|
||||
`card_key` VARCHAR(64) DEFAULT '' COMMENT '卡密(冗余,便于查询)',
|
||||
`machine_id` VARCHAR(128) NOT NULL COMMENT '机器指纹',
|
||||
`ip` VARCHAR(45) DEFAULT '' COMMENT '最后IP',
|
||||
`device_info` TEXT DEFAULT NULL COMMENT '设备信息',
|
||||
`client_version` VARCHAR(50) DEFAULT '' COMMENT '客户端版本',
|
||||
`status` ENUM('active','deleted') NOT NULL DEFAULT 'active' COMMENT '状态: active=存活, deleted=已删除',
|
||||
`install_count` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT '该机器累计激活次数',
|
||||
`last_online_at` DATETIME DEFAULT NULL COMMENT '最后上线时间',
|
||||
`installed_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '安装时间',
|
||||
`deleted_at` DATETIME DEFAULT NULL COMMENT '删除时间',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_project_id` (`project_id`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_project_machine` (`project_id`,`machine_id`,`status`),
|
||||
KEY `idx_card_id` (`card_id`),
|
||||
KEY `idx_last_online` (`last_online_at`),
|
||||
KEY `idx_deleted_at` (`deleted_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='安装记录表';
|
||||
|
||||
-- ============================================
|
||||
-- 项目版本/安装包表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `ca_project_versions` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`project_id` BIGINT UNSIGNED NOT NULL COMMENT '所属项目ID',
|
||||
`version` VARCHAR(50) NOT NULL COMMENT '版本号(如 1.2.0)',
|
||||
`file_name` VARCHAR(255) NOT NULL COMMENT '原始文件名',
|
||||
`file_path` VARCHAR(500) NOT NULL COMMENT '存储路径(相对public)',
|
||||
`file_size` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '文件大小(字节)',
|
||||
`checksum` VARCHAR(64) DEFAULT '' COMMENT 'SHA256',
|
||||
`changelog` TEXT DEFAULT NULL COMMENT '更新说明',
|
||||
`min_client_version` VARCHAR(50) DEFAULT '' COMMENT '强制更新最低版本(可空)',
|
||||
`is_force` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否强制推送: 0=否, 1=是',
|
||||
`is_latest` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否最新版本',
|
||||
`download_count` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载次数',
|
||||
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=正常',
|
||||
`created_by` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '发布人ID',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_project_version` (`project_id`,`version`),
|
||||
KEY `idx_project_id` (`project_id`),
|
||||
KEY `idx_is_latest` (`project_id`,`is_latest`,`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='项目版本/安装包表';
|
||||
@@ -5,6 +5,8 @@
|
||||
-- 字符集: utf8mb4
|
||||
-- ============================================
|
||||
|
||||
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS `card_auth` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE `card_auth`;
|
||||
|
||||
@@ -279,7 +281,7 @@ CREATE TABLE `ca_coupons` (
|
||||
|
||||
-- 初始化超级管理员 (密码: admin123456)
|
||||
INSERT INTO `ca_users` (`username`, `password`, `nickname`, `role`, `status`) VALUES
|
||||
('admin', '$2y$12$LJ3m4ys3OoMJ8zKR0gVNNe5hHOqFh0VhJmKqxXkGgFMfGZqXsQHqK', '超级管理员', 'admin', 1);
|
||||
('admin', '$2y$10$5IZyJdCtuVQ0O7fIzeXgbOa8rOi2kkHBYmEiA4Z/UyKxK.dgBXZLO', '超级管理员', 'admin', 1);
|
||||
|
||||
-- 初始化演示项目
|
||||
INSERT INTO `ca_projects` (`name`, `description`, `api_key`, `status`) VALUES
|
||||
@@ -328,4 +330,60 @@ INSERT INTO `ca_configs` (`key`, `value`, `description`) VALUES
|
||||
('smtp_from_email', '', '发件人邮箱'),
|
||||
('smtp_from_name', 'CardAuth', '发件人名称'),
|
||||
('smtp_enabled', '0', '是否启用邮件通知(1=启用,0=禁用)'),
|
||||
('smtp_expire_days', '7', '到期前N天发送提醒邮件');
|
||||
('smtp_expire_days', '7', '到期前N天发送提醒邮件');
|
||||
|
||||
-- ============================================
|
||||
-- 12. 安装记录表
|
||||
-- ============================================
|
||||
DROP TABLE IF EXISTS `ca_installations`;
|
||||
CREATE TABLE `ca_installations` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`project_id` BIGINT UNSIGNED NOT NULL COMMENT '所属项目ID',
|
||||
`card_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '关联卡密ID(可空)',
|
||||
`card_key` VARCHAR(64) DEFAULT '' COMMENT '卡密(冗余,便于查询)',
|
||||
`machine_id` VARCHAR(128) NOT NULL COMMENT '机器指纹',
|
||||
`ip` VARCHAR(45) DEFAULT '' COMMENT '最后IP',
|
||||
`device_info` TEXT DEFAULT NULL COMMENT '设备信息',
|
||||
`client_version` VARCHAR(50) DEFAULT '' COMMENT '客户端版本',
|
||||
`status` ENUM('active','deleted') NOT NULL DEFAULT 'active' COMMENT '状态: active=存活, deleted=已删除',
|
||||
`install_count` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT '该机器累计激活次数',
|
||||
`last_online_at` DATETIME DEFAULT NULL COMMENT '最后上线时间',
|
||||
`installed_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '安装时间',
|
||||
`deleted_at` DATETIME DEFAULT NULL COMMENT '删除时间',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_project_id` (`project_id`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_project_machine` (`project_id`,`machine_id`,`status`),
|
||||
KEY `idx_card_id` (`card_id`),
|
||||
KEY `idx_last_online` (`last_online_at`),
|
||||
KEY `idx_deleted_at` (`deleted_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='安装记录表';
|
||||
|
||||
-- ============================================
|
||||
-- 13. 项目版本/安装包表
|
||||
-- ============================================
|
||||
DROP TABLE IF EXISTS `ca_project_versions`;
|
||||
CREATE TABLE `ca_project_versions` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`project_id` BIGINT UNSIGNED NOT NULL COMMENT '所属项目ID',
|
||||
`version` VARCHAR(50) NOT NULL COMMENT '版本号(如 1.2.0)',
|
||||
`file_name` VARCHAR(255) NOT NULL COMMENT '原始文件名',
|
||||
`file_path` VARCHAR(500) NOT NULL COMMENT '存储路径(相对public)',
|
||||
`file_size` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '文件大小(字节)',
|
||||
`checksum` VARCHAR(64) DEFAULT '' COMMENT 'SHA256',
|
||||
`changelog` TEXT DEFAULT NULL COMMENT '更新说明',
|
||||
`min_client_version` VARCHAR(50) DEFAULT '' COMMENT '强制更新最低版本(可空)',
|
||||
`is_force` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否强制推送: 0=否, 1=是',
|
||||
`is_latest` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否最新版本',
|
||||
`download_count` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '下载次数',
|
||||
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=正常',
|
||||
`created_by` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '发布人ID',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_project_version` (`project_id`,`version`),
|
||||
KEY `idx_project_id` (`project_id`),
|
||||
KEY `idx_is_latest` (`project_id`,`is_latest`,`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='项目版本/安装包表';
|
||||
Whitespace-only changes.
@@ -16,6 +16,8 @@ use App\Controllers\AuthorizationController;
|
||||
use App\Controllers\CouponController;
|
||||
use App\Controllers\BlacklistController;
|
||||
use App\Controllers\NotificationController;
|
||||
use App\Controllers\InstallationController;
|
||||
use App\Controllers\ProjectVersionController;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
use App\Middleware\RateLimitMiddleware;
|
||||
use App\Middleware\ApiKeyMiddleware;
|
||||
@@ -41,6 +43,9 @@ $router->group('api/public', function ($router) {
|
||||
// 卡密查询
|
||||
$router->get('cards/query', [PublicController::class, 'queryCard']);
|
||||
|
||||
// 支付方式(前台展示用)
|
||||
$router->get('payment/options', [PublicController::class, 'paymentOptions']);
|
||||
|
||||
// 支付回调
|
||||
$router->get('payment/notify', [PublicController::class, 'paymentNotify']);
|
||||
$router->post('payment/notify', [PublicController::class, 'paymentNotify']);
|
||||
@@ -65,6 +70,12 @@ $router->group('api/public/verify', function ($router) {
|
||||
$router->post('', [PublicController::class, 'verify']);
|
||||
}, [new ApiKeyMiddleware(), new RateLimitMiddleware(60, 60, 'verify')]);
|
||||
|
||||
// 安装上报/检查更新 (API Key认证)
|
||||
$router->group('api/public/installations', function ($router) {
|
||||
$router->post('check-update', [PublicController::class, 'checkUpdate']);
|
||||
$router->post('heartbeat', [PublicController::class, 'heartbeat']);
|
||||
}, [new ApiKeyMiddleware(), new RateLimitMiddleware(60, 60, 'install')]);
|
||||
|
||||
// ============================================
|
||||
// 认证接口 (无需JWT)
|
||||
// ============================================
|
||||
@@ -175,6 +186,24 @@ $router->group('api', function ($router) {
|
||||
$router->put('coupons/{id}', [CouponController::class, 'update']);
|
||||
$router->delete('coupons/{id}', [CouponController::class, 'delete']);
|
||||
|
||||
// 安装统计管理 (admin / project_admin / agent)
|
||||
$router->get('installations', [InstallationController::class, 'list']);
|
||||
$router->get('installations/stats', [InstallationController::class, 'stats']);
|
||||
$router->get('installations/export', [InstallationController::class, 'export']);
|
||||
$router->get('installations/{id}', [InstallationController::class, 'detail']);
|
||||
$router->delete('installations/{id}', [InstallationController::class, 'delete']);
|
||||
$router->post('installations/{id}/restore', [InstallationController::class, 'restore']);
|
||||
$router->post('installations/batch-delete', [InstallationController::class, 'batchDelete']);
|
||||
|
||||
// 项目版本/安装包管理 (发布仅 admin/project_admin; agent 只读)
|
||||
$router->get('projects/{projectId}/versions', [ProjectVersionController::class, 'list']);
|
||||
$router->get('projects/{projectId}/versions/{id}', [ProjectVersionController::class, 'detail']);
|
||||
$router->post('projects/{projectId}/versions', [ProjectVersionController::class, 'create']);
|
||||
$router->put('versions/{id}', [ProjectVersionController::class, 'update']);
|
||||
$router->put('versions/{id}/force', [ProjectVersionController::class, 'toggleForce']);
|
||||
$router->put('versions/{id}/latest', [ProjectVersionController::class, 'setLatest']);
|
||||
$router->delete('versions/{id}', [ProjectVersionController::class, 'delete']);
|
||||
|
||||
// 黑名单管理(仅管理员)
|
||||
$router->group('blacklists', function ($router) {
|
||||
$router->get('', [BlacklistController::class, 'list']);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import request from './index'
|
||||
|
||||
/**
|
||||
* 安装统计 API
|
||||
*/
|
||||
const installationApi = {
|
||||
list(params) {
|
||||
return request.get('/installations', { params })
|
||||
},
|
||||
stats(params) {
|
||||
return request.get('/installations/stats', { params })
|
||||
},
|
||||
detail(id) {
|
||||
return request.get(`/installations/${id}`)
|
||||
},
|
||||
remove(id) {
|
||||
return request.delete(`/installations/${id}`)
|
||||
},
|
||||
restore(id) {
|
||||
return request.post(`/installations/${id}/restore`)
|
||||
},
|
||||
batchDelete(ids) {
|
||||
return request.post('/installations/batch-delete', { ids })
|
||||
},
|
||||
exportUrl(params = {}) {
|
||||
const q = new URLSearchParams()
|
||||
Object.entries(params).forEach(([k, v]) => {
|
||||
if (v !== '' && v !== null && v !== undefined) q.set(k, v)
|
||||
})
|
||||
const token = localStorage.getItem('access_token')
|
||||
if (token) q.set('token', token)
|
||||
return `/api/installations/export?${q.toString()}`
|
||||
}
|
||||
}
|
||||
|
||||
export default installationApi
|
||||
@@ -0,0 +1,33 @@
|
||||
import request from './index'
|
||||
|
||||
/**
|
||||
* 项目版本/安装包 API
|
||||
*/
|
||||
const versionApi = {
|
||||
list(projectId, params) {
|
||||
return request.get(`/projects/${projectId}/versions`, { params })
|
||||
},
|
||||
detail(projectId, id) {
|
||||
return request.get(`/projects/${projectId}/versions/${id}`)
|
||||
},
|
||||
create(projectId, formData) {
|
||||
return request.post(`/projects/${projectId}/versions`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: 300000
|
||||
})
|
||||
},
|
||||
update(id, data) {
|
||||
return request.put(`/versions/${id}`, data)
|
||||
},
|
||||
toggleForce(id, isForce) {
|
||||
return request.put(`/versions/${id}/force`, { is_force: isForce })
|
||||
},
|
||||
setLatest(id) {
|
||||
return request.put(`/versions/${id}/latest`)
|
||||
},
|
||||
remove(id) {
|
||||
return request.delete(`/versions/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
export default versionApi
|
||||
@@ -22,7 +22,6 @@ const routes = [
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/views/layout/MainLayout.vue'),
|
||||
redirect: '/dashboard',
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
@@ -78,6 +77,18 @@ const routes = [
|
||||
component: () => import('@/views/Authorizations.vue'),
|
||||
meta: { title: '授权管理', icon: 'Lock' }
|
||||
},
|
||||
{
|
||||
path: 'installations',
|
||||
name: 'Installations',
|
||||
component: () => import('@/views/Installations.vue'),
|
||||
meta: { title: '安装统计', icon: 'Download' }
|
||||
},
|
||||
{
|
||||
path: 'project-versions',
|
||||
name: 'ProjectVersions',
|
||||
component: () => import('@/views/ProjectVersions.vue'),
|
||||
meta: { title: '版本推送', icon: 'Upload' }
|
||||
},
|
||||
{
|
||||
path: 'coupons',
|
||||
name: 'Coupons',
|
||||
@@ -109,6 +120,18 @@ const routes = [
|
||||
name: 'Shop',
|
||||
component: () => import('@/views/public/Shop.vue'),
|
||||
meta: { title: '购买中心' }
|
||||
},
|
||||
{
|
||||
path: '/docs',
|
||||
name: 'IntroDocs',
|
||||
component: () => import('@/views/public/Docs.vue'),
|
||||
meta: { title: '系统介绍与使用文档' }
|
||||
},
|
||||
{
|
||||
path: '/result',
|
||||
name: 'PaymentResult',
|
||||
component: () => import('@/views/public/PaymentResult.vue'),
|
||||
meta: { title: '支付结果' }
|
||||
}
|
||||
]
|
||||
|
||||
@@ -129,9 +152,14 @@ router.beforeEach((to, from, next) => {
|
||||
document.title = to.meta.title ? `${to.meta.title} - CardAuth` : 'CardAuth'
|
||||
const token = localStorage.getItem('access_token')
|
||||
const userRole = localStorage.getItem('user_role')
|
||||
const publicPaths = ['/login', '/shop', '/agent/login', '/agent/register']
|
||||
const publicPaths = ['/login', '/shop', '/agent/login', '/agent/register', '/docs', '/result']
|
||||
const isPublic = publicPaths.some(p => to.path.startsWith(p))
|
||||
|
||||
// 首页一律显示介绍页;管理员可从介绍页顶部进入后台
|
||||
if (to.path === '/') {
|
||||
return next('/docs')
|
||||
}
|
||||
|
||||
// 未登录访问非公开页面 -> 登录页
|
||||
if (!isPublic && !token) {
|
||||
return next('/login')
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
<template>
|
||||
<div class="installations-page">
|
||||
<!-- 统计卡片 -->
|
||||
<el-row :gutter="20" class="stats-row">
|
||||
<el-col :xs="12" :sm="6" :md="6" :lg="6">
|
||||
<div class="stat-card stat-total">
|
||||
<div class="stat-icon"><el-icon :size="32"><Download /></el-icon></div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats?.total_installs ?? 0 }}</div>
|
||||
<div class="stat-label">总安装次数</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="12" :sm="6" :md="6" :lg="6">
|
||||
<div class="stat-card stat-active">
|
||||
<div class="stat-icon"><el-icon :size="32"><CircleCheck /></el-icon></div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats?.active ?? 0 }}</div>
|
||||
<div class="stat-label">存活安装</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="12" :sm="6" :md="6" :lg="6">
|
||||
<div class="stat-card stat-deleted">
|
||||
<div class="stat-icon"><el-icon :size="32"><CircleClose /></el-icon></div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats?.deleted ?? 0 }}</div>
|
||||
<div class="stat-label">已删除</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="12" :sm="6" :md="6" :lg="6">
|
||||
<div class="stat-card stat-online">
|
||||
<div class="stat-icon"><el-icon :size="32"><Timer /></el-icon></div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value stat-value-sm">{{ stats?.last_online_at || '-' }}</div>
|
||||
<div class="stat-label">最后上线时间</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 项目维度统计 -->
|
||||
<el-card shadow="never" class="main-card project-stats-card" v-if="stats?.projects?.length">
|
||||
<div class="section-title">项目安装统计(含已删除)</div>
|
||||
<el-table :data="stats.projects" stripe border class="data-table" :max-height="280">
|
||||
<el-table-column prop="project_name" label="项目" min-width="140" />
|
||||
<el-table-column prop="total_installs" label="安装次数" width="110" align="center" />
|
||||
<el-table-column prop="active" label="存活" width="90" align="center">
|
||||
<template #default="{ row }"><el-tag type="success" size="small">{{ row.active }}</el-tag></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="deleted" label="已删除" width="90" align="center">
|
||||
<template #default="{ row }"><el-tag type="danger" size="small">{{ row.deleted }}</el-tag></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="today_new" label="今日新增" width="100" align="center" />
|
||||
<el-table-column prop="last_online_at" label="最后上线" width="180">
|
||||
<template #default="{ row }">{{ row.last_online_at || '-' }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="main-card">
|
||||
<!-- 筛选 -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<el-select v-model="filters.project_id" placeholder="全部项目" clearable style="width: 160px" @change="handleFilterChange">
|
||||
<el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" />
|
||||
</el-select>
|
||||
<el-select v-model="filters.status" placeholder="全部状态" clearable style="width: 120px" @change="handleFilterChange">
|
||||
<el-option label="存活" value="active" />
|
||||
<el-option label="已删除" value="deleted" />
|
||||
</el-select>
|
||||
<el-input v-model="filters.keyword" placeholder="机器码/卡密/IP" clearable style="width: 180px" @clear="handleFilterChange" @keyup.enter="handleFilterChange" />
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
value-format="YYYY-MM-DD"
|
||||
style="width: 260px"
|
||||
@change="handleFilterChange"
|
||||
/>
|
||||
<el-button type="primary" :icon="Search" @click="handleFilterChange">搜索</el-button>
|
||||
<el-button :icon="Refresh" @click="resetFilters">重置</el-button>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<el-button type="success" :icon="Download" @click="handleExport">导出</el-button>
|
||||
<el-button type="danger" :icon="Delete" :disabled="!selectedRows.length" @click="handleBatchDelete">
|
||||
批量删除 ({{ selectedRows.length }})
|
||||
</el-button>
|
||||
<el-button :icon="Refresh" circle @click="refreshAll" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-table
|
||||
:data="list"
|
||||
v-loading="loading"
|
||||
stripe
|
||||
border
|
||||
highlight-current-row
|
||||
@selection-change="handleSelectionChange"
|
||||
row-key="id"
|
||||
:max-height="tableMaxHeight"
|
||||
class="data-table"
|
||||
>
|
||||
<el-table-column type="selection" width="50" align="center" fixed="left" />
|
||||
<el-table-column prop="id" label="ID" width="70" align="center" />
|
||||
<el-table-column prop="project_name" label="项目" width="130" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.project_name || row.project_id }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="machine_id" label="机器指纹" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }"><span class="mono-text">{{ row.machine_id }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="card_key" label="卡密" min-width="160" show-overflow-tooltip>
|
||||
<template #default="{ row }"><span class="mono-text">{{ row.card_key || '-' }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="ip" label="IP" width="130">
|
||||
<template #default="{ row }"><span class="mono-text">{{ row.ip || '-' }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="client_version" label="客户端版本" width="110" align="center">
|
||||
<template #default="{ row }">{{ row.client_version || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 'active' ? 'success' : 'danger'" size="small">
|
||||
{{ row.status === 'active' ? '存活' : '已删除' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="installed_at" label="安装时间" width="170" />
|
||||
<el-table-column prop="last_online_at" label="最后上线" width="170">
|
||||
<template #default="{ row }">{{ row.last_online_at || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" type="primary" link :icon="View" @click="showDetail(row)">详情</el-button>
|
||||
<el-button
|
||||
v-if="row.status === 'active' && canManage"
|
||||
size="small"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row)"
|
||||
>删除</el-button>
|
||||
<el-button
|
||||
v-if="row.status === 'deleted' && canManage"
|
||||
size="small"
|
||||
type="success"
|
||||
link
|
||||
@click="handleRestore(row)"
|
||||
>恢复</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50, 100, 200]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="fetchData"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<el-dialog v-model="detailVisible" title="安装详情" width="560px" destroy-on-close>
|
||||
<el-descriptions :column="1" border v-if="detailRow">
|
||||
<el-descriptions-item label="ID">{{ detailRow.id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="项目">{{ detailRow.project_name || detailRow.project_id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="机器指纹"><span class="mono-text">{{ detailRow.machine_id }}</span></el-descriptions-item>
|
||||
<el-descriptions-item label="卡密"><span class="mono-text">{{ detailRow.card_key || '-' }}</span></el-descriptions-item>
|
||||
<el-descriptions-item label="IP">{{ detailRow.ip || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="设备信息">{{ detailRow.device_info || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="客户端版本">{{ detailRow.client_version || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="detailRow.status === 'active' ? 'success' : 'danger'" size="small">
|
||||
{{ detailRow.status === 'active' ? '存活' : '已删除' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="安装时间">{{ detailRow.installed_at }}</el-descriptions-item>
|
||||
<el-descriptions-item label="最后上线">{{ detailRow.last_online_at || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="删除时间">{{ detailRow.deleted_at || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Search, Refresh, Delete, Download, View, CircleCheck, CircleClose, Timer } from '@element-plus/icons-vue'
|
||||
import request from '@/api'
|
||||
import installationApi from '@/api/installations'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const user = computed(() => userStore.user)
|
||||
const canManage = computed(() => ['admin', 'project_admin'].includes(user.value?.role))
|
||||
|
||||
const list = ref([])
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const total = ref(0)
|
||||
const selectedRows = ref([])
|
||||
const tableMaxHeight = ref(500)
|
||||
const stats = ref(null)
|
||||
const projects = ref([])
|
||||
const dateRange = ref(null)
|
||||
|
||||
const filters = ref({
|
||||
project_id: route.query.project_id ? Number(route.query.project_id) : '',
|
||||
status: '',
|
||||
keyword: ''
|
||||
})
|
||||
|
||||
const detailVisible = ref(false)
|
||||
const detailRow = ref(null)
|
||||
|
||||
function buildParams() {
|
||||
const params = {
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
project_id: filters.value.project_id || '',
|
||||
status: filters.value.status || '',
|
||||
keyword: filters.value.keyword || ''
|
||||
}
|
||||
if (dateRange.value?.length === 2) {
|
||||
params.date_from = dateRange.value[0]
|
||||
params.date_to = dateRange.value[1]
|
||||
}
|
||||
Object.keys(params).forEach(k => {
|
||||
if (params[k] === '' || params[k] === null || params[k] === undefined) delete params[k]
|
||||
})
|
||||
return params
|
||||
}
|
||||
|
||||
async function fetchList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await request.get('/installations', { params: buildParams() })
|
||||
list.value = res.data.list || []
|
||||
total.value = res.data.total || 0
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchStats() {
|
||||
try {
|
||||
const params = {}
|
||||
if (filters.value.project_id) params.project_id = filters.value.project_id
|
||||
const res = await installationApi.stats(params)
|
||||
stats.value = res.data
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchProjects() {
|
||||
try {
|
||||
const res = await request.get('/projects/all')
|
||||
projects.value = res.data.list || res.data || []
|
||||
if (!Array.isArray(projects.value)) projects.value = []
|
||||
} catch {
|
||||
projects.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function handleFilterChange() {
|
||||
page.value = 1
|
||||
fetchList()
|
||||
fetchStats()
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
filters.value = { project_id: '', status: '', keyword: '' }
|
||||
dateRange.value = null
|
||||
handleFilterChange()
|
||||
}
|
||||
|
||||
function handleSelectionChange(rows) {
|
||||
selectedRows.value = rows
|
||||
}
|
||||
|
||||
function handleSizeChange() {
|
||||
page.value = 1
|
||||
fetchList()
|
||||
}
|
||||
|
||||
function showDetail(row) {
|
||||
detailRow.value = row
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDelete(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定将该安装记录标记为已删除?', '提示', { type: 'warning' })
|
||||
await installationApi.remove(row.id)
|
||||
ElMessage.success('已删除')
|
||||
refreshAll()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function handleRestore(row) {
|
||||
try {
|
||||
await installationApi.restore(row.id)
|
||||
ElMessage.success('已恢复为存活')
|
||||
refreshAll()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function handleBatchDelete() {
|
||||
if (!selectedRows.value.length) return
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除选中的 ${selectedRows.value.length} 条安装记录吗?`, '批量删除', { type: 'warning' })
|
||||
await installationApi.batchDelete(selectedRows.value.map(r => r.id))
|
||||
ElMessage.success('批量删除成功')
|
||||
selectedRows.value = []
|
||||
refreshAll()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function handleExport() {
|
||||
const url = installationApi.exportUrl(buildParams())
|
||||
window.open(url, '_blank')
|
||||
ElMessage.success('导出任务已启动')
|
||||
}
|
||||
|
||||
function refreshAll() {
|
||||
fetchList()
|
||||
fetchStats()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchProjects()
|
||||
refreshAll()
|
||||
const setTableMax = () => {
|
||||
tableMaxHeight.value = Math.max(400, window.innerHeight - 420)
|
||||
}
|
||||
setTableMax()
|
||||
window.addEventListener('resize', setTableMax)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.installations-page { max-width: 1600px; margin: 0 auto; }
|
||||
.stats-row { margin-bottom: 20px; }
|
||||
.stat-card {
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
padding: 14px 18px; border-radius: 12px; background: #fff;
|
||||
border: 1px solid #f0f0f4; transition: all .25s;
|
||||
}
|
||||
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.05); }
|
||||
.stat-icon {
|
||||
width: 40px; height: 40px; border-radius: 10px;
|
||||
display: flex; align-items: center; justify-content: center; flex-shrink: 0;
|
||||
}
|
||||
.stat-icon :deep(.el-icon) { font-size: 20px !important; }
|
||||
.stat-total .stat-icon { background: #eff6ff; color: #3b82f6; }
|
||||
.stat-active .stat-icon { background: #f0fdf4; color: #22c55e; }
|
||||
.stat-deleted .stat-icon { background: #fef2f2; color: #ef4444; }
|
||||
.stat-online .stat-icon { background: #fff7ed; color: #f97316; }
|
||||
.stat-info { display: flex; flex-direction: column; min-width: 0; }
|
||||
.stat-value { font-size: 22px; font-weight: 700; color: #1d1d1f; line-height: 1.1; letter-spacing: -.3px; }
|
||||
.stat-value-sm { font-size: 13px; font-weight: 600; word-break: break-all; }
|
||||
.stat-label { font-size: 12px; color: #9ca3af; margin-top: 2px; font-weight: 500; }
|
||||
.main-card { margin-bottom: 20px; border-radius: 16px; border: 1px solid #f0f0f4; }
|
||||
.main-card:deep(.el-card__body) { padding: 24px; }
|
||||
.section-title { font-weight: 600; margin-bottom: 14px; color: #374151; }
|
||||
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
|
||||
.toolbar-left, .toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
||||
.toolbar :deep(.el-button) { border-radius: 10px; font-weight: 500; }
|
||||
.data-table { border-radius: 12px; overflow: hidden; }
|
||||
.data-table:deep(.el-table__header th) { background: #f8f9fb; font-weight: 600; color: #374151; font-size: 13px; border-color: #f0f0f4; }
|
||||
.data-table:deep(.el-table__body td) { font-size: 13px; color: #374151; border-color: #f5f5f7; }
|
||||
.mono-text { font-family: 'SF Mono', Cascadia Code, Courier New, monospace; font-size: 12px; }
|
||||
.pagination-wrapper { margin-top: 20px; display: flex; justify-content: flex-end; }
|
||||
@media (max-width: 768px) {
|
||||
.toolbar { flex-direction: column; align-items: stretch; }
|
||||
.toolbar-left, .toolbar-right { width: 100%; }
|
||||
.main-card:deep(.el-card__body) { padding: 14px; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,424 @@
|
||||
<template>
|
||||
<div class="versions-page">
|
||||
<el-card shadow="never" class="main-card">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<div class="page-title">版本推送管理</div>
|
||||
<div class="page-sub">上传最新安装包并推送客户端下载;可开启强制更新提示</div>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<el-select
|
||||
v-model="projectId"
|
||||
placeholder="选择项目"
|
||||
style="width: 200px"
|
||||
:loading="projectsLoading"
|
||||
@change="onProjectChange"
|
||||
>
|
||||
<el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" />
|
||||
</el-select>
|
||||
<el-button
|
||||
v-if="canPublish && projectId"
|
||||
type="primary"
|
||||
:icon="Upload"
|
||||
@click="openUploadDialog"
|
||||
>发布新版本</el-button>
|
||||
<el-button :icon="Refresh" circle @click="refresh" :disabled="!projectId" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="isAgent"
|
||||
title="代理账号仅可查看版本列表,不可发布/修改/删除版本"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<el-table
|
||||
:data="list"
|
||||
v-loading="loading"
|
||||
stripe
|
||||
border
|
||||
row-key="id"
|
||||
class="data-table"
|
||||
:max-height="560"
|
||||
>
|
||||
<el-table-column prop="version" label="版本号" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.is_latest == 1" type="success" size="small" style="margin-right:6px">最新</el-tag>
|
||||
<span class="mono-text">{{ row.version }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="file_name" label="文件名" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column label="大小" width="100" align="center">
|
||||
<template #default="{ row }">{{ formatSize(row.file_size) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="download_count" label="下载次数" width="100" align="center" />
|
||||
<el-table-column prop="is_force" label="强制推送" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_force == 1 ? 'danger' : 'info'" size="small">
|
||||
{{ row.is_force == 1 ? '强制' : '普通' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="min_client_version" label="最低版本" width="110" align="center">
|
||||
<template #default="{ row }">{{ row.min_client_version || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status == 1 ? 'success' : 'info'" size="small">
|
||||
{{ row.status == 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="changelog" label="更新说明" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.changelog || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="发布时间" width="170" />
|
||||
<el-table-column label="操作" width="240" fixed="right" align="center">
|
||||
<template #default="{ row }">
|
||||
<template v-if="canPublish">
|
||||
<el-button
|
||||
v-if="row.is_latest != 1"
|
||||
size="small"
|
||||
type="success"
|
||||
link
|
||||
@click="handleSetLatest(row)"
|
||||
>设为最新</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
:type="row.is_force == 1 ? 'info' : 'danger'"
|
||||
link
|
||||
@click="handleToggleForce(row)"
|
||||
>{{ row.is_force == 1 ? '取消强制' : '强制推送' }}</el-button>
|
||||
<el-button size="small" type="primary" link @click="openEditDialog(row)">编辑</el-button>
|
||||
<el-button size="small" type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
<span v-else class="readonly-text">只读</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-empty v-if="!loading && !list.length" description="暂无版本,请先发布安装包" />
|
||||
</el-card>
|
||||
|
||||
<!-- 上传发布弹窗 -->
|
||||
<el-dialog
|
||||
v-model="uploadVisible"
|
||||
title="发布新版本"
|
||||
width="560px"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
@closed="resetUploadForm"
|
||||
>
|
||||
<el-form ref="uploadFormRef" :model="uploadForm" :rules="uploadRules" label-width="110px">
|
||||
<el-form-item label="项目">
|
||||
<el-input :model-value="currentProjectName" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="版本号" prop="version">
|
||||
<el-input v-model="uploadForm.version" placeholder="如 1.2.0" />
|
||||
</el-form-item>
|
||||
<el-form-item label="安装包" prop="file">
|
||||
<el-upload
|
||||
class="package-uploader"
|
||||
drag
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
accept=".zip,.tar,.gz,.tgz,.7z,.exe,.dmg,.apk,.msi,.pkg,.rar,.bin"
|
||||
:on-change="handleFileChange"
|
||||
:on-remove="handleFileRemove"
|
||||
ref="uploadRef"
|
||||
>
|
||||
<el-icon class="el-icon--upload"><UploadFilled /></el-icon>
|
||||
<div class="el-upload__text">拖拽文件到此处,或<em>点击选择</em></div>
|
||||
<template #tip>
|
||||
<div class="el-upload__tip">
|
||||
支持 zip/tar/gz/7z/exe/dmg/apk/msi/pkg/rar/bin,最大 200MB
|
||||
</div>
|
||||
</template>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item label="更新说明">
|
||||
<el-input v-model="uploadForm.changelog" type="textarea" :rows="4" placeholder="本次更新内容" />
|
||||
</el-form-item>
|
||||
<el-form-item label="强制推送">
|
||||
<el-switch v-model="uploadForm.is_force" :active-value="1" :inactive-value="0" />
|
||||
<span class="form-tip">开启后客户端将收到强制更新提示(仅提示,不阻断授权)</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="最低强制版本">
|
||||
<el-input v-model="uploadForm.min_client_version" placeholder="选填,如 1.0.0;低于此版本强制更新" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设为最新">
|
||||
<el-switch v-model="uploadForm.is_latest" :active-value="1" :inactive-value="0" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="uploadVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="uploadLoading" @click="handleUpload">发布</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<el-dialog v-model="editVisible" title="编辑版本" width="480px" :close-on-click-modal="false" destroy-on-close>
|
||||
<el-form :model="editForm" label-width="110px">
|
||||
<el-form-item label="版本号">
|
||||
<el-input :model-value="editForm.version" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="更新说明">
|
||||
<el-input v-model="editForm.changelog" type="textarea" :rows="4" />
|
||||
</el-form-item>
|
||||
<el-form-item label="强制推送">
|
||||
<el-switch v-model="editForm.is_force" :active-value="1" :inactive-value="0" />
|
||||
</el-form-item>
|
||||
<el-form-item label="最低强制版本">
|
||||
<el-input v-model="editForm.min_client_version" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-switch v-model="editForm.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="禁用" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="editVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="editLoading" @click="handleEditSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Upload, Refresh, UploadFilled } from '@element-plus/icons-vue'
|
||||
import request from '@/api'
|
||||
import versionApi from '@/api/versions'
|
||||
|
||||
const route = useRoute()
|
||||
const userStore = useUserStore()
|
||||
const user = computed(() => userStore.user)
|
||||
const isAgent = computed(() => user.value?.role === 'agent')
|
||||
const canPublish = computed(() => ['admin', 'project_admin'].includes(user.value?.role))
|
||||
|
||||
const projects = ref([])
|
||||
const projectsLoading = ref(false)
|
||||
const projectId = ref(route.query.project_id ? Number(route.query.project_id) : null)
|
||||
const list = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
const uploadVisible = ref(false)
|
||||
const uploadLoading = ref(false)
|
||||
const uploadFormRef = ref(null)
|
||||
const uploadRef = ref(null)
|
||||
const uploadFile = ref(null)
|
||||
const uploadForm = ref({
|
||||
version: '',
|
||||
changelog: '',
|
||||
is_force: 0,
|
||||
min_client_version: '',
|
||||
is_latest: 1
|
||||
})
|
||||
const uploadRules = {
|
||||
version: [{ required: true, message: '请输入版本号', trigger: 'blur' }],
|
||||
file: [{ required: true, message: '请选择安装包文件', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const editVisible = ref(false)
|
||||
const editLoading = ref(false)
|
||||
const editForm = ref({ id: null, version: '', changelog: '', is_force: 0, min_client_version: '', status: 1 })
|
||||
|
||||
const currentProjectName = computed(() => {
|
||||
const p = projects.value.find(i => Number(i.id) === Number(projectId.value))
|
||||
return p ? p.name : ''
|
||||
})
|
||||
|
||||
function formatSize(bytes) {
|
||||
const n = Number(bytes || 0)
|
||||
if (!n) return '-'
|
||||
if (n < 1024) return n + ' B'
|
||||
if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB'
|
||||
if (n < 1024 * 1024 * 1024) return (n / 1024 / 1024).toFixed(2) + ' MB'
|
||||
return (n / 1024 / 1024 / 1024).toFixed(2) + ' GB'
|
||||
}
|
||||
|
||||
async function fetchProjects() {
|
||||
projectsLoading.value = true
|
||||
try {
|
||||
const res = await request.get('/projects/all')
|
||||
let data = res.data.list || res.data || []
|
||||
if (!Array.isArray(data)) data = []
|
||||
projects.value = data
|
||||
if (!projectId.value && data.length) {
|
||||
projectId.value = Number(data[0].id)
|
||||
await refresh()
|
||||
}
|
||||
} catch {
|
||||
projects.value = []
|
||||
} finally {
|
||||
projectsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (!projectId.value) {
|
||||
list.value = []
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await versionApi.list(projectId.value)
|
||||
list.value = Array.isArray(res.data) ? res.data : []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
list.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onProjectChange() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
function openUploadDialog() {
|
||||
if (!projectId.value) {
|
||||
ElMessage.warning('请先选择项目')
|
||||
return
|
||||
}
|
||||
uploadVisible.value = true
|
||||
}
|
||||
|
||||
function resetUploadForm() {
|
||||
uploadForm.value = { version: '', changelog: '', is_force: 0, min_client_version: '', is_latest: 1 }
|
||||
uploadFile.value = null
|
||||
if (uploadRef.value) uploadRef.value.clearFiles()
|
||||
}
|
||||
|
||||
function handleFileChange(file) {
|
||||
uploadFile.value = file.raw
|
||||
uploadForm.value.file = file.raw
|
||||
}
|
||||
|
||||
function handleFileRemove() {
|
||||
uploadFile.value = null
|
||||
uploadForm.value.file = null
|
||||
}
|
||||
|
||||
async function handleUpload() {
|
||||
if (!uploadFormRef.value) return
|
||||
await uploadFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
if (!uploadFile.value) {
|
||||
ElMessage.warning('请选择安装包文件')
|
||||
return
|
||||
}
|
||||
uploadLoading.value = true
|
||||
try {
|
||||
const fd = new FormData()
|
||||
fd.append('version', uploadForm.value.version)
|
||||
fd.append('file', uploadFile.value)
|
||||
fd.append('changelog', uploadForm.value.changelog || '')
|
||||
fd.append('is_force', uploadForm.value.is_force)
|
||||
fd.append('min_client_version', uploadForm.value.min_client_version || '')
|
||||
fd.append('is_latest', uploadForm.value.is_latest)
|
||||
await versionApi.create(projectId.value, fd)
|
||||
ElMessage.success('版本发布成功')
|
||||
uploadVisible.value = false
|
||||
refresh()
|
||||
} catch {} finally {
|
||||
uploadLoading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function openEditDialog(row) {
|
||||
editForm.value = {
|
||||
id: row.id,
|
||||
version: row.version,
|
||||
changelog: row.changelog || '',
|
||||
is_force: Number(row.is_force) || 0,
|
||||
min_client_version: row.min_client_version || '',
|
||||
status: Number(row.status) || 1
|
||||
}
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
async function handleEditSubmit() {
|
||||
editLoading.value = true
|
||||
try {
|
||||
await versionApi.update(editForm.value.id, {
|
||||
changelog: editForm.value.changelog,
|
||||
is_force: editForm.value.is_force,
|
||||
min_client_version: editForm.value.min_client_version,
|
||||
status: editForm.value.status
|
||||
})
|
||||
ElMessage.success('更新成功')
|
||||
editVisible.value = false
|
||||
refresh()
|
||||
} catch {} finally {
|
||||
editLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggleForce(row) {
|
||||
try {
|
||||
const next = Number(row.is_force) === 1 ? 0 : 1
|
||||
const tip = next === 1
|
||||
? '确定对该版本开启强制推送?客户端将收到强制更新提示。'
|
||||
: '确定取消该版本的强制推送?'
|
||||
await ElMessageBox.confirm(tip, '提示', { type: 'warning' })
|
||||
await versionApi.toggleForce(row.id, next)
|
||||
ElMessage.success(next === 1 ? '已开启强制推送' : '已取消强制推送')
|
||||
refresh()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function handleSetLatest(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定将 ${row.version} 设为最新版本并推送?`, '提示', { type: 'warning' })
|
||||
await versionApi.setLatest(row.id)
|
||||
ElMessage.success('已设为最新版本')
|
||||
refresh()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function handleDelete(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除版本 ${row.version}?将同时删除安装包文件。`, '提示', { type: 'warning' })
|
||||
await versionApi.remove(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
refresh()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchProjects()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.versions-page { max-width: 1600px; margin: 0 auto; }
|
||||
.main-card { border-radius: 16px; border: 1px solid #f0f0f4; }
|
||||
.main-card:deep(.el-card__body) { padding: 24px; }
|
||||
.page-header {
|
||||
display: flex; justify-content: space-between; align-items: flex-start;
|
||||
margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
|
||||
}
|
||||
.page-title { font-size: 18px; font-weight: 700; color: #1d1d1f; }
|
||||
.page-sub { font-size: 13px; color: #9ca3af; margin-top: 4px; }
|
||||
.header-actions { display: flex; gap: 10px; align-items: center; }
|
||||
.header-actions :deep(.el-button) { border-radius: 10px; font-weight: 500; }
|
||||
.data-table { border-radius: 12px; overflow: hidden; }
|
||||
.data-table:deep(.el-table__header th) { background: #f8f9fb; font-weight: 600; color: #374151; font-size: 13px; border-color: #f0f0f4; }
|
||||
.data-table:deep(.el-table__body td) { font-size: 13px; color: #374151; border-color: #f5f5f7; }
|
||||
.mono-text { font-family: 'SF Mono', Cascadia Code, Courier New, monospace; font-size: 13px; }
|
||||
.form-tip { margin-left: 10px; font-size: 12px; color: #9ca3af; }
|
||||
.readonly-text { color: #9ca3af; font-size: 12px; }
|
||||
.package-uploader { width: 100%; }
|
||||
.package-uploader:deep(.el-upload-dragger) { border-radius: 12px; }
|
||||
@media (max-width: 768px) {
|
||||
.main-card:deep(.el-card__body) { padding: 14px; }
|
||||
.header-actions { width: 100%; flex-wrap: wrap; }
|
||||
}
|
||||
</style>
|
||||
@@ -59,10 +59,12 @@
|
||||
<el-table-column prop="api_key" label="API Key" min-width="220" show-overflow-tooltip v-if="visibleColumns.api_key"><template #default="{ row }"><div class="key-cell"><span class="mono-text">{{ row.api_key }}</span><el-icon class="copy-icon" @click="copyToClipboard(row.api_key)" title="复制"><DocumentCopy /></el-icon></div></template></el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="100" align="center" sortable="custom" v-if="visibleColumns.status"><template #default="{ row }"><el-switch v-model="row.status" :active-value="1" :inactive-value="0" @change="handleStatusChange(row)" :disabled="!canManage" /></template></el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180" sortable="custom" v-if="visibleColumns.created_at" />
|
||||
<el-table-column label="操作" width="260" fixed="right" align="center" v-if="canManage">
|
||||
<el-table-column label="操作" width="320" fixed="right" align="center" v-if="canManage">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" type="primary" link :icon="Edit" @click="showEditDialog(row)">编辑</el-button>
|
||||
<el-button size="small" type="warning" link @click="showCardTypeDialog(row)">套餐</el-button>
|
||||
<el-button size="small" type="success" link @click="goInstallations(row)">安装统计</el-button>
|
||||
<el-button size="small" type="info" link @click="goVersions(row)">版本管理</el-button>
|
||||
<el-button size="small" link @click="handleRegenerateKey(row)">重置Key</el-button>
|
||||
<el-button size="small" type="danger" link :icon="Delete" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
@@ -113,6 +115,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useList } from '@/composables/useList'
|
||||
@@ -120,6 +123,7 @@ import { useColumnSettings } from '@/composables/useColumnSettings'
|
||||
import { Plus, Delete, Download, Search, Refresh, Filter, Setting, Edit, ArrowDown, FolderOpened, CircleCheck, CircleClose, DocumentCopy } from '@element-plus/icons-vue'
|
||||
import request from '@/api'
|
||||
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const user = computed(() => userStore.user)
|
||||
const canManage = computed(() => ['admin', 'project_admin'].includes(user.value?.role))
|
||||
@@ -198,6 +202,8 @@ function handleExport(format) {
|
||||
ElMessage.success('导出任务已启动')
|
||||
}
|
||||
function copyToClipboard(text) { navigator.clipboard.writeText(text).then(() => ElMessage.success('已复制')).catch(() => ElMessage.error('复制失败')) }
|
||||
function goInstallations(row) { router.push({ path: '/installations', query: { project_id: row.id } }) }
|
||||
function goVersions(row) { router.push({ path: '/project-versions', query: { project_id: row.id } }) }
|
||||
|
||||
// 套餐管理
|
||||
const typeDialogVisible = ref(false)
|
||||
|
||||
@@ -63,6 +63,14 @@
|
||||
<el-icon><Lock /></el-icon>
|
||||
<span>授权管理</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/installations">
|
||||
<el-icon><Download /></el-icon>
|
||||
<span>安装统计</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/project-versions" v-if="canManage || isAgent">
|
||||
<el-icon><Upload /></el-icon>
|
||||
<span>版本推送</span>
|
||||
</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 代理业务 -->
|
||||
@@ -79,6 +87,14 @@
|
||||
<el-icon><Lock /></el-icon>
|
||||
<span>授权管理</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/installations">
|
||||
<el-icon><Download /></el-icon>
|
||||
<span>安装统计</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/project-versions">
|
||||
<el-icon><Upload /></el-icon>
|
||||
<span>版本推送</span>
|
||||
</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 订单与代理 -->
|
||||
@@ -459,6 +475,8 @@ const parentMap = {
|
||||
'/products': [{ path: '/dashboard', title: '业务管理' }],
|
||||
'/cards': [{ path: '/dashboard', title: '业务管理' }],
|
||||
'/authorizations': [{ path: '/dashboard', title: '业务管理' }],
|
||||
'/installations': [{ path: '/dashboard', title: '业务管理' }],
|
||||
'/project-versions': [{ path: '/dashboard', title: '业务管理' }],
|
||||
'/orders': [{ path: '/dashboard', title: '订单与代理' }],
|
||||
'/coupons': [{ path: '/dashboard', title: '订单与代理' }],
|
||||
'/blacklist': [{ path: '/dashboard', title: '订单与代理' }],
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
<template>
|
||||
<div class="docs-app">
|
||||
<div class="bg-canvas">
|
||||
<div class="bg-grid"></div>
|
||||
<div class="bg-orb orb-a"></div>
|
||||
<div class="bg-orb orb-b"></div>
|
||||
<div class="bg-orb orb-c"></div>
|
||||
</div>
|
||||
|
||||
<header class="top-bar">
|
||||
<div class="top-brand">
|
||||
<svg viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>
|
||||
<div class="top-brand-text">
|
||||
<span class="top-name">CardAuth</span>
|
||||
<span class="top-sub">卡密授权管理系统</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="top-actions">
|
||||
<router-link to="/shop" class="top-btn btn-primary">进入购买中心</router-link>
|
||||
<router-link to="/login" class="top-btn btn-ghost">管理登录</router-link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="docs-wrap">
|
||||
<div class="docs-hero">
|
||||
<h1 class="hero-title">CardAuth 授权管理系统</h1>
|
||||
<p class="hero-desc">轻量级<b>卡密(激活码)+ 机器授权</b>解决方案 · 多项目管理 · 代理分销 · 在线支付 · API 对接</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-grid">
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><span>系统介绍</span></div>
|
||||
<p>CardAuth 是一套轻量级的<b>卡密(激活码)+ 机器授权管理系统</b>,提供多项目管理、卡密生成与分销、代理体系、在线支付购买及授权验证 API。适用于软件授权、机器人授权等场景。</p>
|
||||
<ul>
|
||||
<li><b>多项目</b>:每个项目拥有独立商品、API Key 与卡密池</li>
|
||||
<li><b>卡密</b>:支持批量生成、按天/月/年设定期限、导入导出</li>
|
||||
<li><b>代理/分销</b>:代理充值额度、以折扣价采购并分发卡密</li>
|
||||
<li><b>在线支付</b>:内置易支付对接,用户可直接付款购买</li>
|
||||
<li><b>授权验证</b>:REST API 实时校验卡密与机器码绑定状态</li>
|
||||
<li><b>安装统计</b>:记录安装次数、存活/已删除、最后上线时间</li>
|
||||
<li><b>版本推送</b>:上传安装包并推送客户端下载,支持强制更新提示</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><span>购买与激活流程</span></div>
|
||||
<ol>
|
||||
<li><b>购买授权</b>:在<b>购买中心</b>选择项目与商品,支付宝/微信付款后系统即时发放卡密</li>
|
||||
<li><b>在线授权</b>:在购买中心「在线授权」中输入卡密与机器码,完成绑定</li>
|
||||
<li><b>授权查询</b>:按卡密或机器码查询绑定状态与到期时间</li>
|
||||
<li><b>续期</b>:对已绑定的机器人再次使用卡密授权,自动延长有效期</li>
|
||||
</ol>
|
||||
<p class="docs-tip">卡密未使用前不限期有效;一旦绑定,有效期自激活时开始计算。请妥善保管卡密,谨防泄露。</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><span>安装统计与版本推送</span></div>
|
||||
<p>系统支持统计项目被安装次数、区分存活/已删除、记录最后上线时间,并可向客户端推送最新安装包(支持强制更新提示)。</p>
|
||||
<ul>
|
||||
<li><b>安装统计</b>:每次安装独立计数(含已删除);同机器删除后重装会再次计入</li>
|
||||
<li><b>存活 / 已删除</b>:后台可软删除安装记录,也可恢复;统计口径含已删除</li>
|
||||
<li><b>最后上线</b>:客户端 verify / check-update / heartbeat 成功时自动更新</li>
|
||||
<li><b>版本推送</b>:上传安装包后,客户端检查更新即可获得下载地址与更新说明</li>
|
||||
<li><b>强制推送</b>:开启后返回强制更新提示(仅提示下载,不阻断授权)</li>
|
||||
</ul>
|
||||
<h4 class="docs-sub">后台使用方法</h4>
|
||||
<ol>
|
||||
<li>进入管理后台 → <b>业务管理 → 安装统计</b>:查看总安装、存活、已删除、最后上线、分项目明细</li>
|
||||
<li>进入 <b>业务管理 → 版本推送</b>(或项目管理行内「版本管理」)</li>
|
||||
<li>选择项目 → <b>发布新版本</b>:填写版本号、上传安装包、更新说明</li>
|
||||
<li>可选:<b>强制推送</b>(客户端弹强制更新)、<b>最低强制版本</b>(低于此版本强制更新)</li>
|
||||
<li>发布后客户端调用 check-update 即可收到下载提示;可随时「设为最新」「取消强制」「删除版本」</li>
|
||||
</ol>
|
||||
<p class="doc-note">权限:超级管理员/项目管理员可发布与修改版本;代理仅可查看安装统计与版本列表,不可发布。</p>
|
||||
<p class="docs-tip">强制推送仅影响客户端更新提示,不会让旧版本卡密验证失败。若需彻底停用旧版本,请在卡密/授权侧处理。</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-card docs-card-wide">
|
||||
<div class="docs-card-head"><span>开发者对接(API)</span></div>
|
||||
|
||||
<h4 class="docs-sub">1. 鉴权方式</h4>
|
||||
<div class="docs-table-wrap">
|
||||
<table class="docs-table">
|
||||
<thead><tr><th>类型</th><th>说明</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>公开接口</td><td>无需认证:商品浏览、订单创建/查询、QQ授权查询与验证</td></tr>
|
||||
<tr><td>API Key</td><td>项目密钥,用于机器码授权验证接口,请求头 <code>X-Api-Key</code>(管理员在「项目管理」中获取)</td></tr>
|
||||
<tr><td>JWT Token</td><td>后台/代理站点使用,请求头 <code>Authorization: Bearer <token></code>,有效期 24 小时</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="doc-note">所有接口需携带 <code>Content-Type: application/json</code>;统一响应结构 <code>{ "code": 200, "message": "操作成功", "data": {...} }</code>。</p>
|
||||
|
||||
<h4 class="docs-sub">2. 机器码授权验证(核心接口)</h4>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">POST /api/public/verify <span>Header: X-Api-Key: 项目APIKey</span></div>
|
||||
<pre>{
|
||||
"card_key": "CA-XXXX-XXXX", // 必填:卡密
|
||||
"machine_id": "UNIQUE-DEVICE-FP", // 必填:机器指纹(首次调用即绑定)
|
||||
"ip": "客户端IP", // 选填:默认取请求来源IP
|
||||
"device_info": "设备描述信息", // 选填:留作记录
|
||||
"client_version": "1.0.0" // 选填:客户端版本,用于更新提示
|
||||
}</pre>
|
||||
</div>
|
||||
<div class="docs-table-wrap">
|
||||
<table class="docs-table">
|
||||
<thead><tr><th>场景</th><th>响应 data</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>首次激活(卡密未使用)</td><td><code>valid:true, message:"激活成功", type, duration_days, expire_time, is_permanent</code>,绑定机器指纹并开始计时;同时登记安装记录并附带更新字段</td></tr>
|
||||
<tr><td>已激活 · 同一机器</td><td><code>valid:true, message:"授权有效", expire_time, bound_at, remaining_days</code>;更新安装 last_online_at 并附带更新字段</td></tr>
|
||||
<tr><td>已激活 · 换机器</td><td><code>valid:false, message:"设备不匹配,请使用绑定的设备"</code></td></tr>
|
||||
<tr><td>授权已过期</td><td><code>valid:false, message:"授权已过期"</code></td></tr>
|
||||
<tr><td>卡密不存在 / 已禁用</td><td><code>valid:false, message:"卡密不存在" / "卡密已被禁用"</code></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="doc-note"><b>注:</b><code>duration_days=0</code> 表示永久卡,<code>expire_time</code> 为空且 <code>is_permanent=true</code>。verify 成功时还会附带更新提示字段(见下节),便于客户端弹窗下载最新安装包。</p>
|
||||
|
||||
<h4 class="docs-sub">3. 安装上报 / 检查更新(客户端)</h4>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">POST /api/public/installations/check-update <span>Header: X-Api-Key: 项目APIKey</span></div>
|
||||
<pre>{
|
||||
"machine_id": "UNIQUE-DEVICE-FP", // 必填:机器指纹
|
||||
"client_version": "1.0.0", // 选填:当前版本,用于对比是否需要更新
|
||||
"card_key": "CA-XXXX-XXXX", // 选填:关联卡密,便于统计归属
|
||||
"device_info": "Windows 11" // 选填
|
||||
}</pre>
|
||||
</div>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">响应示例</div>
|
||||
<pre>{
|
||||
"code": 200,
|
||||
"data": {
|
||||
"update_available": true, // 是否有新版本
|
||||
"update_required": true, // 是否强制更新(仅提示,不阻断授权)
|
||||
"current_version": "1.0.0",
|
||||
"latest_version": "1.2.0",
|
||||
"version": "1.2.0",
|
||||
"download_url": "/uploads/packages/1/pkg_xxx.zip",
|
||||
"file_size": 10485760,
|
||||
"checksum": "sha256...",
|
||||
"changelog": "本次更新说明",
|
||||
"min_client_version": "1.1.0", // 低于此版本强制更新
|
||||
"is_force": 1,
|
||||
"install_id": 123
|
||||
}
|
||||
}</pre>
|
||||
</div>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">POST /api/public/installations/heartbeat <span>仅更新在线时间</span></div>
|
||||
<pre>{
|
||||
"machine_id": "UNIQUE-DEVICE-FP",
|
||||
"client_version": "1.0.0",
|
||||
"card_key": "CA-XXXX-XXXX" // 选填
|
||||
}
|
||||
响应 data: { "install_id": 123 }</pre>
|
||||
</div>
|
||||
<p><b>客户端接入建议:</b></p>
|
||||
<ul>
|
||||
<li>启动/周期心跳时调用 <code>check-update</code>,同时完成安装登记与在线上报</li>
|
||||
<li><code>update_available=true</code> 且 <code>update_required=false</code> → 弹出「发现新版本,是否下载?」</li>
|
||||
<li><code>update_required=true</code> → 强制更新提示(不可关闭),引导下载 <code>download_url</code></li>
|
||||
<li>授权 <code>verify</code> 成功时也会返回相同更新字段,并自动刷新 last_online_at</li>
|
||||
</ul>
|
||||
|
||||
<h4 class="docs-sub">4. 后台安装/版本管理接口(JWT)</h4>
|
||||
<div class="docs-table-wrap">
|
||||
<table class="docs-table">
|
||||
<thead><tr><th>方法</th><th>路径</th><th>说明</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>GET</td><td><code>/api/installations</code></td><td>安装列表(可筛项目/状态/关键字/日期)</td></tr>
|
||||
<tr><td>GET</td><td><code>/api/installations/stats</code></td><td>统计:总安装(含已删除)、存活、已删除、今日新增、最后上线、分项目</td></tr>
|
||||
<tr><td>DELETE</td><td><code>/api/installations/{id}</code></td><td>标记已删除(软删除)</td></tr>
|
||||
<tr><td>POST</td><td><code>/api/installations/{id}/restore</code></td><td>恢复为存活</td></tr>
|
||||
<tr><td>GET</td><td><code>/api/projects/{projectId}/versions</code></td><td>版本列表(代理只读)</td></tr>
|
||||
<tr><td>POST</td><td><code>/api/projects/{projectId}/versions</code></td><td>上传发布版本(multipart)</td></tr>
|
||||
<tr><td>PUT</td><td><code>/api/versions/{id}/force</code></td><td>强制推送开关</td></tr>
|
||||
<tr><td>PUT</td><td><code>/api/versions/{id}/latest</code></td><td>设为最新版本</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="doc-note">发布版本需 <code>multipart/form-data</code>:字段 <code>version</code>、<code>file</code>、可选 <code>changelog</code>、<code>is_force</code>、<code>min_client_version</code>、<code>is_latest</code>。支持 zip/tar/gz/7z/exe/dmg/apk/msi/pkg/rar/bin,单文件最大 200MB。</p>
|
||||
|
||||
<h4 class="docs-sub">5. QQ 授权验证(机器人场景)</h4>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">POST /api/public/authorizations/verify</div>
|
||||
<pre>{
|
||||
"bot_qq": "123456789", // 必填:机器码
|
||||
"card_key": "CA-XXXX-XXXX", // 选填:限定卡密校验
|
||||
"contact_qq": "987654321" // 选填:联系人QQ
|
||||
}</pre>
|
||||
</div>
|
||||
<p>响应 <code>data</code>:<code>valid</code>、<code>has_valid_auth</code>、<code>bot_qq</code>、<code>contact_qq</code>、<code>card_key</code>、<code>project_name</code>、<code>expire_time</code>、<code>days_left</code>、<code>message</code>。</p>
|
||||
|
||||
<h4 class="docs-sub">6. QQ 授权状态查询</h4>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">GET /api/public/authorizations/query?bot_qq=123456789</div>
|
||||
<pre>{
|
||||
"code": 200,
|
||||
"data": {
|
||||
"bot_qq": "123456789",
|
||||
"total": 2, "active_count": 1, "expired_count": 1, "revoked_count": 0,
|
||||
"has_valid_auth": true,
|
||||
"list": [
|
||||
{ "card_key": "CA-XXXX-XXXX", "project_name": "演示项目",
|
||||
"duration_days": 30, "status": "active",
|
||||
"authorized_at": "2026-01-01 12:00:00",
|
||||
"expire_time": "2026-01-31 12:00:00", "is_expired": false }
|
||||
]
|
||||
}
|
||||
}</pre>
|
||||
</div>
|
||||
|
||||
<h4 class="docs-sub">7. 商城公共接口</h4>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">GET /api/public/projects — 项目与商品列表</div>
|
||||
<pre>GET /api/public/projects/{project_id}/card-types — 项目套餐
|
||||
|
||||
POST /api/public/orders — 创建订单(在服务器内支付,返回支付链接)
|
||||
{
|
||||
"project_id": 1, "card_type_id": 1,
|
||||
"amount": 29.90, "pay_type": "wxpay", // wxpay | alipay | qqpay
|
||||
"contact_qq": "987654321", "bot_qq": "123456789",
|
||||
"coupon_code": "" // 选填:优惠码
|
||||
}
|
||||
响应 data: { "order_no":"2026062317530410859", "pay_url":"https://…", "is_renew":false }
|
||||
|
||||
GET /api/public/orders/query?order_no=2026062317530410859 — 订单查询
|
||||
GET /api/public/cards/query?card_key=CA-XXXX — 卡密查询</pre>
|
||||
</div>
|
||||
|
||||
<h4 class="docs-sub">8. 调用示例(CURL)</h4>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">curl · 授权验证</div>
|
||||
<pre>curl -X POST https://你的域名/api/public/verify \
|
||||
-H "X-Api-Key: 你的项目APIKey" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"card_key":"CA-XXXX-XXXX","machine_id":"FP-001","client_version":"1.0.0"}'</pre>
|
||||
</div>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">curl · 检查更新 / 心跳</div>
|
||||
<pre>curl -X POST https://你的域名/api/public/installations/check-update \
|
||||
-H "X-Api-Key: 你的项目APIKey" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"machine_id":"FP-001","client_version":"1.0.0"}'
|
||||
|
||||
curl -X POST https://你的域名/api/public/installations/heartbeat \
|
||||
-H "X-Api-Key: 你的项目APIKey" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"machine_id":"FP-001","client_version":"1.0.0"}'</pre>
|
||||
</div>
|
||||
|
||||
<h4 class="docs-sub">9. 频率限制</h4>
|
||||
<p>公开接口默认限流:QQ 授权验证等公共接口每 <b>60 秒 30 次</b>;机器码授权验证与安装上报每 <b>60 秒 60 次</b>。超出后返回 <code>429</code>,请控制调用频率并缓存验证结果(建议客户端每 10 分钟校验一次)。</p>
|
||||
<p class="doc-note"><b>对接建议:</b>软件启动时调用 verify 或 check-update;将 remaining_days / update_available 缓存本地并在需要时提示续费或更新;付款回调由系统处理,客户端只需轮询 orders/query。</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><span>常见问题</span></div>
|
||||
<ul>
|
||||
<li><b>付款后没有收到卡密?</b>在购买中心用订单号查询;超过 15 分钟未支付订单自动作废。</li>
|
||||
<li><b>卡密提示已被使用?</b>卡密一次性绑定,若需更换设备请联系管理员重置绑定。</li>
|
||||
<li><b>支持退款吗?</b>卡密一经绑定激活不支持退款,购买前请确认商品信息。</li>
|
||||
<li><b>忘记绑定的机器码?</b>用卡密在「授权查询」中即可反查。</li>
|
||||
<li><b>客户端一直不提示更新?</b>请确认管理端已发布版本且状态启用;并传入 <code>client_version</code>;检查项目 API Key 是否正确。</li>
|
||||
<li><b>强制更新会拦住旧用户吗?</b>不会阻断授权,仅在客户端弹出强制更新提示;是否升级由客户端 UI 实现决定。</li>
|
||||
<li><b>如何成为代理?</b>通过 <router-link to="/agent/login" class="docs-link">代理登录入口</router-link> 注册,审核通过后可在额度内采购卡密。</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="docs-cta">
|
||||
<router-link to="/shop" class="cta-btn">立即购买 / 查看商品</router-link>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="docs-footer">
|
||||
<span>© {{ year }} CardAuth · 轻量级卡密授权管理系统</span>
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const year = new Date().getFullYear()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.docs-app {
|
||||
position: relative; min-height: 100vh; overflow-x: hidden;
|
||||
background: linear-gradient(135deg, #f5f7fc 0%, #eef1fb 45%, #f8f5ff 100%);
|
||||
}
|
||||
.bg-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
|
||||
.bg-grid {
|
||||
position: absolute; inset: 0; opacity: .5;
|
||||
background-image: linear-gradient(rgba(115,103,240,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(115,103,240,.05) 1px, transparent 1px);
|
||||
background-size: 42px 42px;
|
||||
}
|
||||
.bg-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .35; }
|
||||
.orb-a { width: 420px; height: 420px; background: #a78bfa; top: -120px; right: -80px; }
|
||||
.orb-b { width: 360px; height: 360px; background: #60a5fa; bottom: -100px; left: -100px; }
|
||||
.orb-c { width: 260px; height: 260px; background: #f0abfc; bottom: 30%; right: 25%; opacity: .2; }
|
||||
|
||||
/* 顶部栏 */
|
||||
.top-bar {
|
||||
position: relative; z-index: 2;
|
||||
max-width: 1100px; margin: 0 auto;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 20px 24px; flex-wrap: wrap; gap: 12px;
|
||||
}
|
||||
.top-brand { display: flex; align-items: center; gap: 10px; color: #7367f0; }
|
||||
.top-brand-text { display: flex; flex-direction: column; line-height: 1.3; }
|
||||
.top-name { font-size: 18px; font-weight: 800; color: #333; letter-spacing: .4px; }
|
||||
.top-sub { font-size: 12px; color: #8b93a7; }
|
||||
.top-actions { display: flex; gap: 10px; }
|
||||
.top-btn {
|
||||
display: inline-block; padding: 9px 18px; border-radius: 999px;
|
||||
font-size: 14px; font-weight: 600; text-decoration: none; transition: all .2s;
|
||||
}
|
||||
.btn-primary { background: linear-gradient(135deg, #7367f0, #9d67ff); color: #fff; box-shadow: 0 4px 14px rgba(115,103,240,.35); }
|
||||
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(115,103,240,.45); }
|
||||
.btn-ghost { border: 1px solid rgba(115,103,240,.4); color: #6758e8; background: #fff; }
|
||||
.btn-ghost:hover { background: rgba(115,103,240,.08); }
|
||||
|
||||
/* 文档主体 */
|
||||
.docs-wrap { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 18px 24px 40px; }
|
||||
.docs-hero { text-align: center; padding: 26px 0 30px; }
|
||||
.hero-title { font-size: 34px; font-weight: 800; margin: 0 0 12px; color: #2d2b45; letter-spacing: 1px; }
|
||||
.hero-desc { font-size: 15px; color: #5f6580; margin: 0; }
|
||||
.hero-desc b { color: #6758e8; }
|
||||
|
||||
.docs-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
|
||||
.docs-card {
|
||||
background: rgba(255,255,255,.78);
|
||||
backdrop-filter: blur(14px);
|
||||
border: 1px solid rgba(255,255,255,.8);
|
||||
border-radius: 18px;
|
||||
padding: 22px 24px;
|
||||
box-shadow: 0 8px 30px rgba(102,126,234,.10);
|
||||
color: #333; font-size: 14px; line-height: 1.85;
|
||||
}
|
||||
.docs-card-head { font-size: 16px; font-weight: 700; color: #333; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
|
||||
.docs-card-head::before { content: ''; width: 4px; height: 18px; border-radius: 3px; background: linear-gradient(#7367f0, #9d67ff); }
|
||||
.docs-card-head span { font-weight: 400; color: #8b93a7; font-size: 12px; }
|
||||
.docs-card-wide { grid-column: 1 / -1; }
|
||||
.docs-sub { margin: 18px 0 8px; font-size: 14.5px; color: #4c40b8; }
|
||||
.docs-code-title span { color: #6ee7b7; font-size: 11px; font-weight: 500; }
|
||||
.docs-table-wrap { overflow-x: auto; margin: 8px 0; }
|
||||
.docs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
||||
.docs-table th,.docs-table td { border: 1px solid rgba(115,103,240,.18); padding: 7px 10px; text-align: left; }
|
||||
.docs-table th { background: rgba(115,103,240,.08); color: #4c40b8; }
|
||||
.doc-note { font-size: 12.5px; color: #8b93a7; }
|
||||
.docs-link { color: #6758e8; }
|
||||
.docs-card b { color: #4c40b8; }
|
||||
.docs-card ul, .docs-card ol { padding-left: 20px; margin: 8px 0; }
|
||||
.docs-card li { margin: 4px 0; }
|
||||
.docs-card code {
|
||||
background: rgba(115,103,240,.10); color: #5b4fd0;
|
||||
padding: 1px 6px; border-radius: 6px; font-size: 12.5px;
|
||||
font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
|
||||
}
|
||||
.docs-tip {
|
||||
margin-top: 10px; padding: 10px 12px;
|
||||
background: rgba(255,183,77,.14); border-left: 3px solid #f5b04c;
|
||||
border-radius: 8px; font-size: 13px; color: #8a5a1f;
|
||||
}
|
||||
.docs-code {
|
||||
background: #2d2b45; color: #e6e6f0; border-radius: 12px;
|
||||
padding: 14px 16px; margin: 10px 0; overflow-x: auto;
|
||||
font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12.5px; line-height: 1.7;
|
||||
}
|
||||
.docs-code-title { color: #9d94ff; font-weight: 600; margin-bottom: 6px; font-size: 12px; letter-spacing: .4px; }
|
||||
.docs-code pre { margin: 0; white-space: pre-wrap; }
|
||||
|
||||
.docs-cta { text-align: center; padding: 30px 0 10px; }
|
||||
.cta-btn {
|
||||
display: inline-block; padding: 13px 44px; border-radius: 999px;
|
||||
background: linear-gradient(135deg, #7367f0, #9d67ff); color: #fff;
|
||||
font-size: 15px; font-weight: 700; text-decoration: none;
|
||||
box-shadow: 0 6px 20px rgba(115,103,240,.4); transition: transform .2s;
|
||||
}
|
||||
.cta-btn:hover { transform: translateY(-2px) scale(1.02); }
|
||||
|
||||
.docs-footer { position: relative; z-index: 1; text-align: center; padding: 20px; color: #9aa0b5; font-size: 12.5px; }
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.docs-grid { grid-template-columns: 1fr; }
|
||||
.hero-title { font-size: 26px; }
|
||||
}
|
||||
</style>
|
||||
@@ -1,4 +1,4 @@
|
||||
<template>
|
||||
<template>
|
||||
<div class="shop-app">
|
||||
<!-- ========== 全屏 Loading ========== -->
|
||||
<transition name="loader-fade">
|
||||
@@ -167,7 +167,7 @@
|
||||
<input v-model="activateForm.card_key" class="form-input" placeholder="请输入卡密" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>机器人QQ <em>*</em></label>
|
||||
<label>机器码 <em>*</em></label>
|
||||
<input v-model="activateForm.bot_qq" class="form-input" placeholder="5-15位数字" maxlength="15" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
@@ -212,17 +212,17 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 机器人QQ查询 -->
|
||||
<!-- 机器码查询 -->
|
||||
<div v-else-if="queryTab === 'bot'" key="bot" class="center-card">
|
||||
<div class="center-icon icon-orange">
|
||||
<svg viewBox="0 0 24 24" width="32" height="32" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
|
||||
</div>
|
||||
<h2 class="center-title">授权查询</h2>
|
||||
<p class="center-desc">按机器人QQ号查询授权绑定状态</p>
|
||||
<p class="center-desc">按机器码号查询授权绑定状态</p>
|
||||
|
||||
<div class="form-field">
|
||||
<label>机器人QQ</label>
|
||||
<input v-model="queryBotQq" class="form-input" placeholder="请输入机器人QQ号" @keyup.enter="handleQueryBot" :disabled="loading.authQuery" />
|
||||
<label>机器码</label>
|
||||
<input v-model="queryBotQq" class="form-input" placeholder="请输入机器码号" @keyup.enter="handleQueryBot" :disabled="loading.authQuery" />
|
||||
</div>
|
||||
<button class="btn-submit btn-warn full" :disabled="!queryBotQq.trim() || loading.authQuery" @click="handleQueryBot" type="button">
|
||||
<span v-if="loading.authQuery" class="spinner"></span><span v-else>查询授权</span>
|
||||
@@ -230,6 +230,82 @@
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
|
||||
<!-- ===== 4. 使用文档 ===== -->
|
||||
<div v-else-if="activeTab === 'docs'" class="docs-wrap">
|
||||
<div class="docs-hero">
|
||||
<h2 class="center-title">CardAuth 使用文档</h2>
|
||||
<p class="center-desc">了解系统功能、购买流程与 API 对接方式</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-grid">
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><IconQuery /><span>系统介绍</span></div>
|
||||
<p>CardAuth 是一套轻量级的<b>卡密(激活码)+ 机器授权管理系统</b>,提供多项目管理、卡密生成与分销、代理体系、在线支付购买及授权验证 API。适用于软件授权、机器人授权等场景。</p>
|
||||
<ul>
|
||||
<li><b>多项目</b>:每个项目拥有独立商品、API Key 与卡密池</li>
|
||||
<li><b>卡密</b>:支持批量生成、按天/月/年设定期限、导入导出</li>
|
||||
<li><b>代理/分销</b>:代理充值额度、以折扣价采购并分发卡密</li>
|
||||
<li><b>在线支付</b>:内置易支付对接,用户可直接付款购买</li>
|
||||
<li><b>授权验证</b>:REST API 实时校验卡密与机器码绑定状态</li>
|
||||
<li><b>安装统计</b>:安装次数、存活/已删除、最后上线时间</li>
|
||||
<li><b>版本推送</b>:推送最新安装包下载,支持强制更新提示</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><IconBuy /><span>购买与激活流程</span></div>
|
||||
<ol>
|
||||
<li><b>购买授权</b>:在本页「购买授权」中选择项目与商品,通过支付宝/微信完成付款,系统即时发放卡密</li>
|
||||
<li><b>在线授权</b>:在「在线授权」中输入卡密与机器码,完成卡密绑定</li>
|
||||
<li><b>授权查询</b>:在「授权查询」中可按卡密或机器码查询绑定状态与到期时间</li>
|
||||
<li><b>续期</b>:对已绑定的机器人再次使用卡密授权,即自动延长有效期</li>
|
||||
</ol>
|
||||
<p class="docs-tip">卡密未使用前不限期有效;一旦绑定,有效期自激活时开始计算。请妥善保管卡密,谨防泄露。</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-card docs-card-wide">
|
||||
<div class="docs-card-head"><IconDoc /><span>开发者对接(API)— 详细文档详见 <a href="#/docs" style="color:#6758e8">系统介绍页</a></span></div>
|
||||
<p>统一响应 <code>{"code":200,"message":"…","data":{…}}</code>;公开接口无需认证,机器码验证需请求头 <code>X-Api-Key: 项目APIKey</code>(「项目管理」中获取)。</p>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">POST /api/public/verify 机器码授权验证</div>
|
||||
<pre>Header: X-Api-Key: <项目APIKey>
|
||||
{ "card_key": "CA-XXXX-XXXX", // 必填
|
||||
"machine_id": "UNIQUE-DEVICE-FP", // 必填:首次调用即绑定
|
||||
"ip": "客户端IP", "device_info": "…" } // 选填</pre>
|
||||
</div>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">响应场景</div>
|
||||
<pre>首次激活 → valid:true, message:"激活成功", expire_time, is_permanent
|
||||
同机校验 → valid:true, message:"授权有效", remaining_days
|
||||
换机校验 → valid:false, message:"设备不匹配,请使用绑定的设备"
|
||||
已过期 → valid:false, message:"授权已过期"
|
||||
无卡密 → valid:false, message:"卡密不存在" / "卡密已被禁用"</pre>
|
||||
</div>
|
||||
<div class="docs-code">
|
||||
<div class="docs-code-title">其他常用接口</div>
|
||||
<pre>GET /api/public/projects 项目/商品列表
|
||||
GET /api/public/projects/{id}/card-types 项目套餐
|
||||
POST /api/public/orders 创建订单 → 返回 pay_url
|
||||
GET /api/public/orders/query?order_no=… 订单查询
|
||||
POST /api/public/authorizations/verify QQ授权验证 { bot_qq }
|
||||
GET /api/public/authorizations/query?bot_qq=… QQ授权状态查询</pre>
|
||||
</div>
|
||||
<p class="docs-tip">限流:公共接口 60 秒 30 次、机器码验证 60 秒 60 次,超限返回 429;建议客户端缓存结果每 10 分钟校验一次。</p>
|
||||
</div>
|
||||
|
||||
<div class="docs-card">
|
||||
<div class="docs-card-head"><IconActivate /><span>常见问题</span></div>
|
||||
<ul>
|
||||
<li><b>付款后没有收到卡密?</b>在「授权查询」用订单号查询;超过 15 分钟未支付订单自动作废。</li>
|
||||
<li><b>卡密提示已被使用?</b>卡密一次性绑定,若需更换设备请联系管理员重置绑定。</li>
|
||||
<li><b>支持退款吗?</b>卡密一经绑定激活不支持退款,购买前请确认商品信息。</li>
|
||||
<li><b>忘记绑定的机器码?</b>用卡密在「授权查询」中即可反查。</li>
|
||||
<li><b>如何成为代理?</b>在网站底部通过代理登录入口注册,审核通过后可在额度内采购卡密。</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</transition>
|
||||
|
||||
@@ -252,7 +328,7 @@
|
||||
<div class="cr-row"><span>类型</span><span>{{ cardResult.type }}</span></div>
|
||||
<div class="cr-row"><span>有效期</span><span>{{ cardResult.expire_time || '永久有效' }}</span></div>
|
||||
<div class="cr-divider"></div>
|
||||
<div class="cr-row"><span>机器人QQ</span><span class="mono">{{ cardResult.bot_qq || '-' }}</span></div>
|
||||
<div class="cr-row"><span>机器码</span><span class="mono">{{ cardResult.bot_qq || '-' }}</span></div>
|
||||
<div class="cr-row"><span>联系人QQ</span><span class="mono">{{ cardResult.contact_qq || '-' }}</span></div>
|
||||
<div class="cr-row" v-if="cardResult.bind_info?.machine_id"><span>绑定设备</span><span class="mono">{{ cardResult.bind_info.machine_id }}</span></div>
|
||||
<div class="cr-row" v-if="cardResult.bound_at"><span>绑定时间</span><span>{{ cardResult.bound_at }}</span></div>
|
||||
@@ -281,7 +357,7 @@
|
||||
<p class="act-success-sub">{{ activateResult?.is_renew ? '授权有效期已延长' : '卡密已成功绑定到以下机器人' }}</p>
|
||||
<div class="act-success-body">
|
||||
<div class="act-row"><span>所属项目</span><strong>{{ activateResult.project_name }}</strong></div>
|
||||
<div class="act-row"><span>机器人QQ</span><strong class="mono">{{ activateResult.bot_qq }}</strong></div>
|
||||
<div class="act-row"><span>机器码</span><strong class="mono">{{ activateResult.bot_qq }}</strong></div>
|
||||
<div class="act-row"><span>联系人QQ</span><strong class="mono">{{ activateResult.contact_qq }}</strong></div>
|
||||
<div class="act-row"><span>卡密</span><strong class="mono">{{ activateResult.card_key }}</strong></div>
|
||||
<div class="act-row" v-if="activateResult.expire_time"><span>到期时间</span><strong>{{ activateResult.expire_time }}</strong></div>
|
||||
@@ -319,7 +395,7 @@
|
||||
</transition>
|
||||
</teleport>
|
||||
|
||||
<!-- 机器人QQ查询结果弹窗 -->
|
||||
<!-- 机器码查询结果弹窗 -->
|
||||
<teleport to="body">
|
||||
<transition name="modal">
|
||||
<div v-if="queryBotDialogVisible && authQueryResult" class="modal-overlay" @click.self="queryBotDialogVisible = false">
|
||||
@@ -392,7 +468,7 @@
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="form-field modal-field">
|
||||
<label>机器人QQ <em>*</em></label>
|
||||
<label>机器码 <em>*</em></label>
|
||||
<input v-model="buyBotQq" class="form-input" placeholder="5-15位数字" maxlength="15" />
|
||||
</div>
|
||||
<div class="form-field modal-field">
|
||||
@@ -449,7 +525,7 @@
|
||||
<svg class="check-svg" viewBox="0 0 24 24" width="44" height="44" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
|
||||
</div>
|
||||
<h3 class="modal-title">购买成功</h3>
|
||||
<p class="success-sub">卡密已自动绑定到机器人QQ,请妥善保存</p>
|
||||
<p class="success-sub">卡密已自动绑定到机器码,请妥善保存</p>
|
||||
<div class="key-box">
|
||||
<code class="mono">{{ orderResult?.card_key }}</code>
|
||||
<button class="btn-sm btn-green" @click="copyCardKey" type="button">复制</button>
|
||||
@@ -457,7 +533,7 @@
|
||||
<div class="success-rows">
|
||||
<div class="s-row"><span>订单号</span><span class="mono">{{ orderResult?.order_no }}</span></div>
|
||||
<div class="s-row"><span>商品</span><span>{{ currentProject?.name }} {{ buyingProduct?.name }}</span></div>
|
||||
<div class="s-row"><span>机器人QQ</span><strong class="mono">{{ buyBotQq }}</strong></div>
|
||||
<div class="s-row"><span>机器码</span><strong class="mono">{{ buyBotQq }}</strong></div>
|
||||
<div class="s-row"><span>联系人QQ</span><strong class="mono">{{ buyContactQq }}</strong></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -487,6 +563,9 @@ const IconActivate = () => h('svg', { viewBox: '0 0 16 16', width: 16, height: 1
|
||||
const IconQuery = () => h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, fill: 'currentColor' }, [
|
||||
h('path', { d: 'M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z' })
|
||||
])
|
||||
const IconDoc = () => h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, fill: 'currentColor' }, [
|
||||
h('path', { d: 'M4 1v8h1V1h6.5a.5.5 0 0 1 .354.146l1.853 1.853A.5.5 0 0 1 13.853 3.5H14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-3H4v3a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V4.5a1.5 1.5 0 0 0-.44-1.06L13.56 1.44A1.5 1.5 0 0 0 12.5 1H4zm-2.5 10h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1 0-1zm0-3h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1 0-1zm0-3h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 1 0-1z' })
|
||||
])
|
||||
const CheckIcon = () => h('svg', { viewBox: '0 0 16 16', width: 14, height: 14, fill: 'currentColor' }, [
|
||||
h('path', { d: 'M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z' })
|
||||
])
|
||||
@@ -497,6 +576,7 @@ const tabs = [
|
||||
{ key: 'buy', label: '购买授权', icon: IconBuy },
|
||||
{ key: 'activate', label: '在线授权', icon: IconActivate },
|
||||
{ key: 'query', label: '授权查询', icon: IconQuery },
|
||||
{ key: 'docs', label: '使用文档', icon: IconDoc },
|
||||
]
|
||||
const navTabsRef = ref(null)
|
||||
const navTabRefs = ref([])
|
||||
@@ -595,15 +675,30 @@ const buyFinalAmount = computed(() => {
|
||||
if (buyCouponResult.value?.valid) return buyCouponResult.value.final_amount
|
||||
return parseFloat(buyingProduct.value?.price || 0)
|
||||
})
|
||||
const payOptions = [
|
||||
const allPayOptions = [
|
||||
{ value: 'alipay', label: '支付宝', icon: '<svg viewBox="0 0 24 24" width="18" height="18" fill="#1677ff"><circle cx="12" cy="12" r="10"/></svg>' },
|
||||
{ value: 'wxpay', label: '微信', icon: '<svg viewBox="0 0 24 24" width="18" height="18" fill="#07c160"><circle cx="12" cy="12" r="10"/></svg>' },
|
||||
{ value: 'qqpay', label: 'QQ钱包', icon: '<svg viewBox="0 0 24 24" width="18" height="18" fill="#12b7f5"><circle cx="12" cy="12" r="10"/></svg>' },
|
||||
]
|
||||
const payOptions = computed(() => {
|
||||
const enabled = enabledPayTypes.value.length ? enabledPayTypes.value : ['alipay', 'wxpay']
|
||||
return allPayOptions.filter(o => enabled.includes(o.value))
|
||||
})
|
||||
const enabledPayTypes = ref(['alipay', 'wxpay'])
|
||||
async function loadPayOptions() {
|
||||
try {
|
||||
const res = await request.get('/public/payment/options')
|
||||
enabledPayTypes.value = res.data.pay_types || ['alipay', 'wxpay']
|
||||
if (!payOptions.value.some(o => o.value === payType.value)) {
|
||||
payType.value = payOptions.value[0]?.value || 'alipay'
|
||||
}
|
||||
} catch { /* fallback to defaults */ }
|
||||
}
|
||||
loadPayOptions()
|
||||
|
||||
/* ===== 查询 ===== */
|
||||
const queryTab = ref('card')
|
||||
const queryTabs = [{ key: 'card', label: '卡密查询' }, { key: 'bot', label: '机器人QQ查询' }]
|
||||
const queryTabs = [{ key: 'card', label: '卡密查询' }, { key: 'bot', label: '机器码查询' }]
|
||||
const queryCardKey = ref('')
|
||||
|
||||
watch(queryTab, updateQuerySlider)
|
||||
@@ -670,8 +765,8 @@ async function handleCheckBuyCoupon() {
|
||||
}
|
||||
|
||||
async function handlePay() {
|
||||
if (!buyBotQq.value.trim()) { ElMessage.error('请输入机器人QQ'); return }
|
||||
if (!/^\d{5,15}$/.test(buyBotQq.value.trim())) { ElMessage.error('机器人QQ格式不正确(5-15位数字)'); return }
|
||||
if (!buyBotQq.value.trim()) { ElMessage.error('请输入机器码'); return }
|
||||
if (!/^\d{5,15}$/.test(buyBotQq.value.trim())) { ElMessage.error('机器码格式不正确(5-15位数字)'); return }
|
||||
if (!buyContactQq.value.trim()) { ElMessage.error('请输入联系人QQ'); return }
|
||||
if (!/^\d{5,15}$/.test(buyContactQq.value.trim())) { ElMessage.error('联系人QQ格式不正确(5-15位数字)'); return }
|
||||
loading.pay = true
|
||||
@@ -683,8 +778,8 @@ async function handlePay() {
|
||||
bot_qq: buyBotQq.value.trim(), contact_qq: buyContactQq.value.trim(),
|
||||
})
|
||||
if (res.data.pay_url) {
|
||||
ElMessage.success('订单创建成功,5秒后跳转支付页面')
|
||||
setTimeout(() => { window.open(res.data.pay_url, '_blank') }, 5000)
|
||||
ElMessage.success('订单创建成功,正在跳转支付页面...')
|
||||
window.location.href = res.data.pay_url
|
||||
}
|
||||
pollOrderStatus(res.data.order_no)
|
||||
} catch { /* handled */ }
|
||||
@@ -709,8 +804,8 @@ function copyCardKey() {
|
||||
async function handleActivate() {
|
||||
const { card_key, bot_qq, contact_qq } = activateForm
|
||||
if (!card_key.trim()) { activateError.value = '请输入卡密'; activateErrorDialogVisible.value = true; return }
|
||||
if (!bot_qq.trim()) { activateError.value = '请输入机器人QQ'; activateErrorDialogVisible.value = true; return }
|
||||
if (!/^\d{5,15}$/.test(bot_qq.trim())) { activateError.value = '机器人QQ格式不正确'; activateErrorDialogVisible.value = true; return }
|
||||
if (!bot_qq.trim()) { activateError.value = '请输入机器码'; activateErrorDialogVisible.value = true; return }
|
||||
if (!/^\d{5,15}$/.test(bot_qq.trim())) { activateError.value = '机器码格式不正确'; activateErrorDialogVisible.value = true; return }
|
||||
if (!contact_qq.trim()) { activateError.value = '请输入联系人QQ'; activateErrorDialogVisible.value = true; return }
|
||||
if (!/^\d{5,15}$/.test(contact_qq.trim())) { activateError.value = '联系人QQ格式不正确'; activateErrorDialogVisible.value = true; return }
|
||||
loading.activate = true
|
||||
@@ -1865,4 +1960,49 @@ function clearQueryResults() { cardResult.value = null; cardDialogVisible.value
|
||||
.auth-stats { gap: 8px; }
|
||||
.stat-block { min-width: 60px; padding: 12px 8px; }
|
||||
}
|
||||
|
||||
/* ===== 使用文档 ===== */
|
||||
.docs-wrap { display: flex; flex-direction: column; gap: 22px; max-width: 1100px; margin: 0 auto; }
|
||||
.docs-hero { text-align: center; padding: 10px 0 4px; }
|
||||
.docs-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
|
||||
.docs-card {
|
||||
background: rgba(255,255,255,.72);
|
||||
backdrop-filter: blur(14px);
|
||||
border: 1px solid rgba(255,255,255,.75);
|
||||
border-radius: 18px;
|
||||
padding: 22px 24px;
|
||||
box-shadow: 0 8px 30px rgba(102,126,234,.10);
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
line-height: 1.85;
|
||||
}
|
||||
.docs-card-head {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
font-size: 16px; font-weight: 700; color: #333;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.docs-card-head svg { color: #7367f0; }
|
||||
.docs-card b { color: #4c40b8; }
|
||||
.docs-card ul, .docs-card ol { padding-left: 20px; margin: 8px 0; }
|
||||
.docs-card li { margin: 4px 0; }
|
||||
.docs-card code {
|
||||
background: rgba(115,103,240,.10); color: #5b4fd0;
|
||||
padding: 1px 6px; border-radius: 6px; font-size: 12.5px;
|
||||
font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
|
||||
}
|
||||
.docs-tip {
|
||||
margin-top: 10px; padding: 10px 12px;
|
||||
background: rgba(255,183,77,.14); border-left: 3px solid #f5b04c;
|
||||
border-radius: 8px; font-size: 13px; color: #8a5a1f;
|
||||
}
|
||||
.docs-code {
|
||||
background: #2d2b45; color: #e6e6f0; border-radius: 12px;
|
||||
padding: 14px 16px; margin: 10px 0; overflow-x: auto;
|
||||
font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12.5px; line-height: 1.7;
|
||||
}
|
||||
.docs-code-title { color: #9d94ff; font-weight: 600; margin-bottom: 6px; font-size: 12px; letter-spacing: .4px; }
|
||||
.docs-code pre { margin: 0; white-space: pre-wrap; }
|
||||
@media (max-width: 860px) {
|
||||
.docs-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user