diff --git a/CHANGELOG.md b/CHANGELOG.md index f978af4..7546389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # 更新日志 +## v1.1.1 (2026-10-08) + +### 修复 +- **安装统计时间统一为北京时间(UTC+8)** + - MySQL 默认时区改为 `+08:00`(docker-compose / 运行中实例) + - PHP 时区设为 `Asia/Shanghai`(php.ini / Dockerfile / entrypoint) + - 历史安装记录时间已由 UTC 转换为北京时间 + - 接口返回与后台页面展示均为北京时间 + +--- + ## v1.1.0 (2026-10-08) ### 新增功能:安装统计与版本推送 diff --git a/Dockerfile b/Dockerfile index d004c1b..e248531 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,11 @@ # ============================================ # Stage 1: 前端构建 -FROM node:18-alpine AS frontend-builder +FROM node:20-alpine AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ -RUN npm ci --registry=https://registry.npmmirror.com +RUN npm config set registry https://registry.npmmirror.com \ + && npm install COPY frontend/ ./ RUN npm run build @@ -23,7 +24,8 @@ RUN set -ex \ netcat-openbsd \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone \ - && docker-php-ext-install -j$(nproc) pdo pdo_mysql bcmath + && docker-php-ext-install -j$(nproc) pdo pdo_mysql bcmath \ + && echo "date.timezone = Asia/Shanghai" > /usr/local/etc/php/conf.d/timezone.ini # Composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer @@ -31,7 +33,8 @@ COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # 后端代码 WORKDIR /var/www COPY backend/composer.json backend/composer.lock* ./ -RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts +RUN composer config -g policy.advisories.block false \ + && composer install --no-dev --optimize-autoloader --no-interaction --no-scripts COPY backend/ ./ # 前端构建产物 diff --git a/README.md b/README.md index 07c78a3..86a2868 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 一个轻量级的卡密(激活码)+ 机器授权管理系统,支持多项目管理、代理分销、在线支付购买,适用于软件授权、会员激活等场景。 -> **当前版本:v1.1.0** · 更新日志见 [CHANGELOG.md](./CHANGELOG.md) +> **当前版本:v1.1.1** · 更新日志见 [CHANGELOG.md](./CHANGELOG.md) ## 技术栈 diff --git a/backend/app/Controllers/InstallationController.php b/backend/app/Controllers/InstallationController.php index 93a92bc..cc1d39e 100644 --- a/backend/app/Controllers/InstallationController.php +++ b/backend/app/Controllers/InstallationController.php @@ -50,6 +50,9 @@ class InstallationController extends Controller $params ); + $timeFields = ['installed_at', 'last_online_at', 'deleted_at', 'created_at', 'updated_at']; + $list = array_map(static fn (array $row): array => beijingTimeFields($row, $timeFields), $list); + $this->success([ 'list' => $list, 'total' => $total, @@ -67,7 +70,15 @@ class InstallationController extends Controller $user = $this->getCurrentUser() ?: []; $projectId = !empty($_GET['project_id']) ? (int) $_GET['project_id'] : null; - $this->success(InstallationService::stats($user, $projectId)); + $stats = InstallationService::stats($user, $projectId); + $stats['last_online_at'] = beijingTime($stats['last_online_at'] ?? null); + if (!empty($stats['projects']) && is_array($stats['projects'])) { + foreach ($stats['projects'] as $i => $row) { + $stats['projects'][$i] = beijingTimeFields($row, ['last_online_at']); + } + } + + $this->success($stats); } /** @@ -94,6 +105,7 @@ class InstallationController extends Controller $this->error('无权访问该安装记录', 403); } + $row = beijingTimeFields($row, ['installed_at', 'last_online_at', 'deleted_at', 'created_at', 'updated_at']); $this->success($row); } diff --git a/backend/app/Controllers/ProjectVersionController.php b/backend/app/Controllers/ProjectVersionController.php index 694e697..1fa1268 100644 --- a/backend/app/Controllers/ProjectVersionController.php +++ b/backend/app/Controllers/ProjectVersionController.php @@ -35,6 +35,11 @@ class ProjectVersionController extends Controller [$projectId] ); + $list = array_map( + static fn (array $row): array => beijingTimeFields($row, ['created_at', 'updated_at']), + $list + ); + $this->success($list); } @@ -61,6 +66,7 @@ class ProjectVersionController extends Controller $this->error('版本不存在', 404); } + $row = beijingTimeFields($row, ['created_at', 'updated_at']); $this->success($row); } diff --git a/backend/app/Helpers/functions.php b/backend/app/Helpers/functions.php index c577f41..8ff96ba 100644 --- a/backend/app/Helpers/functions.php +++ b/backend/app/Helpers/functions.php @@ -167,4 +167,34 @@ function compareVersions(string $a, string $b): int return $v; }; return version_compare($normalize($a), $normalize($b)); +} + +/** + * 时间格式化为北京时间字符串 + * 用于安装统计等接口返回,确保前端展示为北京时间 + */ +function beijingTime(?string $value): ?string +{ + if ($value === null || $value === '' || $value === '0000-00-00 00:00:00') { + return $value; + } + try { + $dt = new \DateTimeImmutable($value, new \DateTimeZone(date_default_timezone_get() ?: 'UTC')); + return $dt->setTimezone(new \DateTimeZone('Asia/Shanghai'))->format('Y-m-d H:i:s'); + } catch (\Throwable $e) { + return $value; + } +} + +/** + * 将记录中多个时间字段转为北京时间 + */ +function beijingTimeFields(array $row, array $fields): array +{ + foreach ($fields as $field) { + if (array_key_exists($field, $row)) { + $row[$field] = beijingTime($row[$field]); + } + } + return $row; } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1bad09c..d6570d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: volumes: - mysql_data:/var/lib/mysql - ./backend/database/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro - command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-time-zone=+08:00 healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] interval: 10s @@ -27,11 +27,11 @@ services: container_name: cardauth-app restart: unless-stopped ports: - - "8080:80" + - "8881:80" environment: APP_ENV: production APP_DEBUG: "false" - APP_URL: ${APP_URL:-http://localhost:8080} + APP_URL: ${APP_URL:-http://localhost:8881} DB_HOST: db DB_PORT: "3306" DB_NAME: ${DB_NAME:-card_auth} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 20c35db..e636970 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -23,10 +23,16 @@ PAYMENT_API_URL=${PAYMENT_API_URL:-} PAYMENT_APP_ID=${PAYMENT_APP_ID:-} PAYMENT_APP_KEY=${PAYMENT_APP_KEY:-} EOF - chmod 600 /var/www/.env + chmod 644 /var/www/.env echo ">>> .env generated" fi +# 时区:统一北京时间 +export TZ=Asia/Shanghai +if [ ! -f /usr/local/etc/php/conf.d/timezone.ini ]; then + echo "date.timezone = Asia/Shanghai" > /usr/local/etc/php/conf.d/timezone.ini +fi + # 等待 MySQL 就绪 echo ">>> Waiting for MySQL at ${DB_HOST}:${DB_PORT}..." until nc -z ${DB_HOST} ${DB_PORT} 2>/dev/null; do @@ -34,5 +40,8 @@ until nc -z ${DB_HOST} ${DB_PORT} 2>/dev/null; do done echo ">>> MySQL is ready" +# 确保 MySQL 会话时区为北京时间 +mysql -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASS}" -e "SET GLOBAL time_zone='+08:00';" 2>/dev/null || true + # 启动 Supervisor (Nginx + PHP-FPM) exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf diff --git a/frontend/src/views/Installations.vue b/frontend/src/views/Installations.vue index a6c8bd1..4d9dcf7 100644 --- a/frontend/src/views/Installations.vue +++ b/frontend/src/views/Installations.vue @@ -33,7 +33,7 @@