From 49ec83539c61d9565c5d027ab28111ddb17f2f15 Mon Sep 17 00:00:00 2001 From: jingrow Date: Sun, 27 Jul 2025 19:21:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=9B=E5=BB=BA=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E8=AE=A2=E5=8D=95=E6=97=B6=E7=9A=84=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E5=92=8C=E4=BD=99=E9=A2=9D=E6=94=AF=E4=BB=98=E7=9A=84=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src2/pages/NewJsiteServer.vue | 210 ++++++++++++------------ jcloud/api/aliyun_server_light.py | 2 +- jcloud/api/billing.py | 121 +------------- 3 files changed, 111 insertions(+), 222 deletions(-) diff --git a/dashboard/src2/pages/NewJsiteServer.vue b/dashboard/src2/pages/NewJsiteServer.vue index 7f03ae4..335edcd 100644 --- a/dashboard/src2/pages/NewJsiteServer.vue +++ b/dashboard/src2/pages/NewJsiteServer.vue @@ -8,111 +8,109 @@ 请选择服务器配置并填写相关信息,点击"创建"后将自动为您开通。

-
-
- - - -
- 正在加载地域列表... -
-
- 已加载 {{ regions.length }} 个地域 -
+
+ + + +
+ 正在加载地域列表...
-
- - -
-
- - -
-
- - +
+ 已加载 {{ regions.length }} 个地域
+
+
+ + +
+
+ + +
+
+ + +
- -
-
-
月度费用
-
- ¥ {{ getSelectedPlanPrice() }} - (月付) + +
+
+
月度费用
+
+ ¥ {{ getSelectedPlanPrice() }} + (月付) +
+
+
+
购买时长
+
{{ period }} 个月
+
+
+
总计
+
¥ {{ getTotalAmount() }}
+
+
+ + +
+ +
+ + +
-
-
购买时长
-
{{ period }} 个月
-
-
-
总计
-
¥ {{ getTotalAmount() }}
-
-
- - -
- -
- - - + + - - -
+
+
+
-
- {{ error }} -
- +
+ {{ error }} +
@@ -419,7 +417,7 @@ export default { // 处理余额支付 processBalancePayment() { return { - url: 'jcloud.api.billing.process_balance_payment_for_server_order', + url: 'jcloud.api.billing.process_balance_payment_for_order', validate() { if (!this.order || !this.order.order_id) { throw new DashboardError('缺少订单信息'); @@ -452,7 +450,7 @@ export default { // 处理支付宝支付 processAlipayPayment() { return { - url: 'jcloud.api.billing.process_alipay_server_order', + url: 'jcloud.api.billing.process_alipay_order', validate() { if (!this.order || !this.order.order_id) { throw new DashboardError('缺少订单信息'); @@ -476,7 +474,7 @@ export default { // 处理微信支付 processWechatPayment() { return { - url: 'jcloud.api.billing.process_wechatpay_server_order', + url: 'jcloud.api.billing.process_wechatpay_order', validate() { if (!this.order || !this.order.order_id) { throw new DashboardError('缺少订单信息'); @@ -498,7 +496,7 @@ export default { // 检查支付状态 checkPaymentStatus() { return { - url: 'jcloud.api.billing.check_server_order_payment_status', + url: 'jcloud.api.billing.check_site_order_payment_status', params: { order_id: this.order?.order_id }, @@ -667,6 +665,14 @@ export default { return `${name} (${platform})`; } return name; + }, + getPaymentMethodName(method) { + const methodNames = { + 'balance': '余额支付', + 'alipay': '支付宝', + 'wechatpay': '微信支付' + }; + return methodNames[method] || '未知方式'; } }, diff --git a/jcloud/api/aliyun_server_light.py b/jcloud/api/aliyun_server_light.py index 2ba3d14..0c2b1e1 100644 --- a/jcloud/api/aliyun_server_light.py +++ b/jcloud/api/aliyun_server_light.py @@ -419,7 +419,7 @@ def create_server_order(**kwargs): "team": team.name, "status": "待支付", "total_amount": total_amount, - "title": f"新建服务器 - {region_id}", + "title": f"{region_id}", "description": f"{selected_plan.get('core')}核/{selected_plan.get('memory')}GB/{selected_plan.get('disk_size')}GB, {period}个月", "server_config": { "plan_id": plan_id, diff --git a/jcloud/api/billing.py b/jcloud/api/billing.py index 1bfc9f0..0c1e05a 100644 --- a/jcloud/api/billing.py +++ b/jcloud/api/billing.py @@ -43,6 +43,7 @@ from jcloud.utils.billing import ( ) from jcloud.utils.mpesa_utils import create_mpesa_request_log from jcloud.api.payment.wechatpay import WeChatPayAPI +from jcloud.api.payment.alipay import AlipayAPI @jingrow.whitelist() def get_publishable_key_and_setup_intent(): @@ -1223,7 +1224,6 @@ def create_alipay_order_for_recharge(amount): jingrow.db.commit() # 直接使用AlipayAPI类生成支付链接 - from jcloud.api.payment.alipay import AlipayAPI api = AlipayAPI() try: @@ -1451,7 +1451,7 @@ def process_balance_payment_for_order(order_id): "type": "Adjustment", "source": "Prepaid Credits", "amount": -1 * float(order.total_amount), # 使用负数表示扣减 - "description": f"新建网站: {order.title}", + "description": f"{order.order_type}-{order.title}", "paid_via_local_pg": 1 }) balance_transaction.flags.ignore_permissions = True @@ -1590,7 +1590,6 @@ def process_alipay_order(order_id): amount = round(float(order.total_amount), 2) # 直接使用AlipayAPI类生成支付链接 - from jcloud.api.payment.alipay import AlipayAPI api = AlipayAPI() try: @@ -1874,119 +1873,3 @@ def get_balance_transactions(page=1, page_size=20, search=None): } # Jsite Server 相关功能 - -@jingrow.whitelist() -def process_balance_payment_for_server_order(order_id): - """使用余额支付服务器订单""" - try: - team = get_current_team(True) - order = jingrow.get_pg("Order", {"order_id": order_id}) - - if not order or order.team != team.name: - jingrow.throw("订单不存在或无权限") - - if order.status != "待支付": - return {"success": False, "message": "订单已处理"} - - balance = team.get_balance() - if balance < order.total_amount: - return {"success": False, "message": "余额不足"} - - # 扣款 - balance_transaction = jingrow.get_pg({ - "pagetype": "Balance Transaction", - "team": team.name, - "type": "Adjustment", - "source": "Prepaid Credits", - "amount": -order.total_amount, - "description": f"服务器购买: {order.title}" - }) - balance_transaction.insert(ignore_permissions=True) - balance_transaction.submit() - - # 更新订单状态 - order.status = "已支付" - order.payment_method = "余额支付" - order.save(ignore_permissions=True) - - # 异步创建服务器 - jingrow.enqueue('jcloud.api.aliyun_server_light.create_server_async', order_name=order.name) - - return {"success": True, "message": "支付成功,服务器创建中"} - - except Exception as e: - jingrow.log_error("服务器支付失败", str(e)) - return {"success": False, "message": str(e)} - -@jingrow.whitelist() -def process_alipay_server_order(order_id): - """支付宝支付服务器订单""" - team = get_current_team(True) - order = jingrow.get_pg("Order", {"order_id": order_id}) - - if not order or order.team != team.name: - jingrow.throw("订单不存在或无权限") - - if order.status != "待支付": - jingrow.throw("订单已处理") - - from jcloud.api.payment.alipay import AlipayAPI - api = AlipayAPI() - - payment_url = api.generate_payment_url( - order_id=order_id, - amount=order.total_amount, - subject=order.title, - team_name=team.name - ) - - order.payment_method = "支付宝" - order.save(ignore_permissions=True) - - return {"payment_url": payment_url, "order_id": order_id} - -@jingrow.whitelist() -def process_wechatpay_server_order(order_id): - """微信支付服务器订单""" - team = get_current_team(True) - order = jingrow.get_pg("Order", {"order_id": order_id}) - - if not order or order.team != team.name: - jingrow.throw("订单不存在或无权限") - - if order.status != "待支付": - jingrow.throw("订单已处理") - - wechat_pay = WeChatPayAPI() - qr_code_url = wechat_pay.generate_payment_url( - order_id=order_id, - amount=order.total_amount, - subject=order.title, - team_name=team.name - ) - - order.payment_method = "微信支付" - order.save(ignore_permissions=True) - - return {"qr_code_url": qr_code_url, "order_id": order_id} - -@jingrow.whitelist() -def check_server_order_payment_status(order_id): - """检查服务器订单支付状态""" - try: - order = jingrow.get_pg("Order", {"order_id": order_id}) - if not order: - jingrow.throw(f"找不到订单: {order_id}") - - return { - "success": True, - "status": order.status, - "order": order.as_dict() - } - - except Exception as e: - jingrow.log_error("服务器订单错误", f"检查服务器订单状态失败: {str(e)}") - return { - "success": False, - "message": f"检查订单状态失败: {str(e)}" - }