77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?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();
|
||
|
|
|
||
|
|
if (($where['keyword'] ?? '') !== '') {
|
||
|
|
$query->where(function (Builder $builder) use ($where) {
|
||
|
|
$keyword = '%' . $where['keyword'] . '%';
|
||
|
|
$builder->where('order_no', 'like', $keyword)
|
||
|
|
->orWhere('user_code', 'like', $keyword)
|
||
|
|
->orWhere('operator', 'like', $keyword)
|
||
|
|
->orWhere('remark', 'like', $keyword);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
}
|