Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-18 18:06:24 +08:00
parent bc0fa6b8d5
commit e89062a2d7
+16 -17
View File
@@ -13,8 +13,8 @@ namespace Database;
use Database\Base\Getter;
use Database\Traits\HasBase;
use Exception;
use Kiri\Exception\NotFindClassException;
use Kiri;
use Kiri\Exception\NotFindClassException;
use Kiri\ToArray;
use ReflectionException;
use Swoole\Coroutine;
@@ -113,24 +113,23 @@ class Model extends Base\Model
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
}
Db::beginTransaction();
/** @var static $select */
$select = static::query()->where($condition)->first();
var_dump($select);
if (empty($select)) {
$select = new static();
$select->attributes = $attributes;
if (!$select->save()) {
var_dump('end rollback');
Db::rollback();
return $logger->addError($select->getLastError(), 'mysql');
try {
/** @var static $select */
$select = static::query()->where($condition)->first();
if (empty($select)) {
$select = new static();
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception($select->getLastError());
}
}
Db::commit();
return $select;
} catch (\Throwable $throwable) {
Db::rollback();
return $logger->addError($throwable->getMessage(), 'mysql');
}
var_dump('end commit');
Db::commit();
return $select;
}