app->db->name('ShopOrder')->where(['order_no' => $orderNo])->find(); if (empty($order)) throw new Exception("订单不存在"); if ($order['status'] !== 2) throw new Exception("不可发起支付"); // 创建支付行为 $this->createPaymentAction($orderNo, $paymentTitle, $paymentAmount); // 扣减用户余额 [$total, $used] = UserUpgradeService::instance()->balance($order['uid'], [$orderNo]); if ($paymentAmount > $total - $used) throw new Exception("可抵扣余额不足"); $this->app->db->name('ShopOrder')->where(['order_no' => $orderNo])->update(['payment_balance' => $paymentAmount]); // 更新支付行为 $this->updatePaymentAction($orderNo, CodeExtend::uniqidDate(20), $paymentAmount, '账户余额支付'); // 刷新用户余额 UserUpgradeService::instance()->balance($order['uid']); return ['info' => '余额支付完成']; } }