From 18b3d56e5e6b8b72e6fbc09ea66a322c18d41232 Mon Sep 17 00:00:00 2001 From: jingrow Date: Thu, 31 Jul 2025 01:09:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=BC=B9=E7=AA=97=E9=9D=A2=E6=9D=BF=E5=8F=8A?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src2/components/JsiteServerOverview.vue | 22 + .../components/JsiteServerUpgradeDialog.vue | 644 ++++++++++++++++++ jcloud/api/aliyun_server_light.py | 24 +- jcloud/api/billing.py | 3 + 4 files changed, 687 insertions(+), 6 deletions(-) create mode 100644 dashboard/src2/components/JsiteServerUpgradeDialog.vue diff --git a/dashboard/src2/components/JsiteServerOverview.vue b/dashboard/src2/components/JsiteServerOverview.vue index bd4fdad..7f60f06 100644 --- a/dashboard/src2/components/JsiteServerOverview.vue +++ b/dashboard/src2/components/JsiteServerOverview.vue @@ -30,6 +30,13 @@ > 续费 + @@ -230,6 +237,7 @@ export default { resetPasswordLoading: false, resetKeyPairLoading: false, resetSystemLoading: false, + upgradeLoading: false, copySuccess: false, }; }, @@ -300,6 +308,15 @@ export default { onSuccess: this.onRenewalSuccess })); }, + upgradeServer() { + const JsiteServerUpgradeDialog = defineAsyncComponent(() => import('./JsiteServerUpgradeDialog.vue')); + + renderDialog(h(JsiteServerUpgradeDialog, { + server: this.server, + serverDoc: this.$jsiteServer.pg, + onSuccess: this.onUpgradeSuccess + })); + }, async restartServer() { if (!this.$jsiteServer.pg.instance_id) { toast.error('服务器实例ID不存在'); @@ -492,6 +509,11 @@ export default { // 刷新服务器数据 this.$jsiteServer.reload(); }, + onUpgradeSuccess(data) { + toast.success('服务器升级成功!'); + // 刷新服务器数据 + this.$jsiteServer.reload(); + }, }, computed: { serverInformation() { diff --git a/dashboard/src2/components/JsiteServerUpgradeDialog.vue b/dashboard/src2/components/JsiteServerUpgradeDialog.vue new file mode 100644 index 0000000..ebb6ff0 --- /dev/null +++ b/dashboard/src2/components/JsiteServerUpgradeDialog.vue @@ -0,0 +1,644 @@ + + + + + \ No newline at end of file diff --git a/jcloud/api/aliyun_server_light.py b/jcloud/api/aliyun_server_light.py index 822f78a..a12aef4 100644 --- a/jcloud/api/aliyun_server_light.py +++ b/jcloud/api/aliyun_server_light.py @@ -495,7 +495,7 @@ def monitor_server_status(instance_id, region_id): manager = _get_manager() max_retries = 60 # 最多查询60次(10分钟) # 阿里云轻量应用服务器可能的状态值 - waiting_states = ['Starting', 'Stopping', 'Resetting', 'Stopped', 'Pending'] + waiting_states = ['Starting', 'Stopping', 'Resetting', 'Stopped', 'Pending', 'Upgrading'] for retry in range(max_retries): # 查询实例状态 @@ -811,6 +811,10 @@ def get_aliyun_instance_upgrade_plans(instance_id, region_id='cn-shanghai'): try: support_platform_list = json.loads(support_platform_str) if support_platform_str else [] if server.os_type in support_platform_list: + # 在origin_price上统一增加20%作为利润 + if 'origin_price' in plan and plan['origin_price'] is not None: + original_price = float(plan['origin_price']) + plan['origin_price'] = int(original_price / (1 - 0.2)) # 确保20%利润率且价格为整数 filtered_plans.append(plan) except: continue @@ -993,11 +997,19 @@ def create_server_upgrade_order(**kwargs): # 计算剩余天数 if server_pg.end_date: - end_date = jingrow.utils.getdate(server_pg.end_date) - current_date = jingrow.utils.nowdate() - remaining_days = (end_date - current_date).days - if remaining_days <= 0: - remaining_days = 1 # 至少1天 + try: + # 确保end_date是datetime.date对象 + if isinstance(server_pg.end_date, str): + end_date = jingrow.utils.getdate(server_pg.end_date) + else: + end_date = server_pg.end_date + current_date = jingrow.utils.nowdate() + remaining_days = (end_date - current_date).days + if remaining_days <= 0: + remaining_days = 1 # 至少1天 + except Exception as e: + jingrow.log_error("计算剩余天数失败", f"计算实例 {server_pg.instance_id} 剩余天数时发生错误: {str(e)}") + remaining_days = 30 # 出错时使用默认值 else: remaining_days = 30 # 默认30天 diff --git a/jcloud/api/billing.py b/jcloud/api/billing.py index bbab3b8..82407df 100644 --- a/jcloud/api/billing.py +++ b/jcloud/api/billing.py @@ -1092,6 +1092,9 @@ def handle_order_payment_complete(order_id): elif order.order_type == "服务器续费": # 异步续费服务器 jingrow.enqueue('jcloud.api.aliyun_server_light.renew_server', order_name=order.name) + elif order.order_type == "服务器升级": + # 异步升级服务器 + jingrow.enqueue('jcloud.api.aliyun_server_light.upgrade_server', order_name=order.name) elif order.order_type == "新建服务器": # 异步创建服务器 jingrow.enqueue('jcloud.api.aliyun_server_light.create_aliyun_server', order_name=order.name)