From 7e3af6d7d705aa99730cb87e9221ca65d9410e9e Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Thu, 16 Jul 2026 19:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=98=E6=89=A3=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E7=A1=AC=E9=94=81=E8=A7=84=E5=88=99=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=90=8E=E4=BB=B7=E6=A0=BC=E5=BF=85=E9=A1=BB=E5=B0=8F?= =?UTF-8?q?=E4=BA=8E=E5=8E=9F=E4=BB=B7=EF=BC=8C=E4=B8=94=E4=B8=8D=E4=BD=8E?= =?UTF-8?q?=E4=BA=8E0.01=E5=85=83=EF=BC=9B=E5=94=AE=E4=BB=B7=E4=BD=8E?= =?UTF-8?q?=E4=BA=8E0.01=E5=85=83=E7=9A=84=E5=95=86=E5=93=81=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.php | 38 +++++++++++++ api/check_discount.php | 105 ++++++++++++++++++++++++++++++++++++ api/recharge_orders_api.php | 22 +++++++- 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 api/check_discount.php diff --git a/admin.php b/admin.php index e6a254f..4f78095 100644 --- a/admin.php +++ b/admin.php @@ -3541,6 +3541,7 @@ async function loadShopConfig(el) {
+
⚠️ 优惠后价格必须小于原价,且不低于0.01元。售价低于0.01元的商品不支持折扣。
@@ -3650,6 +3651,43 @@ async function saveShopConfig() { if (!name) { glassAlert('请输入商品名称'); return; } if (price <= 0) { glassAlert('售价必须大于0'); return; } if (!/^\d+(-\d+)?$/.test(bond)) { glassAlert('债券范围格式错误,应为数字或范围如"1-10"'); return; } + + // 折扣价格验证 + if (discountPriceRaw && discountPriceRaw !== '0') { + // 0.01元以下的商品不支持折扣 + if (price < 0.01) { + glassAlert('售价低于0.01元的商品不支持折扣'); + return; + } + + const discountValue = parseFloat(discountPriceRaw); + if (isNaN(discountValue) || discountValue <= 0) { + glassAlert('优惠后价格必须是大于0的数字'); + return; + } + + // 计算实际折扣价格 + let actualDiscount; + if (discountValue < 1) { + // 折扣比例 + actualDiscount = price * discountValue; + } else { + // 直接价格 + actualDiscount = discountValue; + } + + // 硬锁:优惠后价格必须小于原价 + if (actualDiscount >= price) { + glassAlert('优惠后价格必须小于原价(当前原价: ' + price.toFixed(2) + '元)'); + return; + } + + // 硬锁:优惠后价格不能低于0.01元 + if (actualDiscount < 0.01) { + glassAlert('优惠后价格不能低于0.01元'); + return; + } + } // 防重复点击:获取按钮并禁用 const btn = event.target; diff --git a/api/check_discount.php b/api/check_discount.php new file mode 100644 index 0000000..11bdb66 --- /dev/null +++ b/api/check_discount.php @@ -0,0 +1,105 @@ +busyTimeout(5000); +$db->exec('PRAGMA journal_mode=WAL'); + +// 检查表结构 +echo "=== shop_configs表结构 ===\n"; +$result = $db->query("PRAGMA table_info(shop_configs)"); +while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + echo "{$row['cid']}: {$row['name']} ({$row['type']})" . (isset($row['notnull']) && $row['notnull'] ? ' NOT NULL' : '') . (isset($row['dflt_value']) ? " DEFAULT {$row['dflt_value']}" : '') . "\n"; +} + +// 检查现有数据 +echo "\n=== 现有商品数据 ===\n"; +$result = $db->query("SELECT * FROM shop_configs ORDER BY id DESC LIMIT 5"); +while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + echo "ID: {$row['id']}, 名称: {$row['item_name']}, 原价: {$row['price']}, 折扣价: " . (isset($row['discount_price']) ? $row['discount_price'] : '字段不存在') . "\n"; +} + +// 测试插入(带折扣价格) +echo "\n=== 测试插入带折扣价格的商品 ===\n"; +$stmt = $db->prepare("INSERT INTO shop_configs (item_name, stock, temporary_offer, offer_expire, price, discount_price, bond_reward, is_active, created_at, updated_at) VALUES (:name, :stock, :offer, :expire, :price, :discount_price, :bond, :active, :created, :updated)"); +$stmt->bindValue(':name', '测试折扣商品', SQLITE3_TEXT); +$stmt->bindValue(':stock', -1, SQLITE3_INTEGER); +$stmt->bindValue(':offer', '', SQLITE3_TEXT); +$stmt->bindValue(':expire', '', SQLITE3_TEXT); +$stmt->bindValue(':price', 10.00, SQLITE3_FLOAT); +$stmt->bindValue(':discount_price', 8.50, SQLITE3_FLOAT); +$stmt->bindValue(':bond', '1-10', SQLITE3_TEXT); +$stmt->bindValue(':active', 1, SQLITE3_INTEGER); +$stmt->bindValue(':created', time(), SQLITE3_INTEGER); +$stmt->bindValue(':updated', time(), SQLITE3_INTEGER); +$stmt->execute(); + +$testId = $db->lastInsertRowID(); +echo "测试商品ID: $testId\n"; + +// 验证插入 +$result = $db->query("SELECT * FROM shop_configs WHERE id = $testId"); +$row = $result->fetchArray(SQLITE3_ASSOC); +if ($row) { + echo "验证: 原价={$row['price']}, 折扣价={$row['discount_price']}\n"; + if ($row['discount_price'] == 8.50) { + echo "✅ 折扣价格保存成功!\n"; + } else { + echo "❌ 折扣价格保存失败!\n"; + } +} + +// 清理测试数据 +$db->exec("DELETE FROM shop_configs WHERE id = $testId"); +echo "已清理测试数据\n"; + +$db->close(); diff --git a/api/recharge_orders_api.php b/api/recharge_orders_api.php index 520ec9f..90480ac 100644 --- a/api/recharge_orders_api.php +++ b/api/recharge_orders_api.php @@ -491,13 +491,23 @@ function handleShopConfigSave($db) { // 支持两种格式: // 1. 直接价格(如 1、2、1.5)→ 直接使用 // 2. 折扣(如 0.9、0.8)→ 计算 原价 × 折扣 + // 硬锁规则: + // - 0.01元以下的商品不支持折扣 + // - 优惠后价格必须小于原价 $discountPrice = 0; $discountPriceRaw = trim($discountPriceRaw); - if ($discountPriceRaw !== '' && $discountPriceRaw !== '0') { + + // 0.01元以下的商品不支持折扣 + if ($price < 0.01) { + if ($discountPriceRaw !== '' && $discountPriceRaw !== '0') { + error('售价低于0.01元的商品不支持折扣'); + } + } elseif ($discountPriceRaw !== '' && $discountPriceRaw !== '0') { $discountValue = floatval($discountPriceRaw); if ($discountValue <= 0) { error('优惠后价格必须大于0'); } + // 判断是直接价格还是折扣(<1的数认为是折扣) if ($discountValue < 1) { // 折扣:原价 × 折扣 @@ -506,6 +516,16 @@ function handleShopConfigSave($db) { // 直接价格 $discountPrice = round($discountValue, 2); } + + // 硬锁:优惠后价格必须小于原价 + if ($discountPrice >= $price) { + error('优惠后价格必须小于原价(当前原价: ' . number_format($price, 2) . '元)'); + } + + // 硬锁:优惠后价格不能低于0.01元 + if ($discountPrice < 0.01) { + error('优惠后价格不能低于0.01元'); + } } // 验证债券范围格式(支持盲盒范围,如"1-10")