From 55f70cbf088d6241e37ff8380a3f76b9557870f6 Mon Sep 17 00:00:00 2001 From: jingrow Date: Thu, 31 Jul 2025 02:24:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=8F=AF=E9=80=89=E5=A5=97=E9=A4=90=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=E5=8F=8A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0plan=5Ftype=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/JsiteServerUpgradeDialog.vue | 3 +- jcloud/api/aliyun_server_light.py | 50 ++++++++++++------- .../pagetype/jsite_server/jsite_server.json | 23 +++++++-- .../pagetype/jsite_server/jsite_server.py | 2 + 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/dashboard/src2/components/JsiteServerUpgradeDialog.vue b/dashboard/src2/components/JsiteServerUpgradeDialog.vue index ebb6ff0..90d88f2 100644 --- a/dashboard/src2/components/JsiteServerUpgradeDialog.vue +++ b/dashboard/src2/components/JsiteServerUpgradeDialog.vue @@ -365,8 +365,7 @@ export default { return { url: 'jcloud.api.aliyun_server_light.get_aliyun_instance_upgrade_plans', params: { - instance_id: this.serverInfo?.instance_id, - region_id: this.serverInfo?.region + instance_id: this.serverInfo?.instance_id }, onSuccess(data) { if (data.success && data.data && data.data.plans) { diff --git a/jcloud/api/aliyun_server_light.py b/jcloud/api/aliyun_server_light.py index a12aef4..182d9b3 100644 --- a/jcloud/api/aliyun_server_light.py +++ b/jcloud/api/aliyun_server_light.py @@ -788,36 +788,50 @@ def get_aliyun_instance_details(instance_ids, region_id='cn-shanghai'): return manager.get_instance_details(instance_ids, region_id) @jingrow.whitelist() -def get_aliyun_instance_upgrade_plans(instance_id, region_id='cn-shanghai'): +def get_aliyun_instance_upgrade_plans(instance_id): """获取指定实例可升级的套餐列表""" try: - # 获取当前实例的os_type + # 获取当前实例信息 server = jingrow.get_pg("Jsite Server", {"instance_id": instance_id}) - if not server or not server.os_type: - return {"success": False, "message": "找不到服务器记录或缺少os_type信息"} + if not server: + return {"success": False, "message": "找不到服务器记录"} - # 获取可升级套餐列表 + # 从实例记录中获取region_id + region_id = server.region + if not region_id: + return {"success": False, "message": "服务器记录缺少region信息"} + + # 从get_plans获取所有套餐 manager = _get_manager() - result = manager.get_instance_upgrade_plans(instance_id, region_id) + result = manager.get_plans(region_id) if not result or not result.get('success'): return result - # 过滤套餐:只返回support_platform包含当前实例os_type的套餐 + # 过滤套餐:只返回PlanType值一致的套餐,且价格大于等于当前套餐价格 if result.get('data') and 'plans' in result['data']: filtered_plans = [] + current_plan_price = server.plan_price or 0 + for plan in result['data']['plans']: - support_platform_str = plan.get('support_platform', '') - 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 + # 检查plan_type是否与服务器的PlanType一致 + if plan.get('plan_type') == server.plan_type: + # 检查support_platform是否包含当前实例的os_type + support_platform_str = plan.get('support_platform', '') + try: + support_platform_list = json.loads(support_platform_str) if support_platform_str else [] + if server.os_type and 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']) + adjusted_price = int(original_price / (1 - 0.2)) # 确保20%利润率且价格为整数 + plan['origin_price'] = adjusted_price + + # 只显示价格大于等于当前套餐价格的套餐 + if adjusted_price >= current_plan_price: + filtered_plans.append(plan) + except: + continue result['data']['plans'] = filtered_plans diff --git a/jcloud/jcloud/pagetype/jsite_server/jsite_server.json b/jcloud/jcloud/pagetype/jsite_server/jsite_server.json index c24438a..aa5bf16 100644 --- a/jcloud/jcloud/pagetype/jsite_server/jsite_server.json +++ b/jcloud/jcloud/pagetype/jsite_server/jsite_server.json @@ -7,25 +7,27 @@ "field_order": [ "title", "team", + "plan_type", + "plan_price", "column_break_4", "status", "order_id", + "planid", + "auto_renew", "server_section", "instance_id", - "planid", "cpu", "disk_size", "region", "system", - "period", + "image_id", "column_break_aliyun", "end_date", - "plan_price", "memory", "bandwidth", "public_ip", - "image_id", "os_type", + "period", "ssh_section", "ssh_user", "ssh_port", @@ -204,11 +206,22 @@ "fieldname": "os_type", "fieldtype": "Data", "label": "系统类型" + }, + { + "fieldname": "plan_type", + "fieldtype": "Data", + "label": "套餐类型" + }, + { + "default": "0", + "fieldname": "auto_renew", + "fieldtype": "Check", + "label": "自动续费" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2025-07-30 22:13:52.117023", + "modified": "2025-07-31 01:41:20.678986", "modified_by": "Administrator", "module": "Jcloud", "name": "Jsite Server", diff --git a/jcloud/jcloud/pagetype/jsite_server/jsite_server.py b/jcloud/jcloud/pagetype/jsite_server/jsite_server.py index 55133d1..71fe71f 100644 --- a/jcloud/jcloud/pagetype/jsite_server/jsite_server.py +++ b/jcloud/jcloud/pagetype/jsite_server/jsite_server.py @@ -14,6 +14,7 @@ class JsiteServer(Document): if TYPE_CHECKING: from jingrow.types import DF + auto_renew: DF.Check bandwidth: DF.Data | None cpu: DF.Data | None disk_size: DF.Data | None @@ -27,6 +28,7 @@ class JsiteServer(Document): password: DF.Password | None period: DF.Int plan_price: DF.Int + plan_type: DF.Data | None planid: DF.Data | None private_key: DF.Text | None public_ip: DF.Data | None