Files
MrleeAdmin/backend/plugin/produce/app/dao/ScanDataDao.php
T

76 lines
2.2 KiB
PHP
Raw Normal View History

2026-08-31 13:16:46 +08:00
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\ScanData;
class ScanDataDao extends BaseDao
{
protected function setModel(): string
{
return ScanData::class;
}
protected function getKeywordFields(): array
{
return ['order_no', 'user_code', 'operator', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['process', 'step', 'status']));
$order = $order ?: 'scan_time desc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
foreach (['order_no', 'user_code', 'operator', 'remark'] as $field) {
$value = trim((string) ($where['LIKE_' . $field] ?? ''));
if ($value === '') {
continue;
}
$query->where($field, 'like', '%' . $value . '%');
2026-08-31 13:16:46 +08:00
}
if (($where['process_id'] ?? '') !== '') {
$query->where('process_id', $where['process_id']);
}
if (($where['step_id'] ?? '') !== '') {
$query->where('step_id', $where['step_id']);
}
if (($where['status_id'] ?? '') !== '') {
$query->where('status_id', $where['status_id']);
}
if (($where['scan_result'] ?? '') !== '') {
$query->where('scan_result', $where['scan_result']);
}
if (!empty($where['scan_time_range']) && is_array($where['scan_time_range']) && count($where['scan_time_range']) === 2) {
$query->whereBetween('scan_time', [strtotime((string) $where['scan_time_range'][0]), strtotime((string) $where['scan_time_range'][1])]);
}
return $query;
}
}