|
|
@@ -273,6 +273,17 @@ class OrderController extends BaseController
|
|
|
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
+ $transactionFinished = false;
|
|
|
+ register_shutdown_function(function () use (&$transactionFinished, $transaction) {
|
|
|
+ if ($transactionFinished) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ \bizHd\product\classes\ProductClass::rollbackLimitBuySnapshot();
|
|
|
+ if ($transaction->isActive) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
try {
|
|
|
$orderValidTime = !getenv('ORDER_VALID_TIME') ? 600 : getenv('ORDER_VALID_TIME');
|
|
|
$post['deadline'] = time() + $orderValidTime;
|
|
|
@@ -480,6 +491,9 @@ class OrderController extends BaseController
|
|
|
|
|
|
$transaction->commit();
|
|
|
|
|
|
+ $transactionFinished = true;
|
|
|
+ \bizHd\product\classes\ProductClass::clearLimitBuyRollbackSnapshot();
|
|
|
+
|
|
|
$orderSn = $return->orderSn ?? '';
|
|
|
$orderPrice = $return->orderPrice ?? 0;
|
|
|
$id = $return->id ?? 0;
|
|
|
@@ -487,6 +501,8 @@ class OrderController extends BaseController
|
|
|
util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id, 'getPayType' => $getPayType]);
|
|
|
} catch (\Exception $e) {
|
|
|
$transaction->rollBack();
|
|
|
+ \bizHd\product\classes\ProductClass::rollbackLimitBuySnapshot();
|
|
|
+ $transactionFinished = true;
|
|
|
Yii::error("失败原因:" . $e->getMessage());
|
|
|
util::fail('下单失败');
|
|
|
}
|