|
@@ -13,6 +13,7 @@ use App\Models\SiteAlbumLog;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
+use ZipArchive;
|
|
|
|
|
|
|
|
|
class HomeController extends Controller
|
|
@@ -30,11 +31,25 @@ class HomeController extends Controller
|
|
|
*/
|
|
|
public function gallery(Request $request)
|
|
|
{
|
|
|
- $folder_id = $request->input('fid',$this->getFoldersTreeFirstId());
|
|
|
- $father_id = $this->getFoldersTreeFatherId($folder_id);
|
|
|
- $folder = SiteAlbumFolder::find($folder_id);
|
|
|
- $albums = SiteAlbum::where('folder_id', $folder_id)->get();
|
|
|
- $albums = $albums->toArray();
|
|
|
+ $search = $request->input('search', '');
|
|
|
+ if ($search) {
|
|
|
+ $search = '%' . $search . '%';
|
|
|
+ $albums = SiteAlbum::where('title', 'like', $search)->get();
|
|
|
+ $title = '搜索结果';
|
|
|
+ $folder_id = 0;
|
|
|
+ $father_id = 0;
|
|
|
+ if ($albums) {
|
|
|
+ $albums = $albums->toArray();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $folder_id = $request->input('fid',$this->getFoldersTreeFirstId());
|
|
|
+ $father_id = $this->getFoldersTreeFatherId($folder_id);
|
|
|
+ $folder = SiteAlbumFolder::find($folder_id);
|
|
|
+ $albums = SiteAlbum::where('folder_id', $folder_id)->get();
|
|
|
+ $albums = $albums->toArray();
|
|
|
+ $title = $folder->title;
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($albums as $key => $album) {
|
|
|
$cover = json_decode($album['cover']);
|
|
|
foreach ($cover as $k => $v) {
|
|
@@ -49,7 +64,7 @@ class HomeController extends Controller
|
|
|
return view('gallery',
|
|
|
[
|
|
|
'foldersTree' => $this->foldersTree,
|
|
|
- 'folderName'=> $folder->title,
|
|
|
+ 'folderName'=> $title,
|
|
|
'folder_id' => $folder_id,
|
|
|
'father_id' => $father_id,
|
|
|
'albums' => $albums
|
|
@@ -70,7 +85,7 @@ class HomeController extends Controller
|
|
|
switch ($value) {
|
|
|
case '0':
|
|
|
$column = 'cover';
|
|
|
- $title = '主页';
|
|
|
+ $title = '主图';
|
|
|
break;
|
|
|
case '1':
|
|
|
$column = 'en_detail';
|
|
@@ -117,6 +132,57 @@ class HomeController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * 下载全部
|
|
|
+ */
|
|
|
+
|
|
|
+ public function downloadAll(Request $request)
|
|
|
+ {
|
|
|
+ $id = $request->input('id', 0);
|
|
|
+ $tab = $request->input('tab', 'cover');
|
|
|
+ $album = SiteAlbum::find($id);
|
|
|
+
|
|
|
+ if ($album) {
|
|
|
+ $album = $album->toArray();
|
|
|
+
|
|
|
+ if (isset($album[$tab])) {
|
|
|
+ $files = json_decode($album[$tab]);
|
|
|
+ $fileUrls = [];
|
|
|
+
|
|
|
+ // 获取所有图片的 URL
|
|
|
+ foreach ($files as $key => $value) {
|
|
|
+ $fileUrl = ossUrl($value); // 获取完整的图片 URL
|
|
|
+ $fileUrls[] = $fileUrl; // 将图片 URL 存入数组
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个临时 ZIP 文件
|
|
|
+ $zipFileName = 'album_' . $id . '_' . $tab . '.zip';
|
|
|
+ $zipPath = storage_path('app/' . $zipFileName);
|
|
|
+ $zip = new ZipArchive;
|
|
|
+
|
|
|
+ if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) {
|
|
|
+ foreach ($fileUrls as $fileUrl) {
|
|
|
+ $fileContent = file_get_contents($fileUrl); // 下载图片内容
|
|
|
+ $fileName = basename($fileUrl); // 获取文件名
|
|
|
+ $zip->addFromString($fileName, $fileContent); // 将图片添加到 ZIP 文件中
|
|
|
+ }
|
|
|
+
|
|
|
+ $zip->close();
|
|
|
+
|
|
|
+ // 提供 ZIP 文件下载
|
|
|
+ return response()->download($zipPath, $zipFileName)->deleteFileAfterSend(true);
|
|
|
+ } else {
|
|
|
+ return response()->json(['error' => '无法创建 ZIP 文件'], 500);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return response()->json(['error' => '未找到指定的 Tab 数据'], 404);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return response()->json(['error' => '未找到相册'], 404);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/*
|
|
|
* 更新日志
|