优化 AbstractModel::transaction

This commit is contained in:
kuaifan
2021-06-18 19:32:50 +08:00
parent f74b660d4a
commit 6a0bc37645
7 changed files with 86 additions and 97 deletions

View File

@@ -113,9 +113,8 @@ class AbstractModel extends Model
*/
public static function updateData($where, $updateArray)
{
$isUpdate = false;
if ($updateArray) {
$result = self::transaction(function () use ($updateArray, $where) {
self::transaction(function () use ($updateArray, $where) {
$list = static::where($where)->get();
if ($list->isNotEmpty()) {
foreach ($list AS $row) {
@@ -124,9 +123,9 @@ class AbstractModel extends Model
}
}
});
$isUpdate = Base::isSuccess($result);
return true;
}
return $isUpdate;
return false;
}
/**
@@ -154,7 +153,7 @@ class AbstractModel extends Model
/**
* 用于Model的事务处理
* @param \Closure $closure
* @return array
* @return mixed
*/
public static function transaction(\Closure $closure)
{