src/DdvUtil/Laravel/Proxy/Traits/TransactionQuque.php
public function beginTransactionQuque()
    {
        // 开启事物前清空钩子
        $this->isClearHooksBeginBefore && $this->clearTransactionHooks();
        // 清空事物链接
        $this->transactionConnections = array();
        // 标记正在运行事物
        $this->isRunTransactionQuque = true;
        /**
         * 记录错误
         * @var Throwable[]|\Exception[] $exceptions
         */
        $exceptions = array();
        // 试图运行
        try {
            // 设置从最后一个开始运行
            $this->runQuqueIndex = 0;
            // 试图运行队列中最后一个事物
            $this->callTransactionQuque();
        } catch (\Exception $e) {
            // 保存异常
            $exceptions[] = $e;
        } catch (Throwable $e) {
            // 保存异常
            $exceptions[] = $e;
        }
        foreach ($this->transactionConnections as $connection){
            empty($exceptions) ? $connection->commit() : $connection->rollBack();
        }

        if (empty($exceptions)) {
            /**
             * 遍历提交事物
             * @var callable $handler
             */
            foreach ($this->commitHooks as $handler) {
                try {
                    $this->call($handler);
                } catch (Throwable $exception) {
                    $exceptions[] = $exception;
                }
            }
        } else {
            /**
             * 遍历回滚事物
             * @var callable $fn
             */
            foreach ($this->rollBackHooks as $handler) {
                try {
                    $arguments = array();
                    $parameters = new Parameters($handler, $arguments);
                    $parameters->mapNullParameters(function (&$value, $name, $index, ReflectionParameter $parameter) use (&$exceptions) {
                        $class = $parameter->getClass();
                        $isHas = false;
                        if (!empty($class)) {
                            foreach ($exceptions as $exception) {
                                if ($class->isInstance($exception)) {
                                    // 返回控制器
                                    $value = $exception;
                                    $isHas = true;
                                    break;
                                }
                            }
                        }
                        // 释放内存
                        unset($class, $value, $name, $index, $parameter, $exceptions);
                        return $isHas;
                    });
                    $this->call($handler, $parameters);
                } catch (Throwable $exception) {
                    // 把最新异常，插入的异常数组的最前面
                    array_unshift($exceptions, $exception);
                }
            }
        }
        /**
         * 处理完成事件
         */
        foreach ($this->completedHooks as $handler) {
            try {
                $this->call($handler);
            } catch (Throwable $e) {
                $exceptions[] = $exception;
            }
        }
        // 标记为0
        $this->runQuqueIndex = 0;
        // 标记正在运行事物
        $this->isRunTransactionQuque = false;
        // 开启事物前清空钩子
        $this->isClearHooksBeginAfter && $this->clearTransactionHooks();
        // 清空队列
        $this->transactionQuque = array();
        // 清空事物链接
        $this->transactionConnections = array();
        /**
         * 如果存在异常就抛出异常
         */
        if (!empty($exceptions)) {
            throw $exceptions[0];
        }
        // 返回本身，链式调用
        return $this;
    }
public function beginTransactionQuque()
    {
        // 开启事物前清空钩子
        $this->isClearHooksBeginBefore && $this->clearTransactionHooks();
        // 清空事物链接
        $this->transactionConnections = array();
        // 标记正在运行事物
        $this->isRunTransactionQuque = true;
        /**
         * 记录错误
         * @var Throwable[]|\Exception[] $exceptions
         */
        $exceptions = array();
        // 试图运行
        try {
            // 设置从最后一个开始运行
            $this->runQuqueIndex = 0;
            // 试图运行队列中最后一个事物
            $this->callTransactionQuque();
        } catch (\Exception $e) {
            // 保存异常
            $exceptions[] = $e;
        } catch (Throwable $e) {
            // 保存异常
            $exceptions[] = $e;
        }
        foreach ($this->transactionConnections as $connection){
            empty($exceptions) ? $connection->commit() : $connection->rollBack();
        }

        if (empty($exceptions)) {
            /**
             * 遍历提交事物
             * @var callable $handler
             */
            foreach ($this->commitHooks as $handler) {
                try {
                    $this->call($handler);
                } catch (Throwable $exception) {
                    $exceptions[] = $exception;
                }
            }
        } else {
            /**
             * 遍历回滚事物
             * @var callable $fn
             */
            foreach ($this->rollBackHooks as $handler) {
                try {
                    $arguments = array();
                    $parameters = new Parameters($handler, $arguments);
                    $parameters->mapNullParameters(function (&$value, $name, $index, ReflectionParameter $parameter) use (&$exceptions) {
                        $class = $parameter->getClass();
                        $isHas = false;
                        if (!empty($class)) {
                            foreach ($exceptions as $exception) {
                                if ($class->isInstance($exception)) {
                                    // 返回控制器
                                    $value = $exception;
                                    $isHas = true;
                                    break;
                                }
                            }
                        }
                        // 释放内存
                        unset($class, $value, $name, $index, $parameter, $exceptions);
                        return $isHas;
                    });
                    $this->call($handler, $parameters);
                } catch (Throwable $exception) {
                    // 把最新异常，插入的异常数组的最前面
                    array_unshift($exceptions, $exception);
                }
            }
        }
        /**
         * 处理完成事件
         */
        foreach ($this->completedHooks as $handler) {
            try {
                $this->call($handler);
            } catch (Throwable $e) {
                $exceptions[] = $exception;
            }
        }
        // 标记为0
        $this->runQuqueIndex = 0;
        // 标记正在运行事物
        $this->isRunTransactionQuque = false;
        // 开启事物前清空钩子
        $this->isClearHooksBeginAfter && $this->clearTransactionHooks();
        // 清空队列
        $this->transactionQuque = array();
        // 清空事物链接
        $this->transactionConnections = array();
        /**
         * 如果存在异常就抛出异常
         */
        if (!empty($exceptions)) {
            throw $exceptions[0];
        }
        // 返回本身，链式调用
        return $this;
    }
触发事物
@param null $data
@throws Throwable
@return $this