重构服务器升级可选套餐列表获取逻辑及增加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 {
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) {

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)
@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

View File

@ -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",

View File

@ -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