49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use App\Models\Device;
|
|
use App\Filters\Admin\DeviceFilter;
|
|
|
|
/**
|
|
* @method Device getModel()
|
|
* @method Device|\Illuminate\Database\Query\Builder query()
|
|
*/
|
|
class DeviceService extends BaseService
|
|
{
|
|
protected string $modelName = Device::class;
|
|
|
|
protected array $withRelationships = ['factory'];
|
|
|
|
protected string $modelFilterName = DeviceFilter::class;
|
|
|
|
public function list()
|
|
{
|
|
$query = $this->listQuery();
|
|
|
|
$items = (clone $query)->paginate(request()->input('perPage', 20))->items();
|
|
$base = settings()->get('rtsp_url');
|
|
if (request('_type') == Device::TYPE_MONITOR) {
|
|
$history = request('_mode') === 'history';
|
|
$date = explode(',', request('date'));
|
|
$start = data_get($date, 0);
|
|
$end = data_get($date, 1);
|
|
foreach ($items as &$item) {
|
|
$url = data_get($item->extends, $history ? 'rtsp_history' : 'rtsp_url');
|
|
$src = null;
|
|
if ($base && $url) {
|
|
// 查看历史监控
|
|
if ($history && $start && $end) {
|
|
$url .= '?start=' . date('Y-m-d', $start) . '&end=' . data('Y-m-d', $end);
|
|
}
|
|
$src = $base . base64_encode($url);
|
|
}
|
|
$item->src = $src;
|
|
}
|
|
}
|
|
$total = (clone $query)->count();
|
|
|
|
return compact('items', 'total');
|
|
}
|
|
}
|