update
This commit is contained in:
parent
4ff8980268
commit
a9606d9253
@ -70,15 +70,26 @@ main {
|
|||||||
background: linear-gradient(135deg, #28a745, #20c997);
|
background: linear-gradient(135deg, #28a745, #20c997);
|
||||||
color: white;
|
color: white;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 50px;
|
border-radius: 50%;
|
||||||
padding: 12px 25px;
|
width: 60px;
|
||||||
font-size: 14px;
|
height: 60px;
|
||||||
font-weight: bold;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 1px;
|
|
||||||
box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
|
box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-floating-btn svg {
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
color: white;
|
||||||
|
transition: transform 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-floating-btn:hover svg {
|
||||||
|
transform: scale(1.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.contact-floating-btn:hover {
|
.contact-floating-btn:hover {
|
||||||
@ -321,9 +332,21 @@ main {
|
|||||||
.coupon-section {
|
.coupon-section {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
background: linear-gradient(145deg, #0f1419, #1a2332);
|
background: linear-gradient(145deg, #1a1a1a, #2a2a2a);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
border: 1px solid #2c3e50;
|
border: 1px solid #444;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-section::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 2px;
|
||||||
|
background: linear-gradient(90deg, #ffd700, #ffed4a, #ffd700);
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-input-group {
|
.coupon-input-group {
|
||||||
@ -342,24 +365,28 @@ main {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
|
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||||
|
letter-spacing: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-input-group input:focus {
|
.coupon-input-group input:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
border-color: #007bff;
|
border-color: #ffd700;
|
||||||
box-shadow: 0 0 15px rgba(0, 123, 255, 0.2);
|
box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
|
||||||
background: #1a1a1a;
|
background: #1a1a1a;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-input-group input::placeholder {
|
.coupon-input-group input::placeholder {
|
||||||
color: #666;
|
color: #666;
|
||||||
text-transform: none;
|
text-transform: none;
|
||||||
|
font-family: 'Arial', 'Microsoft YaHei', sans-serif;
|
||||||
|
letter-spacing: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-input-group button {
|
.coupon-input-group button {
|
||||||
padding: 12px 20px;
|
padding: 12px 20px;
|
||||||
background: linear-gradient(135deg, #007bff, #0056b3);
|
background: linear-gradient(135deg, #ffd700, #ffed4a);
|
||||||
color: #fff;
|
color: #000;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@ -368,12 +395,29 @@ main {
|
|||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-input-group button::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: -100%;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
|
||||||
|
transition: left 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-input-group button:hover::before {
|
||||||
|
left: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-input-group button:hover {
|
.coupon-input-group button:hover {
|
||||||
background: linear-gradient(135deg, #0056b3, #004085);
|
background: linear-gradient(135deg, #ffed4a, #fff700);
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
box-shadow: 0 8px 20px rgba(0, 123, 255, 0.3);
|
box-shadow: 0 8px 20px rgba(255, 215, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-input-group button:disabled {
|
.coupon-input-group button:disabled {
|
||||||
@ -382,29 +426,34 @@ main {
|
|||||||
transform: none;
|
transform: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.coupon-input-group button:disabled::before {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.coupon-message {
|
.coupon-message {
|
||||||
padding: 8px 12px;
|
padding: 10px 15px;
|
||||||
border-radius: 6px;
|
border-radius: 8px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
border: 1px solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-message.success {
|
.coupon-message.success {
|
||||||
background: rgba(40, 167, 69, 0.1);
|
background: linear-gradient(145deg, #0a1a0a, #1a3a1a);
|
||||||
color: #28a745;
|
color: #28a745;
|
||||||
border: 1px solid #28a745;
|
border-color: #28a745;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-message.error {
|
.coupon-message.error {
|
||||||
background: rgba(220, 53, 69, 0.1);
|
background: linear-gradient(145deg, #1a0a0a, #3a1a1a);
|
||||||
color: #dc3545;
|
color: #dc3545;
|
||||||
border: 1px solid #dc3545;
|
border-color: #dc3545;
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon-message.info {
|
.coupon-message.info {
|
||||||
background: rgba(0, 123, 255, 0.1);
|
background: linear-gradient(145deg, #0a0a1a, #1a1a3a);
|
||||||
color: #007bff;
|
color: #ffd700;
|
||||||
border: 1px solid #007bff;
|
border-color: #ffd700;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 优惠提示样式 */
|
/* 优惠提示样式 */
|
||||||
@ -919,8 +968,13 @@ main {
|
|||||||
.contact-floating-btn {
|
.contact-floating-btn {
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
padding: 10px 20px;
|
width: 50px;
|
||||||
font-size: 12px;
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-floating-btn svg {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer-content {
|
.footer-content {
|
||||||
@ -1163,6 +1217,7 @@ main {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 滚动条样式优化 */
|
/* 滚动条样式优化 */
|
||||||
@ -1196,68 +1251,37 @@ main {
|
|||||||
background: linear-gradient(145deg, #0a0a0a, #1a1a1a);
|
background: linear-gradient(145deg, #0a0a0a, #1a1a1a);
|
||||||
margin: 0 30px 25px;
|
margin: 0 30px 25px;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
padding: 25px;
|
padding: 20px;
|
||||||
border: 1px solid #333;
|
border: 1px solid #333;
|
||||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-header {
|
.summary-header {
|
||||||
display: flex;
|
margin-bottom: 15px;
|
||||||
justify-content: space-between;
|
padding-bottom: 12px;
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
padding-bottom: 15px;
|
|
||||||
border-bottom: 1px solid #333;
|
border-bottom: 1px solid #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-info {
|
.product-info {
|
||||||
display: flex;
|
display: block;
|
||||||
align-items: center;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.product-thumb {
|
|
||||||
width: 50px;
|
|
||||||
height: 50px;
|
|
||||||
object-fit: cover;
|
|
||||||
border-radius: 8px;
|
|
||||||
margin-right: 12px;
|
|
||||||
border: 1px solid #444;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-details h4 {
|
.product-details h4 {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
margin: 0 0 4px 0;
|
margin: 0 0 6px 0;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-details p {
|
.product-meta {
|
||||||
color: #b0b0b0;
|
|
||||||
margin: 0;
|
|
||||||
font-size: 0.85em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.quantity-display {
|
|
||||||
text-align: center;
|
|
||||||
padding: 8px 16px;
|
|
||||||
background: linear-gradient(145deg, #1a1a1a, #2d2d2d);
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid #444;
|
|
||||||
}
|
|
||||||
|
|
||||||
.quantity-label {
|
|
||||||
display: block;
|
|
||||||
color: #b0b0b0;
|
|
||||||
font-size: 0.8em;
|
|
||||||
margin-bottom: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.quantity-value {
|
|
||||||
display: block;
|
|
||||||
color: #ffd700;
|
color: #ffd700;
|
||||||
font-weight: bold;
|
font-size: 0.9em;
|
||||||
font-size: 1.1em;
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-meta strong {
|
||||||
|
color: #ffd700;
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 价格明细 */
|
/* 价格明细 */
|
||||||
@ -1387,22 +1411,20 @@ main {
|
|||||||
|
|
||||||
.order-summary-card {
|
.order-summary-card {
|
||||||
margin: 0 20px 20px;
|
margin: 0 20px 20px;
|
||||||
padding: 20px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary-header {
|
.summary-header {
|
||||||
flex-direction: column;
|
margin-bottom: 12px;
|
||||||
gap: 15px;
|
padding-bottom: 10px;
|
||||||
align-items: stretch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-info {
|
.product-details h4 {
|
||||||
justify-content: center;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quantity-display {
|
.product-meta {
|
||||||
align-self: center;
|
font-size: 0.85em;
|
||||||
min-width: 80px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.shipping-form-section {
|
.shipping-form-section {
|
||||||
@ -1424,17 +1446,4 @@ main {
|
|||||||
font-size: 16px; /* 防止iOS缩放 */
|
font-size: 16px; /* 防止iOS缩放 */
|
||||||
padding: 14px;
|
padding: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product-thumb {
|
|
||||||
width: 45px;
|
|
||||||
height: 45px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.product-details h4 {
|
|
||||||
font-size: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.product-details p {
|
|
||||||
font-size: 0.8em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -16,7 +16,14 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- 联系我们按钮 -->
|
<!-- 联系我们按钮 -->
|
||||||
<button class="contact-floating-btn" onclick="showContactModal()">联系我们</button>
|
<button class="contact-floating-btn" onclick="showContactModal()">
|
||||||
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M12 2C6.48 2 2 6.48 2 12C2 13.75 2.45 15.38 3.24 16.8L2 22L7.2 20.76C8.62 21.55 10.25 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2Z" fill="currentColor"/>
|
||||||
|
<circle cx="8.5" cy="12" r="1.5" fill="white"/>
|
||||||
|
<circle cx="12" cy="12" r="1.5" fill="white"/>
|
||||||
|
<circle cx="15.5" cy="12" r="1.5" fill="white"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<!-- 产品展示区 -->
|
<!-- 产品展示区 -->
|
||||||
@ -248,15 +255,11 @@
|
|||||||
<div class="order-summary-card">
|
<div class="order-summary-card">
|
||||||
<div class="summary-header">
|
<div class="summary-header">
|
||||||
<div class="product-info">
|
<div class="product-info">
|
||||||
<img src="/images/image01.jpg" alt="产品图片" class="product-thumb">
|
|
||||||
<div class="product-details">
|
<div class="product-details">
|
||||||
<h4 id="summary-product-name">高级产品</h4>
|
<h4 id="summary-product-name">高级产品</h4>
|
||||||
|
<span class="product-meta">数量: <strong id="summary-quantity">1</strong></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="quantity-display">
|
|
||||||
<span class="quantity-label">数量</span>
|
|
||||||
<span id="summary-quantity" class="quantity-value">1</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="price-breakdown">
|
<div class="price-breakdown">
|
||||||
|
|||||||
@ -607,6 +607,10 @@ async function createCoupon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('Creating coupon with data:', {
|
||||||
|
code, name, discount_type: discountType, discount_value: discountValue, is_reusable: isReusable, max_uses: maxUses
|
||||||
|
});
|
||||||
|
|
||||||
const response = await fetch('/api/admin/coupons', {
|
const response = await fetch('/api/admin/coupons', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -622,7 +626,20 @@ async function createCoupon() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
console.log('Response status:', response.status);
|
||||||
|
console.log('Response headers:', response.headers);
|
||||||
|
|
||||||
|
const responseText = await response.text();
|
||||||
|
console.log('Response text:', responseText);
|
||||||
|
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = JSON.parse(responseText);
|
||||||
|
} catch (parseError) {
|
||||||
|
console.error('Failed to parse JSON:', parseError);
|
||||||
|
console.error('Response was:', responseText.substring(0, 200));
|
||||||
|
throw new Error('服务器返回了无效的响应格式');
|
||||||
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
alert('优惠码创建成功!');
|
alert('优惠码创建成功!');
|
||||||
|
|||||||
@ -205,19 +205,33 @@ function showShippingInfoModal() {
|
|||||||
const quantity = parseInt(quantityInput.value) || 1;
|
const quantity = parseInt(quantityInput.value) || 1;
|
||||||
const unitPrice = currentProduct.price;
|
const unitPrice = currentProduct.price;
|
||||||
const originalTotal = unitPrice * quantity;
|
const originalTotal = unitPrice * quantity;
|
||||||
let finalTotal = originalTotal;
|
|
||||||
let discountText = '';
|
|
||||||
let hasDiscount = false;
|
|
||||||
|
|
||||||
// 计算折扣
|
// 计算数量折扣
|
||||||
|
let quantityDiscount = 0;
|
||||||
|
let quantityDiscountText = '';
|
||||||
|
let afterQuantityDiscount = originalTotal;
|
||||||
|
|
||||||
if (quantity >= 5) {
|
if (quantity >= 5) {
|
||||||
finalTotal = originalTotal * 0.9;
|
quantityDiscount = originalTotal * 0.1;
|
||||||
discountText = '9折优惠 (-10%)';
|
quantityDiscountText = '9折优惠 (-10%)';
|
||||||
hasDiscount = true;
|
afterQuantityDiscount = originalTotal * 0.9;
|
||||||
} else if (quantity >= 2) {
|
} else if (quantity >= 2) {
|
||||||
finalTotal = originalTotal * 0.95;
|
quantityDiscount = originalTotal * 0.05;
|
||||||
discountText = '9.5折优惠 (-5%)';
|
quantityDiscountText = '9.5折优惠 (-5%)';
|
||||||
hasDiscount = true;
|
afterQuantityDiscount = originalTotal * 0.95;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算优惠码折扣
|
||||||
|
let couponDiscount = 0;
|
||||||
|
let finalTotal = afterQuantityDiscount;
|
||||||
|
|
||||||
|
if (appliedCoupon) {
|
||||||
|
if (appliedCoupon.discount_type === 'percentage') {
|
||||||
|
couponDiscount = afterQuantityDiscount * (appliedCoupon.discount_value / 100);
|
||||||
|
} else if (appliedCoupon.discount_type === 'fixed') {
|
||||||
|
couponDiscount = Math.min(appliedCoupon.discount_value, afterQuantityDiscount);
|
||||||
|
}
|
||||||
|
finalTotal = afterQuantityDiscount - couponDiscount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新订单汇总信息
|
// 更新订单汇总信息
|
||||||
@ -230,9 +244,25 @@ function showShippingInfoModal() {
|
|||||||
const discountRow = document.querySelector('.discount-row');
|
const discountRow = document.querySelector('.discount-row');
|
||||||
const discountTextElement = document.getElementById('summary-discount-text');
|
const discountTextElement = document.getElementById('summary-discount-text');
|
||||||
|
|
||||||
if (hasDiscount) {
|
if (quantityDiscount > 0 || couponDiscount > 0) {
|
||||||
const discountAmount = originalTotal - finalTotal;
|
let totalDiscountAmount = quantityDiscount + couponDiscount;
|
||||||
discountTextElement.textContent = `-$${discountAmount.toFixed(2)} USDT (${discountText})`;
|
let discountDescription = '';
|
||||||
|
|
||||||
|
if (quantityDiscount > 0 && couponDiscount > 0) {
|
||||||
|
// 同时有数量折扣和优惠码折扣
|
||||||
|
discountDescription = `数量${quantityDiscountText} + 优惠码"${appliedCoupon.name}"`;
|
||||||
|
} else if (quantityDiscount > 0) {
|
||||||
|
// 只有数量折扣
|
||||||
|
discountDescription = quantityDiscountText;
|
||||||
|
} else if (couponDiscount > 0) {
|
||||||
|
// 只有优惠码折扣
|
||||||
|
const couponDiscountText = appliedCoupon.discount_type === 'percentage'
|
||||||
|
? `${appliedCoupon.discount_value}%折扣`
|
||||||
|
: `$${appliedCoupon.discount_value}减免`;
|
||||||
|
discountDescription = `优惠码"${appliedCoupon.name}" (${couponDiscountText})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
discountTextElement.textContent = `-$${totalDiscountAmount.toFixed(2)} USDT (${discountDescription})`;
|
||||||
discountRow.classList.remove('no-discount');
|
discountRow.classList.remove('no-discount');
|
||||||
} else {
|
} else {
|
||||||
discountTextElement.textContent = `$0.00 USDT (无优惠)`;
|
discountTextElement.textContent = `$0.00 USDT (无优惠)`;
|
||||||
@ -368,12 +398,23 @@ async function handleOrderSubmit(e) {
|
|||||||
// 计算最终价格(包含折扣)
|
// 计算最终价格(包含折扣)
|
||||||
const unitPrice = currentProduct.price;
|
const unitPrice = currentProduct.price;
|
||||||
const originalTotal = unitPrice * quantity;
|
const originalTotal = unitPrice * quantity;
|
||||||
let finalTotal = originalTotal;
|
|
||||||
|
|
||||||
|
// 数量折扣计算
|
||||||
|
let afterQuantityDiscount = originalTotal;
|
||||||
if (quantity >= 5) {
|
if (quantity >= 5) {
|
||||||
finalTotal = originalTotal * 0.9; // 9折
|
afterQuantityDiscount = originalTotal * 0.9; // 9折
|
||||||
} else if (quantity >= 2) {
|
} else if (quantity >= 2) {
|
||||||
finalTotal = originalTotal * 0.95; // 9.5折
|
afterQuantityDiscount = originalTotal * 0.95; // 9.5折
|
||||||
|
}
|
||||||
|
|
||||||
|
// 优惠码折扣计算
|
||||||
|
let finalTotal = afterQuantityDiscount;
|
||||||
|
if (appliedCoupon) {
|
||||||
|
if (appliedCoupon.discount_type === 'percentage') {
|
||||||
|
finalTotal = afterQuantityDiscount * (1 - appliedCoupon.discount_value / 100);
|
||||||
|
} else if (appliedCoupon.discount_type === 'fixed') {
|
||||||
|
finalTotal = Math.max(0, afterQuantityDiscount - appliedCoupon.discount_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderData = {
|
const orderData = {
|
||||||
@ -713,12 +754,23 @@ async function handleShippingOrderSubmit(e) {
|
|||||||
// 计算最终价格(包含折扣)
|
// 计算最终价格(包含折扣)
|
||||||
const unitPrice = currentProduct.price;
|
const unitPrice = currentProduct.price;
|
||||||
const originalTotal = unitPrice * quantity;
|
const originalTotal = unitPrice * quantity;
|
||||||
let finalTotal = originalTotal;
|
|
||||||
|
|
||||||
|
// 数量折扣计算
|
||||||
|
let afterQuantityDiscount = originalTotal;
|
||||||
if (quantity >= 5) {
|
if (quantity >= 5) {
|
||||||
finalTotal = originalTotal * 0.9; // 9折
|
afterQuantityDiscount = originalTotal * 0.9; // 9折
|
||||||
} else if (quantity >= 2) {
|
} else if (quantity >= 2) {
|
||||||
finalTotal = originalTotal * 0.95; // 9.5折
|
afterQuantityDiscount = originalTotal * 0.95; // 9.5折
|
||||||
|
}
|
||||||
|
|
||||||
|
// 优惠码折扣计算
|
||||||
|
let finalTotal = afterQuantityDiscount;
|
||||||
|
if (appliedCoupon) {
|
||||||
|
if (appliedCoupon.discount_type === 'percentage') {
|
||||||
|
finalTotal = afterQuantityDiscount * (1 - appliedCoupon.discount_value / 100);
|
||||||
|
} else if (appliedCoupon.discount_type === 'fixed') {
|
||||||
|
finalTotal = Math.max(0, afterQuantityDiscount - appliedCoupon.discount_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderData = {
|
const orderData = {
|
||||||
|
|||||||
25
server.js
25
server.js
@ -42,6 +42,31 @@ db.serialize(() => {
|
|||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
)`);
|
)`);
|
||||||
|
|
||||||
|
// 检查并添加缺失的列
|
||||||
|
db.all("PRAGMA table_info(orders)", [], (err, columns) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Error checking table structure:', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const columnNames = columns.map(col => col.name);
|
||||||
|
|
||||||
|
// 添加缺失的优惠码相关列
|
||||||
|
if (!columnNames.includes('coupon_code')) {
|
||||||
|
db.run("ALTER TABLE orders ADD COLUMN coupon_code TEXT", (err) => {
|
||||||
|
if (err) console.error('Error adding coupon_code column:', err);
|
||||||
|
else console.log('Added coupon_code column to orders table');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!columnNames.includes('coupon_discount')) {
|
||||||
|
db.run("ALTER TABLE orders ADD COLUMN coupon_discount REAL DEFAULT 0", (err) => {
|
||||||
|
if (err) console.error('Error adding coupon_discount column:', err);
|
||||||
|
else console.log('Added coupon_discount column to orders table');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 创建优惠码表
|
// 创建优惠码表
|
||||||
db.run(`CREATE TABLE IF NOT EXISTS coupons (
|
db.run(`CREATE TABLE IF NOT EXISTS coupons (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user