续费或升级服务器套餐计划时改为根据当前计划实时查询最新的套餐价格作为当前计划的价格

This commit is contained in:
jingrow 2025-07-31 04:34:17 +08:00
parent 6b9ac72cee
commit 64bfb46b98
2 changed files with 114 additions and 20 deletions

View File

@ -249,6 +249,7 @@ export default {
paymentQrCode: null,
paymentQrCodeImage: null,
checkInterval: null,
realPlanPrice: null, //
renewalPeriods: [
{ months: 1, name: '1个月', discount: 0 },
{ months: 3, name: '3个月', discount: 0 },
@ -264,7 +265,7 @@ export default {
if (!this.serverDoc) return null;
return {
plan_price: this.serverDoc.plan_price || 0,
plan_price: this.realPlanPrice || 0,
instance_id: this.serverDoc.instance_id,
region: this.serverDoc.region
};
@ -415,6 +416,28 @@ export default {
}
}
};
},
getRealPlanPrice() {
return {
url: 'jcloud.api.aliyun_server_light.get_server_plan_price',
params: {
instance_id: this.serverDoc?.instance_id
},
onSuccess(data) {
if (data.success) {
this.realPlanPrice = data.plan_price;
}
},
onError(error) {
console.warn('获取实时套餐价格失败:', error.message);
}
};
}
},
async mounted() {
//
if (this.serverDoc?.instance_id) {
await this.$resources.getRealPlanPrice.submit();
}
},
methods: {

View File

@ -810,9 +810,22 @@ def get_aliyun_instance_upgrade_plans(instance_id):
# 过滤套餐只返回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']:
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%利润率且价格为整数
# 获取当前套餐价格
current_plan_price = 0
if server.planid:
for plan in result['data']['plans']:
if plan.get('plan_id') == server.planid:
current_plan_price = plan['origin_price']
break
# 过滤套餐
filtered_plans = []
for plan in result['data']['plans']:
# 检查plan_type是否与服务器的PlanType一致
if plan.get('plan_type') == server.plan_type:
@ -821,15 +834,9 @@ def get_aliyun_instance_upgrade_plans(instance_id):
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)
# 只显示价格大于等于当前套餐价格的套餐
if plan['origin_price'] > current_plan_price:
filtered_plans.append(plan)
except:
continue
@ -994,15 +1001,27 @@ def create_server_upgrade_order(**kwargs):
if current_team.name != team:
jingrow.throw("您没有权限为此服务器创建升级订单")
# 获取当前套餐和新套餐信息
current_plan_price = server_pg.plan_price or 0
# 获取套餐列表
plans_response = get_aliyun_plans(server_pg.region)
if not plans_response or not plans_response.get('success'):
jingrow.throw("获取套餐列表失败")
plans = plans_response['data'].get('plans', [])
# 获取当前套餐价格
current_plan_price = 0
if server_pg.planid:
for plan in plans:
if plan.get('plan_id') == server_pg.planid:
current_plan_price = float(plan.get('origin_price', 0))
break
# 获取新套餐价格
plans_response = get_aliyun_plans(server_pg.region)
new_plan = None
if plans_response and plans_response.get('success'):
plans = plans_response['data'].get('plans', [])
new_plan = next((p for p in plans if p.get('plan_id') == new_plan_id), None)
for plan in plans:
if plan.get('plan_id') == new_plan_id:
new_plan = plan
break
if not new_plan:
jingrow.throw("新套餐不存在")
@ -1327,9 +1346,12 @@ def update_server_record(instance_ids):
server.disk_size = resource_spec.get('disk_size')
server.bandwidth = resource_spec.get('bandwidth')
# 更新套餐价格信息
# 更新套餐信息
plan_id = instance_info.get('plan_id')
if plan_id:
# 更新planid
server.planid = plan_id
# 获取套餐信息来计算价格
plans_result = get_aliyun_plans(region_id)
if plans_result and plans_result.get('success') and plans_result.get('data', {}).get('plans'):
@ -1353,7 +1375,8 @@ def update_server_record(instance_ids):
"status": server.status,
"system": server.system,
"os_type": server.os_type,
"plan_price": server.plan_price
"plan_price": server.plan_price,
"planid": server.planid
}
}
@ -1377,6 +1400,54 @@ def reset_server_key_pair(instance_id):
jingrow.log_error("重置密钥对失败", f"重置实例 {instance_id} 密钥对时发生错误: {str(e)}")
return {"success": False, "message": str(e)}
@jingrow.whitelist()
def get_server_plan_price(instance_id):
"""根据实例ID获取当前套餐的实时价格"""
try:
# 获取服务器记录
server = jingrow.get_pg("Jsite Server", {"instance_id": instance_id})
if not server:
return {"success": False, "message": "找不到服务器记录"}
if not server.planid:
return {"success": False, "message": "服务器记录缺少套餐信息"}
# 获取套餐列表使用get_aliyun_plans确保价格调整一致
plans_result = get_aliyun_plans(server.region)
if not plans_result or not plans_result.get('success'):
return {"success": False, "message": "获取套餐列表失败"}
# 查找当前套餐
plans = plans_result.get('data', {}).get('plans', [])
current_plan = None
for plan in plans:
if plan.get('plan_id') == server.planid:
current_plan = plan
break
if not current_plan:
return {"success": False, "message": "找不到对应的套餐信息"}
# 使用已经调整过的价格
current_plan_price = float(current_plan.get('origin_price', 0))
return {
"success": True,
"plan_price": current_plan_price,
"plan_info": {
"plan_id": current_plan.get('plan_id'),
"cpu": current_plan.get('core'),
"memory": current_plan.get('memory'),
"disk_size": current_plan.get('disk_size'),
"bandwidth": current_plan.get('bandwidth')
}
}
except Exception as e:
jingrow.log_error("获取套餐价格失败", f"获取实例 {instance_id} 套餐价格时发生错误: {str(e)}")
return {"success": False, "error": str(e), "message": "获取套餐价格失败"}
@jingrow.whitelist()
def get_password(pagetype, name, fieldname):