@@ -79,6 +124,14 @@
+
+
+
diff --git a/public/js/main.js b/public/js/main.js
index 8032ca8..539b906 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -30,6 +30,7 @@ async function loadProductData() {
document.getElementById('product-name').textContent = currentProduct.name;
document.getElementById('product-description').textContent = currentProduct.description;
document.getElementById('product-price').textContent = currentProduct.price.toFixed(2);
+ document.getElementById('unit-price').textContent = currentProduct.price.toFixed(2);
updateTotalPrice();
} catch (error) {
@@ -61,6 +62,17 @@ function setupEventListeners() {
quantityInput.addEventListener('input', updateTotalPrice);
quantityInput.addEventListener('change', validateQuantity);
+ // 手机号验证
+ document.getElementById('customer_phone').addEventListener('blur', validatePhone);
+ document.getElementById('customer_phone').addEventListener('input', function(e) {
+ // 只允许输入数字
+ e.target.value = e.target.value.replace(/[^0-9]/g, '');
+ // 限制长度为11位
+ if (e.target.value.length > 11) {
+ e.target.value = e.target.value.slice(0, 11);
+ }
+ });
+
// 表单提交
orderForm.addEventListener('submit', handleOrderSubmit);
@@ -84,8 +96,45 @@ function updateTotalPrice() {
if (!currentProduct) return;
const quantity = parseInt(quantityInput.value) || 1;
- const total = (currentProduct.price * quantity).toFixed(2);
- totalPriceElement.textContent = `$${total}`;
+ const unitPrice = currentProduct.price;
+ const originalTotal = unitPrice * quantity;
+
+ // 计算折扣
+ let discount = 0;
+ let discountText = '';
+ let finalTotal = originalTotal;
+
+ if (quantity >= 5) {
+ discount = 0.1; // 9折,优惠10%
+ discountText = '5个及以上 9折优惠';
+ finalTotal = originalTotal * 0.9;
+ } else if (quantity >= 2) {
+ discount = 0.05; // 9.5折,优惠5%
+ discountText = '2个 9.5折优惠';
+ finalTotal = originalTotal * 0.95;
+ }
+
+ // 更新显示
+ const discountLine = document.getElementById('discount-line');
+ const subtotalLine = document.getElementById('subtotal-line');
+ const discountTextElement = document.getElementById('discount-text');
+ const subtotalPriceElement = document.getElementById('subtotal-price');
+
+ if (discount > 0) {
+ // 显示优惠信息
+ discountLine.style.display = 'flex';
+ subtotalLine.style.display = 'flex';
+
+ const discountAmount = originalTotal - finalTotal;
+ discountTextElement.textContent = `-$${discountAmount.toFixed(2)} USDT (${discountText})`;
+ subtotalPriceElement.textContent = `$${originalTotal.toFixed(2)} USDT`;
+ } else {
+ // 隐藏优惠信息
+ discountLine.style.display = 'none';
+ subtotalLine.style.display = 'none';
+ }
+
+ totalPriceElement.textContent = `$${finalTotal.toFixed(2)} USDT`;
}
// 验证数量
@@ -110,9 +159,24 @@ async function handleOrderSubmit(e) {
// 获取表单数据
const formData = new FormData(orderForm);
+ const quantity = parseInt(formData.get('quantity'));
+
+ // 计算最终价格(包含折扣)
+ const unitPrice = currentProduct.price;
+ const originalTotal = unitPrice * quantity;
+ let finalTotal = originalTotal;
+
+ if (quantity >= 5) {
+ finalTotal = originalTotal * 0.9; // 9折
+ } else if (quantity >= 2) {
+ finalTotal = originalTotal * 0.95; // 9.5折
+ }
+
const orderData = {
product_id: currentProduct.id,
- quantity: parseInt(formData.get('quantity')),
+ quantity: quantity,
+ unit_price: unitPrice,
+ total_amount: finalTotal, // 使用折扣后的价格
customer_name: formData.get('customer_name').trim(),
customer_email: formData.get('customer_email').trim(),
customer_phone: formData.get('customer_phone').trim(),
@@ -120,8 +184,20 @@ async function handleOrderSubmit(e) {
};
// 验证必填字段
- if (!orderData.customer_name || !orderData.shipping_address) {
- alert('请填写姓名和收货地址');
+ if (!orderData.customer_name || !orderData.customer_phone || !orderData.customer_email || !orderData.shipping_address) {
+ alert('请填写所有必填信息');
+ return;
+ }
+
+ // 验证手机号格式
+ if (!validatePhoneNumber(orderData.customer_phone)) {
+ alert('请输入正确的11位手机号码');
+ return;
+ }
+
+ // 验证邮箱格式
+ if (!validateEmail(orderData.customer_email)) {
+ alert('请输入正确的邮箱地址');
return;
}
@@ -315,12 +391,51 @@ function validateEmail(email) {
return emailRegex.test(email);
}
-// 工具函数:验证电话号码
-function validatePhone(phone) {
- const phoneRegex = /^[\d\s\-\+\(\)]+$/;
+// 工具函数:验证手机号码
+function validatePhoneNumber(phone) {
+ const phoneRegex = /^1[3-9]\d{9}$/;
return phoneRegex.test(phone);
}
+// 手机号失焦验证
+function validatePhone() {
+ const phoneInput = document.getElementById('customer_phone');
+ const phone = phoneInput.value.trim();
+
+ if (phone && !validatePhoneNumber(phone)) {
+ phoneInput.style.borderColor = '#ff4757';
+ showFieldError(phoneInput, '请输入正确的11位手机号码');
+ } else {
+ phoneInput.style.borderColor = '#444';
+ hideFieldError(phoneInput);
+ }
+}
+
+// 显示字段错误
+function showFieldError(input, message) {
+ hideFieldError(input); // 先清除已有错误
+
+ const errorDiv = document.createElement('div');
+ errorDiv.className = 'field-error';
+ errorDiv.textContent = message;
+ errorDiv.style.cssText = 'color: #ff4757; font-size: 12px; margin-top: 5px; padding-left: 5px;';
+
+ input.parentNode.appendChild(errorDiv);
+}
+
+// 隐藏字段错误
+function hideFieldError(input) {
+ const existingError = input.parentNode.querySelector('.field-error');
+ if (existingError) {
+ existingError.remove();
+ }
+}
+
+// 工具函数:验证电话号码(保留兼容性)
+function validatePhone(phone) {
+ return validatePhoneNumber(phone);
+}
+
// 管理员登录相关函数
function showAdminLogin() {
document.getElementById('adminLoginModal').style.display = 'flex';
@@ -333,6 +448,15 @@ function closeAdminLogin() {
document.getElementById('loginError').style.display = 'none';
}
+// 联系我们相关函数
+function showContactModal() {
+ document.getElementById('contactModal').style.display = 'flex';
+}
+
+function closeContactModal() {
+ document.getElementById('contactModal').style.display = 'none';
+}
+
function verifyAdminPassword() {
const password = document.getElementById('adminPassword').value;
const errorDiv = document.getElementById('loginError');
@@ -353,6 +477,7 @@ function verifyAdminPassword() {
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeAdminLogin();
+ closeContactModal();
}
});
diff --git a/public/manual-payment.html b/public/manual-payment.html
index e2cfbd5..7aafb50 100644
--- a/public/manual-payment.html
+++ b/public/manual-payment.html
@@ -3,7 +3,7 @@
-
手动支付确认 - USDT商城
+ 手动支付确认 - 加密世界商城
diff --git a/public/success.html b/public/success.html
index 6348217..3f1f69d 100644
--- a/public/success.html
+++ b/public/success.html
@@ -3,7 +3,7 @@
- 支付成功 - USDT商城
+ 支付成功 - 加密世界商城
diff --git a/server.js b/server.js
index bd8590f..d671818 100644
--- a/server.js
+++ b/server.js
@@ -53,9 +53,9 @@ const UPAY_API_URL = 'https://api-test.upay.ink/v1/api/open';
// 产品配置
const PRODUCTS = {
'premium-product': {
- name: '比特币彩票抽奖机',
+ name: 'Bitaxe 601 比特币刮刮乐',
price: 100,
- description: '这是我们的比特币彩票抽奖机,质量优秀'
+ description: '这是我们的比特币刮刮乐,质量优秀'
}
};
@@ -80,6 +80,8 @@ app.post('/api/orders', async (req, res) => {
const {
product_id,
quantity,
+ unit_price,
+ total_amount,
customer_name,
customer_email,
customer_phone,
@@ -92,7 +94,24 @@ app.post('/api/orders', async (req, res) => {
}
const product = PRODUCTS[product_id];
- const total_amount = product.price * quantity;
+
+ // 验证价格计算(防止客户端篡改)
+ const expectedUnitPrice = product.price;
+ const originalTotal = expectedUnitPrice * quantity;
+ let expectedTotal = originalTotal;
+
+ // 服务器端折扣计算验证
+ if (quantity >= 5) {
+ expectedTotal = originalTotal * 0.9; // 9折
+ } else if (quantity >= 2) {
+ expectedTotal = originalTotal * 0.95; // 9.5折
+ }
+
+ // 价格验证(允许小数点误差)
+ if (Math.abs(total_amount - expectedTotal) > 0.01) {
+ return res.status(400).json({ error: '价格计算错误' });
+ }
+
const order_id = 'ORDER_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
// 保存订单到数据库
@@ -103,7 +122,7 @@ app.post('/api/orders', async (req, res) => {
`);
stmt.run([
- order_id, product.name, quantity, product.price, total_amount,
+ order_id, product.name, quantity, expectedUnitPrice, expectedTotal,
customer_name, customer_email, customer_phone, shipping_address
], function(err) {
if (err) {
@@ -114,7 +133,7 @@ app.post('/api/orders', async (req, res) => {
res.json({
success: true,
order_id,
- total_amount,
+ total_amount: expectedTotal,
message: '订单创建成功'
});
});