|
@@ -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,
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|
|
|
}
|