Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-19 11:30:58 +08:00
parent 5d73bb2c33
commit cada515dc7
+9 -3
View File
@@ -114,8 +114,7 @@ class Model extends Base\Model
} }
$model = new static(); $model = new static();
$database = $model->getConnection(); $database = $model->getConnection()->beginTransaction();
$database->beginTransaction();
try { try {
/** @var static $select */ /** @var static $select */
$select = static::query()->where($condition)->first(); $select = static::query()->where($condition)->first();
@@ -152,6 +151,8 @@ class Model extends Base\Model
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
} }
$database = (new static())->getConnection()->beginTransaction();
try {
/** @var static $select */ /** @var static $select */
$select = static::query()->where($condition)->first(); $select = static::query()->where($condition)->first();
if (empty($select)) { if (empty($select)) {
@@ -159,9 +160,14 @@ class Model extends Base\Model
} }
$select->attributes = $attributes; $select->attributes = $attributes;
if (!$select->save()) { if (!$select->save()) {
$select = $logger->addError($select->getLastError(), 'mysql'); throw new Exception($select->getLastError());
} }
$database->commit();
return $select; return $select;
} catch (\Throwable $throwable) {
$database->rollback();
return $logger->addError($throwable->getMessage(), 'mysql');
}
} }