239 lines
9.4 KiB
HTML
239 lines
9.4 KiB
HTML
![]() |
<!DOCTYPE html>
|
||
|
<html lang="zh">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>套餐列表</title>
|
||
|
<!-- 引入Layui和jQuery -->
|
||
|
<link rel="stylesheet" href="https://file.guimiaokeji.com/layui/css/layui.css">
|
||
|
<script src="https://file.guimiaokeji.com/layui/jquery-3.6.0.min.js"></script>
|
||
|
<script src="https://file.guimiaokeji.com/layui/layui.js"></script>
|
||
|
<!-- PayPal JavaScript SDK -->
|
||
|
<script src="https://www.paypal.com/sdk/js?client-id=AfwWNEZE92XpbmoHywwdDEXH2x2Elak1Gxbireb5bv-u17OtKiJUuz7CMLnqayAZkqeU2kGtWXHXcXGS¤cy=USD"></script>
|
||
|
<!-- 自定义样式 -->
|
||
|
<style>
|
||
|
body {
|
||
|
font-family: Arial, sans-serif;
|
||
|
background: linear-gradient(to right, #f7f7f7, #e9ecef);
|
||
|
padding: 20px;
|
||
|
}
|
||
|
|
||
|
.plan-card {
|
||
|
border-radius: 10px;
|
||
|
background: white;
|
||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||
|
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||
|
cursor: pointer;
|
||
|
margin-bottom: 20px;
|
||
|
}
|
||
|
|
||
|
.plan-card:hover {
|
||
|
transform: translateY(-10px);
|
||
|
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
||
|
}
|
||
|
|
||
|
.plan-header {
|
||
|
background: linear-gradient(45deg, #6a11cb, #2575fc);
|
||
|
color: white;
|
||
|
border-radius: 10px 10px 0 0;
|
||
|
padding: 20px;
|
||
|
text-align: center;
|
||
|
}
|
||
|
|
||
|
.plan-body {
|
||
|
padding: 20px;
|
||
|
}
|
||
|
|
||
|
.plan-footer {
|
||
|
text-align: center;
|
||
|
padding: 20px;
|
||
|
}
|
||
|
|
||
|
.btn-purchase {
|
||
|
background-color: #2575fc;
|
||
|
color: white;
|
||
|
border-radius: 20px;
|
||
|
padding: 10px 20px;
|
||
|
transition: background-color 0.3s ease;
|
||
|
}
|
||
|
|
||
|
.btn-purchase:hover {
|
||
|
background-color: #6a11cb;
|
||
|
}
|
||
|
|
||
|
.payment-options {
|
||
|
margin-top: 20px;
|
||
|
padding: 20px;
|
||
|
border: 1px solid #e9ecef;
|
||
|
border-radius: 10px;
|
||
|
background-color: #fff;
|
||
|
}
|
||
|
|
||
|
.payment-options button {
|
||
|
margin-right: 10px;
|
||
|
margin-top: 10px;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<div class="layui-container">
|
||
|
<h1 class="text-center mb-5">选择您的套餐</h1>
|
||
|
<div class="layui-row" id="plan-container"></div>
|
||
|
<!-- 支付选项的容器 -->
|
||
|
<div class="payment-options" id="payment-options" style="display:none;">
|
||
|
<h3>请选择支付方式</h3>
|
||
|
<div>
|
||
|
<button class="layui-btn layui-btn-normal" id="alipay-btn">支付宝支付(网页端)</button>
|
||
|
<button class="layui-btn layui-btn-warm" id="alipay-mobile-btn">支付宝支付(手机端)</button>
|
||
|
<div id="paypal-button-container"></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<!-- 使用AJAX获取数据并动态生成套餐卡片 -->
|
||
|
<script>
|
||
|
$(document).ready(function() {
|
||
|
$.ajax({
|
||
|
url: '/api/plans/',
|
||
|
method: 'GET',
|
||
|
success: function(response) {
|
||
|
if (response.code === 200) {
|
||
|
var plans = response.data; // 使用响应中的data字段
|
||
|
var planContainer = $('#plan-container');
|
||
|
plans.forEach(function(plan) {
|
||
|
var planCard = `
|
||
|
<div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
|
||
|
<div class="plan-card">
|
||
|
<div class="plan-header">
|
||
|
<h2>${plan.title}</h2>
|
||
|
<p>${plan.price} / 月</p>
|
||
|
</div>
|
||
|
<div class="plan-body">
|
||
|
<p>${plan.description}</p>
|
||
|
<p><strong>${plan.credits_per_month} AI 积分 / 月</strong></p>
|
||
|
</div>
|
||
|
<div class="plan-footer">
|
||
|
<button class="layui-btn btn-purchase" onclick="selectPlan('${plan.id}','${plan.title}', ${plan.price}, ${plan.credits_per_month})">选择计划</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
`;
|
||
|
planContainer.append(planCard);
|
||
|
});
|
||
|
} else {
|
||
|
layer.msg('获取套餐信息失败: ' + response.message, {icon: 5});
|
||
|
}
|
||
|
},
|
||
|
error: function(xhr, status, error) {
|
||
|
layer.msg('请求出错: ' + error, {icon: 5});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// 支付功能示例
|
||
|
window.selectPlan = function(id, planTitle, planPrice, planCredits) {
|
||
|
$('#payment-options').show(); // 显示支付选项
|
||
|
$('#alipay-btn').off('click').on('click', function() {
|
||
|
payWithAlipay(id, planTitle, planPrice, planCredits);
|
||
|
});
|
||
|
|
||
|
$('#alipay-mobile-btn').off('click').on('click', function() {
|
||
|
payWithAlipayMobile(id, planTitle, planPrice, planCredits);
|
||
|
});
|
||
|
|
||
|
// 清除之前的 PayPal 按钮实例
|
||
|
$('#paypal-button-container').html('');
|
||
|
paypal.Buttons({
|
||
|
style: {
|
||
|
layout: 'vertical', // or 'horizontal', depending on your layout preference
|
||
|
color: 'gold',
|
||
|
shape: 'rect',
|
||
|
label: 'paypal'
|
||
|
},
|
||
|
createOrder: function(data, actions) {
|
||
|
return actions.order.create({
|
||
|
purchase_units: [{
|
||
|
amount: {
|
||
|
value: planPrice.toString()
|
||
|
}
|
||
|
}]
|
||
|
});
|
||
|
},
|
||
|
onApprove: function(data, actions) {
|
||
|
return actions.order.capture().then(function(details) {
|
||
|
alert('支付成功,感谢 ' + details.payer.name.given_name + '!');
|
||
|
// 在此处可以调用后端API保存支付信息
|
||
|
$.ajax({
|
||
|
url: '/api/paypal/execute/', // 替换为实际的执行URL
|
||
|
method: 'POST',
|
||
|
contentType: 'application/json',
|
||
|
data: JSON.stringify({ orderID: data.orderID, payerID: details.payer.payer_id }),
|
||
|
success: function(response) {
|
||
|
layer.msg('支付成功', {icon: 1});
|
||
|
},
|
||
|
error: function(xhr, status, error) {
|
||
|
layer.msg('保存支付信息失败: ' + error, {icon: 5});
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
onError: function(err) {
|
||
|
alert('支付过程中出现错误,请稍后再试。');
|
||
|
}
|
||
|
}).render('#paypal-button-container');
|
||
|
|
||
|
};
|
||
|
|
||
|
// 支付宝网页端支付函数
|
||
|
function payWithAlipay(id, planTitle, planPrice, planCredits) {
|
||
|
$.ajax({
|
||
|
url: '/api/alipay/create_order/', // 调用后端接口创建支付宝订单
|
||
|
method: 'POST',
|
||
|
contentType: 'application/json',
|
||
|
data: JSON.stringify({
|
||
|
id: id,
|
||
|
title: planTitle,
|
||
|
price: planPrice
|
||
|
}),
|
||
|
success: function(response) {
|
||
|
if (response.code === 200) {
|
||
|
window.location.href = response.data.alipay_url; // 跳转到支付宝支付页面
|
||
|
} else {
|
||
|
layer.msg('创建订单失败: ' + response.message, {icon: 5});
|
||
|
}
|
||
|
},
|
||
|
error: function(xhr, status, error) {
|
||
|
layer.msg('请求出错: ' + error, {icon: 5});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 支付宝手机端H5支付函数
|
||
|
function payWithAlipayMobile(id, planTitle, planPrice, planCredits) {
|
||
|
$.ajax({
|
||
|
url: '/api/alipay/create_h5_order/', // 调用后端接口创建手机端支付宝H5订单
|
||
|
method: 'POST',
|
||
|
contentType: 'application/json',
|
||
|
data: JSON.stringify({
|
||
|
id: id,
|
||
|
title: planTitle,
|
||
|
price: planPrice
|
||
|
}),
|
||
|
success: function(response) {
|
||
|
if (response.code === 200) {
|
||
|
window.location.href = response.data.alipay_url; // 跳转到支付宝H5支付页面
|
||
|
} else {
|
||
|
layer.msg('创建订单失败: ' + response.message, {icon: 5});
|
||
|
}
|
||
|
},
|
||
|
error: function(xhr, status, error) {
|
||
|
layer.msg('请求出错: ' + error, {icon: 5});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|