platform notify

This commit is contained in:
cano
2024-03-27 00:11:26 +08:00
parent 01e93acdd8
commit 4b47fe7250
21 changed files with 462 additions and 18 deletions

View File

@ -8,6 +8,13 @@ class BaseModel extends Model
{
public $timestamps = false;
const LOCK_TYPE_FOR_UPDATE = 1;
const LOCK_TYPE_FOR_SHARE = 2;
const LOCK_TYPE = [
self::LOCK_TYPE_FOR_UPDATE => '悲观锁',
self::LOCK_TYPE_FOR_SHARE => '乐观锁',
];
function checkColInFill($aItem)
{
foreach ($aItem as $key => $value) {
@ -64,6 +71,17 @@ 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
{
$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();
}
}