钱包余额增加悲观锁
This commit is contained in:
@ -71,7 +71,7 @@ class BaseModel extends Model
|
||||
return $this->newQuery()->where($aWhere)->get($col);
|
||||
}
|
||||
|
||||
function setLockByPrimaryKey($id,$lock_type = self::LOCK_TYPE_FOR_UPDATE): Model|\Illuminate\Database\Eloquent\Builder|null
|
||||
function findByPrimaryKeyWithLock($id,$lock_type = self::LOCK_TYPE_FOR_UPDATE): Model|\Illuminate\Database\Eloquent\Builder|null
|
||||
{
|
||||
$model = $this->newQuery()->where($this->primaryKey, $id);
|
||||
if($lock_type == self::LOCK_TYPE_FOR_SHARE){
|
||||
@ -82,6 +82,17 @@ class BaseModel extends Model
|
||||
return $model->first();
|
||||
}
|
||||
|
||||
function findByWhereWithLock($id,$col=['*'],$lock_type = self::LOCK_TYPE_FOR_UPDATE): Model|\Illuminate\Database\Eloquent\Builder|null
|
||||
{
|
||||
$model = $this->newQuery()->where($this->primaryKey, $id);
|
||||
if($lock_type == self::LOCK_TYPE_FOR_SHARE){
|
||||
$model = $model->sharedLock();
|
||||
}elseif ($lock_type == self::LOCK_TYPE_FOR_UPDATE){
|
||||
$model = $model->lockForUpdate();
|
||||
}
|
||||
return $model->first($col);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user