Реализация смены статуса
Добавлен move метод Правка в поиске
This commit is contained in:
@@ -6,6 +6,51 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArchiveHistory extends Model
|
||||
{
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($archiveHistory) {
|
||||
$archiveHistory->updateArchiveInfoStatus();
|
||||
});
|
||||
|
||||
static::updated(function ($archiveHistory) {
|
||||
$archiveHistory->updateArchiveInfoStatus();
|
||||
});
|
||||
}
|
||||
|
||||
public function updateArchiveInfoStatus()
|
||||
{
|
||||
// Получаем связанную модель через морф
|
||||
$historyable = $this->historyable;
|
||||
|
||||
if (!$historyable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверяем, есть ли у модели архивная информация
|
||||
if (method_exists($historyable, 'archiveInfo') && $historyable->archiveInfo) {
|
||||
$historyable->archiveInfo->update([
|
||||
'status_id' => $this->determineStatusId()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function determineStatusId()
|
||||
{
|
||||
if ($this->has_lost) {
|
||||
return 4; // Утерян
|
||||
}
|
||||
|
||||
if ($this->issue_at && !$this->return_at) {
|
||||
return 3; // Выдан
|
||||
}
|
||||
|
||||
if ($this->return_at) {
|
||||
return 2; // В архиве
|
||||
}
|
||||
|
||||
return 2; // По умолчанию
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'historyable_type',
|
||||
'historyable_id',
|
||||
|
||||
@@ -18,4 +18,9 @@ class ArchiveInfo extends Model
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo(ArchiveStatus::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +43,19 @@ class SttMedicalHistory extends Model
|
||||
{
|
||||
return $query->where(function($q) use ($searchText) {
|
||||
if (is_numeric($searchText)) {
|
||||
$q->where('medcardnum', 'ILIKE', "$searchText%");
|
||||
$q->where('medcardnum', 'ILIKE', "$searchText");
|
||||
} else {
|
||||
// Ищем по всем частям ФИО
|
||||
$q->where('family', 'ILIKE', "%$searchText%")
|
||||
->orWhere('name', 'ILIKE', "%$searchText%")
|
||||
->orWhere('ot', 'ILIKE', "%$searchText%");
|
||||
// Ищем в объединенном ФИО и в отдельных полях
|
||||
$searchPattern = "%{$searchText}%";
|
||||
|
||||
$q->where(function($subQ) use ($searchPattern) {
|
||||
// Поиск в объединенной строке
|
||||
$subQ->whereRaw("CONCAT(family, ' ', name, ' ', COALESCE(ot, '')) ILIKE ?", [$searchPattern])
|
||||
// И дополнительно в отдельных полях для точности
|
||||
->orWhere('family', 'ILIKE', $searchPattern)
|
||||
->orWhere('name', 'ILIKE', $searchPattern)
|
||||
->orWhere('ot', 'ILIKE', $searchPattern);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user