重构服务器升级可选套餐列表获取逻辑及增加plan_type过滤

This commit is contained in:
jingrow 2025-07-31 02:24:07 +08:00
parent 18b3d56e5e
commit 55f70cbf08
4 changed files with 53 additions and 25 deletions

View File

@ -365,8 +365,7 @@ export default {
return { return {
url: 'jcloud.api.aliyun_server_light.get_aliyun_instance_upgrade_plans', url: 'jcloud.api.aliyun_server_light.get_aliyun_instance_upgrade_plans',
params: { params: {
instance_id: this.serverInfo?.instance_id, instance_id: this.serverInfo?.instance_id
region_id: this.serverInfo?.region
}, },
onSuccess(data) { onSuccess(data) {
if (data.success && data.data && data.data.plans) { if (data.success && data.data && data.data.plans) {

View File

@ -788,36 +788,50 @@ def get_aliyun_instance_details(instance_ids, region_id='cn-shanghai'):
return manager.get_instance_details(instance_ids, region_id) return manager.get_instance_details(instance_ids, region_id)
@jingrow.whitelist() @jingrow.whitelist()
def get_aliyun_instance_upgrade_plans(instance_id, region_id='cn-shanghai'): def get_aliyun_instance_upgrade_plans(instance_id):
"""获取指定实例可升级的套餐列表""" """获取指定实例可升级的套餐列表"""
try: try:
# 获取当前实例的os_type # 获取当前实例信息
server = jingrow.get_pg("Jsite Server", {"instance_id": instance_id}) server = jingrow.get_pg("Jsite Server", {"instance_id": instance_id})
if not server or not server.os_type: if not server:
return {"success": False, "message": "找不到服务器记录或缺少os_type信息"} return {"success": False, "message": "找不到服务器记录"}
# 获取可升级套餐列表 # 从实例记录中获取region_id
region_id = server.region
if not region_id:
return {"success": False, "message": "服务器记录缺少region信息"}
# 从get_plans获取所有套餐
manager = _get_manager() 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'): if not result or not result.get('success'):
return result return result
# 过滤套餐:只返回support_platform包含当前实例os_type的套餐 # 过滤套餐:只返回PlanType值一致的套餐且价格大于等于当前套餐价格
if result.get('data') and 'plans' in result['data']: if result.get('data') and 'plans' in result['data']:
filtered_plans = [] filtered_plans = []
current_plan_price = server.plan_price or 0
for plan in result['data']['plans']: for plan in result['data']['plans']:
support_platform_str = plan.get('support_platform', '') # 检查plan_type是否与服务器的PlanType一致
try: if plan.get('plan_type') == server.plan_type:
support_platform_list = json.loads(support_platform_str) if support_platform_str else [] # 检查support_platform是否包含当前实例的os_type
if server.os_type in support_platform_list: support_platform_str = plan.get('support_platform', '')
# 在origin_price上统一增加20%作为利润 try:
if 'origin_price' in plan and plan['origin_price'] is not None: support_platform_list = json.loads(support_platform_str) if support_platform_str else []
original_price = float(plan['origin_price']) if server.os_type and server.os_type in support_platform_list:
plan['origin_price'] = int(original_price / (1 - 0.2)) # 确保20%利润率且价格为整数 # 在origin_price上统一增加20%作为利润
filtered_plans.append(plan) if 'origin_price' in plan and plan['origin_price'] is not None:
except: original_price = float(plan['origin_price'])
continue 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 result['data']['plans'] = filtered_plans

View File

@ -7,25 +7,27 @@
"field_order": [ "field_order": [
"title", "title",
"team", "team",
"plan_type",
"plan_price",
"column_break_4", "column_break_4",
"status", "status",
"order_id", "order_id",
"planid",
"auto_renew",
"server_section", "server_section",
"instance_id", "instance_id",
"planid",
"cpu", "cpu",
"disk_size", "disk_size",
"region", "region",
"system", "system",
"period", "image_id",
"column_break_aliyun", "column_break_aliyun",
"end_date", "end_date",
"plan_price",
"memory", "memory",
"bandwidth", "bandwidth",
"public_ip", "public_ip",
"image_id",
"os_type", "os_type",
"period",
"ssh_section", "ssh_section",
"ssh_user", "ssh_user",
"ssh_port", "ssh_port",
@ -204,11 +206,22 @@
"fieldname": "os_type", "fieldname": "os_type",
"fieldtype": "Data", "fieldtype": "Data",
"label": "系统类型" "label": "系统类型"
},
{
"fieldname": "plan_type",
"fieldtype": "Data",
"label": "套餐类型"
},
{
"default": "0",
"fieldname": "auto_renew",
"fieldtype": "Check",
"label": "自动续费"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2025-07-30 22:13:52.117023", "modified": "2025-07-31 01:41:20.678986",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Jcloud", "module": "Jcloud",
"name": "Jsite Server", "name": "Jsite Server",

View File

@ -14,6 +14,7 @@ class JsiteServer(Document):
if TYPE_CHECKING: if TYPE_CHECKING:
from jingrow.types import DF from jingrow.types import DF
auto_renew: DF.Check
bandwidth: DF.Data | None bandwidth: DF.Data | None
cpu: DF.Data | None cpu: DF.Data | None
disk_size: DF.Data | None disk_size: DF.Data | None
@ -27,6 +28,7 @@ class JsiteServer(Document):
password: DF.Password | None password: DF.Password | None
period: DF.Int period: DF.Int
plan_price: DF.Int plan_price: DF.Int
plan_type: DF.Data | None
planid: DF.Data | None planid: DF.Data | None
private_key: DF.Text | None private_key: DF.Text | None
public_ip: DF.Data | None public_ip: DF.Data | None