Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-19 14:32:23 +08:00
parent cada515dc7
commit d5b58a1fc7
+17 -38
View File
@@ -112,29 +112,16 @@ class Model extends Base\Model
if (empty($attributes)) { if (empty($attributes)) {
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
} }
$model = new static(); /** @var static $select */
$select = static::query()->where($condition)->first();
$database = $model->getConnection()->beginTransaction(); if (empty($select)) {
try { $select = duplicate(static::class);
/** @var static $select */ $select->attributes = $attributes;
$select = static::query()->where($condition)->first(); if (!$select->save()) {
if (empty($select)) { throw new Exception($select->getLastError());
$select = $model;
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception($select->getLastError());
}
} }
$database->commit();
return $select;
} catch (\Throwable $throwable) {
$database->rollback();
return $logger->addError($throwable->getMessage(), 'mysql');
} }
return $select;
} }
@@ -150,24 +137,16 @@ class Model extends Base\Model
if (empty($attributes)) { if (empty($attributes)) {
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
} }
/** @var static $select */
$database = (new static())->getConnection()->beginTransaction(); $select = static::query()->where($condition)->first();
try { if (empty($select)) {
/** @var static $select */ $select = duplicate(static::class);
$select = static::query()->where($condition)->first();
if (empty($select)) {
$select = duplicate(static::class);
}
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception($select->getLastError());
}
$database->commit();
return $select;
} catch (\Throwable $throwable) {
$database->rollback();
return $logger->addError($throwable->getMessage(), 'mysql');
} }
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception($select->getLastError());
}
return $select;
} }