新建服务器时余额支付改成使用process_balance_payment_for_server_order接口
This commit is contained in:
parent
8cbe43237f
commit
207190822f
@ -417,7 +417,7 @@ export default {
|
|||||||
// 处理余额支付
|
// 处理余额支付
|
||||||
processBalancePayment() {
|
processBalancePayment() {
|
||||||
return {
|
return {
|
||||||
url: 'jcloud.api.billing.process_balance_payment_for_order',
|
url: 'jcloud.api.billing.process_balance_payment_for_server_order',
|
||||||
validate() {
|
validate() {
|
||||||
if (!this.order || !this.order.order_id) {
|
if (!this.order || !this.order.order_id) {
|
||||||
throw new DashboardError('缺少订单信息');
|
throw new DashboardError('缺少订单信息');
|
||||||
|
|||||||
@ -1089,7 +1089,7 @@ def handle_order_payment_complete(order_id):
|
|||||||
process_balance_recharge(order)
|
process_balance_recharge(order)
|
||||||
elif order.order_type == "网站续费":
|
elif order.order_type == "网站续费":
|
||||||
process_site_renew(order_id)
|
process_site_renew(order_id)
|
||||||
elif order.order_type == "Jsite Server":
|
elif order.order_type == "新建服务器":
|
||||||
# 异步创建服务器
|
# 异步创建服务器
|
||||||
jingrow.enqueue('jcloud.api.aliyun_server_light.create_server_async', order_name=order.name)
|
jingrow.enqueue('jcloud.api.aliyun_server_light.create_server_async', order_name=order.name)
|
||||||
|
|
||||||
@ -1568,6 +1568,76 @@ def process_balance_payment_for_renew_order(order_id):
|
|||||||
"message": _(f"余额支付失败: {str(e)}")
|
"message": _(f"余额支付失败: {str(e)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@jingrow.whitelist()
|
||||||
|
def process_balance_payment_for_server_order(order_id):
|
||||||
|
"""使用账户余额支付订单"""
|
||||||
|
try:
|
||||||
|
# 获取当前用户团队
|
||||||
|
team = get_current_team(True)
|
||||||
|
|
||||||
|
# 获取订单信息
|
||||||
|
order = jingrow.get_pg("Order", {"order_id": order_id})
|
||||||
|
if not order:
|
||||||
|
jingrow.throw(f"找不到订单: {order_id}")
|
||||||
|
|
||||||
|
# 验证订单是否属于当前团队
|
||||||
|
if order.team != team.name:
|
||||||
|
jingrow.throw("您没有权限支付此订单")
|
||||||
|
|
||||||
|
# 检查订单状态
|
||||||
|
if order.status != "待支付":
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": "该订单已支付或已取消"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 使用 Team 类的 get_balance 方法获取余额
|
||||||
|
balance = team.get_balance()
|
||||||
|
|
||||||
|
# 检查余额是否足够
|
||||||
|
if balance < order.total_amount:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": "余额不足"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 创建余额交易记录(扣款)
|
||||||
|
balance_transaction = jingrow.get_pg({
|
||||||
|
"pagetype": "Balance Transaction",
|
||||||
|
"team": team.name,
|
||||||
|
"type": "Adjustment",
|
||||||
|
"source": "Prepaid Credits",
|
||||||
|
"amount": -1 * float(order.total_amount), # 使用负数表示扣减
|
||||||
|
"description": f"{order.order_type}-{order.title}",
|
||||||
|
"paid_via_local_pg": 1
|
||||||
|
})
|
||||||
|
balance_transaction.flags.ignore_permissions = True
|
||||||
|
balance_transaction.insert()
|
||||||
|
balance_transaction.submit()
|
||||||
|
|
||||||
|
# 更新订单状态
|
||||||
|
order.status = "已支付"
|
||||||
|
order.payment_method = "余额支付"
|
||||||
|
order.save(ignore_permissions=True)
|
||||||
|
jingrow.db.commit()
|
||||||
|
|
||||||
|
# 异步执行服务器创建
|
||||||
|
jingrow.enqueue('jcloud.api.aliyun_server_light.create_server_async', order_name=order.name)
|
||||||
|
jingrow.log_error("异步执行创建服务器", f"订单ID: {order_id}")
|
||||||
|
return {
|
||||||
|
"status": "Success",
|
||||||
|
"message": "支付成功",
|
||||||
|
"order": order.as_dict()
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
jingrow.log_error("支付错误", f"余额支付失败: {str(e)}")
|
||||||
|
return {
|
||||||
|
"status": "Error",
|
||||||
|
"message": f"余额支付失败: {str(e)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@jingrow.whitelist()
|
@jingrow.whitelist()
|
||||||
def process_alipay_order(order_id):
|
def process_alipay_order(order_id):
|
||||||
"""创建支付宝订单支付链接"""
|
"""创建支付宝订单支付链接"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user