70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\File\Repositories;
|
|
|
|
use App\Core\Repository;
|
|
use App\Models\File\File as Model;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use App\Domains\File\Services\FileService;
|
|
|
|
class FileRepository extends Repository
|
|
{
|
|
/**
|
|
* 是否关闭缓存
|
|
*
|
|
* @var boolean
|
|
*/
|
|
protected $cacheSkip = false;
|
|
|
|
/**
|
|
* 是否开启数据转化
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $needTransform = true;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fieldSearchable = [
|
|
'id' => '=',
|
|
'created_at' => 'like',
|
|
];
|
|
|
|
public function model()
|
|
{
|
|
return Model::class;
|
|
}
|
|
|
|
/**
|
|
* 数据格式化
|
|
*
|
|
* @param mixed $result
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function transform($model)
|
|
{
|
|
$model->url = cdn($model->disk, $model->filename, $model->created_at);
|
|
$model->cover = $model->thumb ? cdn($model->disk, FileService::getThumb($model->filename), $model->created_at) : '';
|
|
return $model;
|
|
}
|
|
|
|
public function withConditions(array $conditions =[])
|
|
{
|
|
if (isset($conditions['ids'])) {
|
|
$this->model = $this->model->whereIn('id', $conditions['ids']);
|
|
}
|
|
|
|
if (isset($conditions['creator'])) {
|
|
$this->model = $this->model->where('creator', $conditions['creator']);
|
|
}
|
|
|
|
if (isset($conditions['type'])) {
|
|
$this->model = $this->model->where('type', $conditions['type']);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|