moshaorui 2 months ago
parent
commit
26bd2d7187

+ 11 - 11
app/Admin/Controllers/SiteAlbumController.php

@@ -94,8 +94,16 @@ class SiteAlbumController extends AdminController
                     event.preventDefault(); // 阻止默认的链接跳转行为
                     window.location.href = href; // 跳转到目标页面
                 });
+
+                folderId = $('select[name="folder_id"]').data('value');
+                if (folderId == id) {
+                    // 如果匹配,添加 jstree-clicked 类
+                    anchor.classList.add('jstree-clicked');
+                }
             });
-        }, 200);
+
+
+        }, 100);
         const firstCheckbox = document.querySelector('.vs-checkbox-primary');
         // 如果找到元素,则隐藏它
         if (firstCheckbox) {
@@ -107,6 +115,8 @@ class SiteAlbumController extends AdminController
             // 清空其值
             input.value = '';
         }
+
+
 JS
                 );
         });
@@ -406,16 +416,6 @@ function showHideTabs(fid) {
                 $('.nav-tabs .nav-item:eq(' + (Number(index) + 1) + ')').show(); // 使用字符串拼接
             });
 
-            // 处理下方的 tab-pane,限定在 .tab-content 内
-            // $('.tab-content .tab-pane').each(function(index) {
-            //     if (index > 0) { // 跳过第一个固定元素
-            //         $(this).hide();
-            //     }
-            // });
-            //
-            // tabIndexes.forEach(function(index) {
-            //     $('.tab-content .tab-pane:eq(' + (Number(index) + 1) + ')').show(); // 使用字符串拼接
-            // });
         }
 }
 JS

+ 15 - 2
app/Admin/Controllers/SiteAlbumFolderController.php

@@ -3,6 +3,7 @@
 namespace App\Admin\Controllers;
 
 use App\Admin\Repositories\SiteAlbumFolder;
+use App\Libraries\CommonHelper;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Show;
@@ -30,12 +31,17 @@ class SiteAlbumFolderController extends AdminController
     protected function grid()
     {
         return Grid::make(new SiteAlbumFolder(), function (Grid $grid) {
+            $grid->view('admin.grid-custom.table');
             $grid->column('id')->sortable();
             $grid->column('title')->display(function ($title) {
                 $level = $this->level; // 获取当前行的 level 字段值
                 $prefix = str_repeat('&nbsp; ', $level * 2). ' <i class="fa fa-angle-right"></i>&nbsp; '; // 生成 level * 3 个加号
                 return $prefix . ' ' . html_entity_decode($title); // 拼接加号和名称
-            });;
+            });
+            $grid->column('cover') ->display(function ($images) {
+                return CommonHelper::displayImage([$images],80);
+            });
+            $grid->column('folder_type')->using(admin_trans_array(config('dictionary.folder_type')))->label([0 => 'primary', 1 => 'success',]);
             $grid->column('parent_id');
             $grid->column('order')->sortable();
             $grid->column('enabled')->switch();
@@ -49,7 +55,6 @@ class SiteAlbumFolderController extends AdminController
         });
     }
 
-
     /**
      * Make a form builder.
      *
@@ -64,6 +69,14 @@ class SiteAlbumFolderController extends AdminController
                     return (int) $v;
                 });
             $form->text('title')->required();
+            $form->image('cover')
+                ->retainable()//禁止删OSS图
+                ->autoUpload()
+                ->uniqueName()
+                ->accept(config('admin.upload.oss_image.accept'))
+                ->maxSize(config('admin.upload.oss_image.max_size'))
+                ->dir(config("admin.upload.directory.image").'/uploads/'.date("Ymd"))
+                ->required();
             $form->radio('folder_type')
                 ->options(admin_trans_array(config('dictionary.folder_type')))
                 ->default(0)->required();

+ 6 - 6
app/Admin/Repositories/SiteAlbumFolder.php

@@ -22,7 +22,7 @@ class SiteAlbumFolder extends EloquentRepository
         // 获取模型对象
         $obj = $this->model();
         // 获取数据
-        $tree = $obj->orderBy('order', 'desc')->orderBy('id', 'desc')->get();
+        $tree = $obj->orderBy('order', 'desc')->orderBy('id', 'asc')->get();
         $treeData = $tree->toArray();
 
         // 构建树形结构
@@ -41,7 +41,7 @@ class SiteAlbumFolder extends EloquentRepository
     {
         if (!$closure) {
             $closure = function ($query) {
-                $query =  $query->where("enabled", 1)->orderBy('order', 'desc')->orderBy('id', 'desc');
+                $query =  $query->where("enabled", 1)->orderBy('order', 'desc')->orderBy('id', 'asc');
                 return $query;
             };
         }
@@ -61,7 +61,7 @@ class SiteAlbumFolder extends EloquentRepository
         if (!$closure) {
             $closure = function ($query) {
                 $query = $query->where('enabled', 1);
-                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
+                $query =  $query->orderBy('order', 'desc')->orderBy('id', 'asc');
                 return $query;
             };
         }
@@ -76,7 +76,7 @@ class SiteAlbumFolder extends EloquentRepository
         $result = self::selectOptions(function ($query) use ($ids) {
             $query = $query->wherein('id', $ids);
             $query = $query->where('enabled', 1);
-            $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
+            $query =  $query->orderBy('order', 'desc')->orderBy('id', 'asc');
             return $query;
         });
         unset($result[0]);
@@ -87,7 +87,7 @@ class SiteAlbumFolder extends EloquentRepository
     public static function siteAlbumFolderSelectOptionsAll() {
         $result = self::selectOptions(function ($query) {
             $query = $query->where('enabled', 1);
-            $query =  $query->orderBy('order', 'desc')->orderBy('id', 'desc');
+            $query =  $query->orderBy('order', 'desc')->orderBy('id', 'asc');
             return $query;
         });
         unset($result[0]);
@@ -126,7 +126,7 @@ class SiteAlbumFolder extends EloquentRepository
     public static function getAllFolderTabs()
     {
         $model = new Model();
-        $folders = $model->where('enabled', 1)->orderBy('order', 'desc')->orderBy('id', 'desc')->get();
+        $folders = $model->where('enabled', 1)->orderBy('order', 'desc')->orderBy('id', 'asc')->get();
         $tabs = [];
         foreach ($folders as $folder) {
             $tabs[$folder->id] = json_decode($folder->show_tabs);

+ 0 - 88
app/Console/Commands/ImportSpecificCategories.php

@@ -1,88 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use Carbon\Carbon;
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Log;
-
-/*
- * 导入产品分类
- * 运行命令:php artisan import:specific-categories
- */
-class ImportSpecificCategories extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'import:specific-categories';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Command description';
-
-    /**
-     * Execute the console command.
-     *
-     * @return int
-     */
-    public function handle()
-    {
-        exit;
-        // 获取主类记录
-        $mainCategories = DB::table('album_path')
-            ->whereIn('name', ['功能类产品', '屏幕保护膜', '智能切膜机'])
-            ->where('parent_id', 0)
-            ->get();
-
-        // 获取所有需要导入的类的ID
-        $idsToImport = [];
-        foreach ($mainCategories as $main) {
-            $idsToImport[] = $main->id;
-            $this->getSubCategories($main->id, $idsToImport);
-        }
-
-        // 获取所有需要导入的类
-        $categoriesToImport = DB::table('album_path')
-            ->whereIn('id', $idsToImport)
-            ->get();
-
-        // 插入到目标表并记录ID映射
-        $idMapping = [];
-        $tableMapping = [];
-        foreach ($categoriesToImport as $category) {
-            $parentId = $category->parent_id == 0 ? 0 : ($idMapping[$category->parent_id] ?? 0);
-            $newId = DB::table('base_product_category')->insertGetId([
-                'name' => $category->name,
-                'parent_id' => $parentId,
-                'order' => 0,
-                'enabled' => 1,
-                'created_at' => Carbon::now(),
-                'updated_at' => Carbon::now(),
-            ]);
-            $idMapping[$category->id] = $newId;
-            $tableMapping[] = ['base_product_category'=>$newId, 'album_path_id'=>$category->id];
-        }
-        // 记录映射关系
-        Log::info('tableMapping: '.json_encode($tableMapping));
-        $this->info('Categories imported successfully!');
-    }
-
-    // 递归获取所有子类ID
-    private function getSubCategories($parentId, &$ids)
-    {
-        $subCategories = DB::table('album_path')
-            ->where('parent_id', $parentId)
-            ->get();
-        foreach ($subCategories as $sub) {
-            $ids[] = $sub->id;
-            $this->getSubCategories($sub->id, $ids);
-        }
-    }
-}

+ 46 - 86
app/Console/Commands/SyncAlbumContent.php

@@ -35,100 +35,60 @@ class SyncAlbumContent extends Command
      */
     public function handle()
     {
-        exit;
-        $tableMapping = json_decode(' [{"base_product_category":11,"album_path_id":21},{"base_product_category":12,"album_path_id":22},{"base_product_category":13,"album_path_id":31},{"base_product_category":14,"album_path_id":35},{"base_product_category":15,"album_path_id":51},{"base_product_category":16,"album_path_id":64},{"base_product_category":17,"album_path_id":74},{"base_product_category":18,"album_path_id":79},{"base_product_category":19,"album_path_id":83},{"base_product_category":20,"album_path_id":114},{"base_product_category":21,"album_path_id":123},{"base_product_category":22,"album_path_id":141},{"base_product_category":23,"album_path_id":142},{"base_product_category":24,"album_path_id":143},{"base_product_category":25,"album_path_id":145},{"base_product_category":26,"album_path_id":151},{"base_product_category":27,"album_path_id":153},{"base_product_category":28,"album_path_id":154}]  ');
+        // 任务1: 同步 cover 字段
+        $albumPaths = DB::table('album_path')->get();
 
-        foreach ($tableMapping as $mapping) {
-            $mapping = (array)$mapping;
-            $albumContents = DB::table('album_content')
-                ->where('path_id', $mapping['album_path_id'])
-                ->get();
+        foreach ($albumPaths as $albumPath) {
+            DB::table('site_album_folder')
+                ->where('title', $albumPath->name)
+                ->update(['cover' => $albumPath->cover]);
+        }
 
-            foreach ($albumContents as $albumContent) {
-                // Insert or update base_product
-                $baseProduct = DB::table('base_product')
-                    ->where('title', $albumContent->model)
-                    ->first();
+        $this->info('Cover data synced successfully.');
 
-                $detail = json_decode($albumContent->detail);
-                $detail_cn = json_decode($albumContent->detail_cn);
+        // 任务2: 同步 album_content 数据到 site_album
+        $siteAlbumFolders = DB::table('site_album_folder')->get();
 
-                $content = "";
-                if ($detail) {
-                    foreach ($detail as $key => $value) {
-                        $content .= '<img src="'. $value. '" width="100%">';
-                    }
-                }
-//                if ($detail_cn) {
-//                    foreach ($detail_cn as $key => $value) {
-//                        $content .= '<img src="'. $value. '" width="100%">';
-//                    }
-//                }
+        foreach ($siteAlbumFolders as $siteAlbumFolder) {
+            $albumPath = DB::table('album_path')
+                ->where('name', $siteAlbumFolder->title)
+                ->first();
 
-                $baseProductId = 0;
-                $sku = '';
-                if (strpos($albumContent->model, "MTB-") === 0) {
-                    $sku = $albumContent->model;
-                }
-                if (!$baseProduct) {
-                    $baseProduct = DB::table('base_product')
-                        ->insertGetId([
-                            'title' => $albumContent->model,
-                            'category_id' => $mapping['base_product_category'],
-                            'sku' => $sku,
-                            'content' => $content,
-                            'created_at' => Carbon::now(),
-                            'updated_at' => Carbon::now(),
-                            'seo_title' => $albumContent->model,
-                        ]);
-                    $baseProductId = $baseProduct;
-                } else {
-                    DB::table('base_product')
-                        ->where('id', $baseProduct->id)
-                        ->update([
-                            'title' => $albumContent->model,
-                            'category_id' => $mapping['base_product_category'],
-                            'sku' => $sku,
-                            'content' => $content,
-                            'updated_at' => Carbon::now(),
-                            'seo_title' => $albumContent->model,
-                        ]);
-                    $baseProductId = $baseProduct->id;
-                }
-//                var_dump($baseProduct->id);
-//                exit;
+            if ($albumPath) {
+                $albumContents = DB::table('album_content')
+                    ->where('path_id', $albumPath->id)
+                    ->get();
 
-                // Insert base_product_image
-                $photos = json_decode($albumContent->photo, true);
-                if (is_array($photos)) {
-                    foreach ($photos as $photo) {
-                        DB::table('base_product_image')
-                            ->insert([
-                                'product_id' => $baseProductId,
-                                'image_url' => $photo,
-                                'created_at' => Carbon::now(),
-                                'updated_at' => Carbon::now(),
-                            ]);
+                foreach ($albumContents as $albumContent) {
+                    $cover = empty($albumContent->cover) ? [] : [$albumContent->cover];
+                    $cover = json_encode($cover);
+                    if (empty($albumContent->photo) == false) {
+                        $cover = $albumContent->photo;
                     }
-                }
+                    $detail = empty($albumContent->detail) ? '[]' : $albumContent->detail;
+                    $detail_cn = empty($albumContent->detail_cn) ? '[]' : $albumContent->detail_cn;
+                    $poster = empty($albumContent->poster) ? '[]' : $albumContent->poster;
+                    $cert = empty($albumContent->cert) ? '[]' : $albumContent->cert;
+                    $pdf = empty($albumContent->pdf) ? '[]' : $albumContent->pdf;
+                    $video = empty($albumContent->video) ? '[]' : $albumContent->video;
 
-                // Insert base_video
-                $videos = json_decode($albumContent->video, true);
-                if (is_array($videos)) {
-                    foreach ($videos as $video) {
-                        if (isset($video['video_src']) && $video['video_src'] !== '0' && !empty($video['video_src'])) {
-                            DB::table('base_video')
-                                ->insert([
-                                    'title' => $video['video_title'] ?? null,
-                                    'category_id' => 1,
-                                    'video_url' => $video['video_src'],
-                                    'cover_image' => $video['cover'] ?? null,
-                                    'enabled' => 1,
-                                    'created_at' => Carbon::now(),
-                                    'updated_at' => Carbon::now(),
-                                ]);
-                        }
-                    }
+                    DB::table('site_album')->insert([
+                        'folder_id' => $siteAlbumFolder->id,
+                        'order' => 0, // 你可以根据需要设置排序
+                        'title' => $albumContent->model,
+                        'model' => $albumContent->model,
+                        'parameters' => null, // 你可以根据需要设置参数
+                        'cover' => $cover,
+                        'en_detail' => $detail,
+                        'cn_detail' => $detail_cn,
+                        'poster' => $poster,
+                        'cert' => $cert,
+                        'pdf' => $pdf,
+                        'video' => $video,
+                        'created_at' => now(),
+                        'updated_at' => now(),
+                        'enabled' => 1,
+                    ]);
                 }
             }
         }