| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace UCore\Db;
- use Illuminate\Support\Facades\DB;
- use UCore\Helper\Logger;
- /**
- * 数据库助手类
- */
- class Helper
- {
- /**
- * 检查是否已经开启事务
- *
- * @return void
- * @throws \LogicException
- */
- static public function check_tr()
- {
- $level = DB::transactionLevel();
- if ($level === 0) {
- $w =( debug_backtrace()[1]['file'] ??' file '). ':' . (debug_backtrace()[1]['line']??'line');
- Logger::error("check_tr - transaction level is 0 没有开启事务" . $w);
- // 没有开启事务
- throw new \LogicException("transaction level is 0");
- }
- if ($level > 1) {
- // 事务嵌套
- Logger::error("check_tr - transaction level >1 事务嵌套 ");
- throw new \LogicException("transaction level > 1");
- }
- }
- }
|