From a8303ba772ccdb4bc1b22ff45b366fc21b9201f6 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Thu, 16 Jul 2026 16:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpay.php=E5=85=85=E5=80=BC?= =?UTF-8?q?=E5=95=86=E5=93=81500=E9=94=99=E8=AF=AF=EF=BC=9A=E5=86=85?= =?UTF-8?q?=E8=81=94parseExpireDate=E5=87=BD=E6=95=B0=EF=BC=88=E5=8E=9F?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=BB=85=E5=9C=A8recharge=5Forders=5Fapi.php?= =?UTF-8?q?=E4=B8=AD=E5=AE=9A=E4=B9=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/pay.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/api/pay.php b/api/pay.php index bdef0f8..7b49f4d 100644 --- a/api/pay.php +++ b/api/pay.php @@ -907,6 +907,40 @@ function findRecentOrder($token) { // ==================================================================== // 动作:get_shop_products — 获取上架商品列表(前端充值页面使用) // ==================================================================== +/** + * 解析有效期日期(支持yyyy-MM-dd和中文格式如"2026年7月16日") + */ +function parseExpireDate($expireStr) { + if (empty($expireStr)) { + return ['valid' => true, 'timestamp' => 0, 'display' => '长期有效']; + } + $expireStr = trim($expireStr); + + // yyyy-MM-dd + if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $expireStr)) { + $time = strtotime($expireStr . ' 23:59:59'); + if ($time !== false) { + return ['valid' => true, 'timestamp' => $time, 'display' => date('Y-m-d', $time) . ' 到期']; + } + } + + // 中文格式(如"2026年7月16日") + if (preg_match('/(\d{4})年(\d{1,2})月(\d{1,2})日/', $expireStr, $matches)) { + $time = mktime(23, 59, 59, intval($matches[2]), intval($matches[3]), intval($matches[1])); + if ($time !== false) { + $now = time(); + return [ + 'valid' => $time >= $now, + 'timestamp' => $time, + 'display' => date('Y-m-d', $time) . ($time >= $now ? ' 到期' : ' 已过期') + ]; + } + } + + // 无法解析 → 视为无效 + return ['valid' => false, 'timestamp' => 0, 'display' => '日期格式错误: ' . $expireStr]; +} + function getShopProducts() { $db = getOrdersDB();