|
@@ -1,126 +0,0 @@
|
|
|
-<?php
|
|
|
|
|
-
|
|
|
|
|
-namespace App\Module\File\Repositories;
|
|
|
|
|
-
|
|
|
|
|
-use App\Module\File\Models\FileFile;
|
|
|
|
|
-use App\Module\File\Models\FileImg;
|
|
|
|
|
-use App\Module\File\Models\FileTemplate;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * 文件仓库类
|
|
|
|
|
- *
|
|
|
|
|
- * 提供文件数据的访问和操作
|
|
|
|
|
- */
|
|
|
|
|
-class FileRepository
|
|
|
|
|
-{
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据ID获取文件
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $id 文件ID
|
|
|
|
|
- * @return FileFile|null 文件模型
|
|
|
|
|
- */
|
|
|
|
|
- public function getFileById(int $id)
|
|
|
|
|
- {
|
|
|
|
|
- return FileFile::find($id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据ID获取图片
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $id 图片ID
|
|
|
|
|
- * @return FileImg|null 图片模型
|
|
|
|
|
- */
|
|
|
|
|
- public function getImageById(int $id)
|
|
|
|
|
- {
|
|
|
|
|
- return FileImg::find($id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据ID获取模板
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $id 模板ID
|
|
|
|
|
- * @return FileTemplate|null 模板模型
|
|
|
|
|
- */
|
|
|
|
|
- public function getTemplateById(int $id)
|
|
|
|
|
- {
|
|
|
|
|
- return FileTemplate::find($id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据标识获取模板
|
|
|
|
|
- *
|
|
|
|
|
- * @param string $unid 模板标识
|
|
|
|
|
- * @return FileTemplate|null 模板模型
|
|
|
|
|
- */
|
|
|
|
|
- public function getTemplateByUnid(string $unid)
|
|
|
|
|
- {
|
|
|
|
|
- return FileTemplate::where('unid', $unid)->first();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取用户的图片列表
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $userId 用户ID
|
|
|
|
|
- * @param int $page 页码
|
|
|
|
|
- * @param int $pageSize 每页数量
|
|
|
|
|
- * @return \Illuminate\Pagination\LengthAwarePaginator 分页结果
|
|
|
|
|
- */
|
|
|
|
|
- public function getUserImages(int $userId, int $page = 1, int $pageSize = 20)
|
|
|
|
|
- {
|
|
|
|
|
- return FileImg::where('user_id', $userId)
|
|
|
|
|
- ->orderBy('id', 'desc')
|
|
|
|
|
- ->paginate($pageSize, ['*'], 'page', $page);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取关联的图片列表
|
|
|
|
|
- *
|
|
|
|
|
- * @param string $reType 关联类型
|
|
|
|
|
- * @param int $reId 关联ID
|
|
|
|
|
- * @return \Illuminate\Database\Eloquent\Collection 图片集合
|
|
|
|
|
- */
|
|
|
|
|
- public function getRelatedImages(string $reType, int $reId)
|
|
|
|
|
- {
|
|
|
|
|
- return FileImg::where('re_type', $reType)
|
|
|
|
|
- ->where('re_id', $reId)
|
|
|
|
|
- ->orderBy('id', 'desc')
|
|
|
|
|
- ->get();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取关联的文件列表
|
|
|
|
|
- *
|
|
|
|
|
- * @param string $reType 关联类型
|
|
|
|
|
- * @param int $reId 关联ID
|
|
|
|
|
- * @return \Illuminate\Database\Eloquent\Collection 文件集合
|
|
|
|
|
- */
|
|
|
|
|
- public function getRelatedFiles(string $reType, int $reId)
|
|
|
|
|
- {
|
|
|
|
|
- return FileFile::where('re_type', $reType)
|
|
|
|
|
- ->where('re_id', $reId)
|
|
|
|
|
- ->orderBy('id', 'desc')
|
|
|
|
|
- ->get();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取模板列表
|
|
|
|
|
- *
|
|
|
|
|
- * @param string $group 分组
|
|
|
|
|
- * @param int $status 状态
|
|
|
|
|
- * @return \Illuminate\Database\Eloquent\Collection 模板集合
|
|
|
|
|
- */
|
|
|
|
|
- public function getTemplates(string $group = '', int $status = FileTemplate::STATUS_1)
|
|
|
|
|
- {
|
|
|
|
|
- $query = FileTemplate::query();
|
|
|
|
|
-
|
|
|
|
|
- if (!empty($group)) {
|
|
|
|
|
- $query->where('group', $group);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ($status !== null) {
|
|
|
|
|
- $query->where('status', $status);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $query->orderBy('id', 'desc')->get();
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|