|
|
@ -697,47 +697,64 @@ class ContentController extends BaseController |
|
|
|
|
|
|
|
|
Db::startTrans(); |
|
|
Db::startTrans(); |
|
|
try{ |
|
|
try{ |
|
|
// 查询栏目
|
|
|
|
|
|
|
|
|
// 查询目标语言栏目,建立 category_map → 目标栏目ID 的映射
|
|
|
$Category = new Category(); |
|
|
$Category = new Category(); |
|
|
$categories = $Category->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'website_id'=>$param['website_id'],'lang'=>$param['to']],'id asc','id,category_map')['data']; |
|
|
$categories = $Category->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'website_id'=>$param['website_id'],'lang'=>$param['to']],'id asc','id,category_map')['data']; |
|
|
// 处理 categoryMap,检查重复的 category_map 值
|
|
|
|
|
|
$categoryMapData = array_column($categories, 'category_map'); |
|
|
$categoryMapData = array_column($categories, 'category_map'); |
|
|
$duplicateMaps = array_filter(array_count_values($categoryMapData), function($v) { return $v > 1; }); |
|
|
$duplicateMaps = array_filter(array_count_values($categoryMapData), function($v) { return $v > 1; }); |
|
|
if (!empty($duplicateMaps)) { |
|
|
if (!empty($duplicateMaps)) { |
|
|
\think\facade\Log::warning('copyToOtherLang: 发现重复的 category_map 值: ' . implode(',', array_keys($duplicateMaps))); |
|
|
\think\facade\Log::warning('copyToOtherLang: 发现重复的 category_map 值: ' . implode(',', array_keys($duplicateMaps))); |
|
|
} |
|
|
} |
|
|
|
|
|
// category_map(源语言栏目ID) → 目标语言栏目ID
|
|
|
$categoryMap = array_combine($categoryMapData, array_column($categories,'id')); |
|
|
$categoryMap = array_combine($categoryMapData, array_column($categories,'id')); |
|
|
|
|
|
|
|
|
|
|
|
// 清理目标语言已有的关联数据,防止重复插入
|
|
|
|
|
|
$existingTargetSubIds = Db::name('sub_content') |
|
|
|
|
|
->where('lang', $param['to']) |
|
|
|
|
|
->where('seller_id', $this->admin['seller_id']) |
|
|
|
|
|
->column('id'); |
|
|
|
|
|
if (!empty($existingTargetSubIds)) { |
|
|
|
|
|
Db::name('category_sub_content')->where('sub_content_id', 'in', $existingTargetSubIds)->delete(); |
|
|
|
|
|
Db::name('tag_sub_content')->where('sub_content_id', 'in', $existingTargetSubIds)->delete(); |
|
|
|
|
|
Db::name('inner_chart_sub_content')->where('sub_content_id', 'in', $existingTargetSubIds)->delete(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 查找模型
|
|
|
// 查找模型
|
|
|
$Module = new Module(); |
|
|
$Module = new Module(); |
|
|
$modules = $Module->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id']],'id asc','id,table')['data']; |
|
|
$modules = $Module->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id']],'id asc','id,table')['data']; |
|
|
$SubContent = new SubContent(); |
|
|
$SubContent = new SubContent(); |
|
|
|
|
|
|
|
|
|
|
|
// 源语言sub_content_id → 目标语言sub_content_id 的映射
|
|
|
|
|
|
$subIdMap = []; |
|
|
|
|
|
// 源语言主表id → 目标语言主表id 的映射
|
|
|
|
|
|
$mainIdMap = []; |
|
|
|
|
|
|
|
|
foreach($modules as $module){ |
|
|
foreach($modules as $module){ |
|
|
// 副表的内容
|
|
|
|
|
|
$content = $SubContent -> getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'module_id'=>$module['id'],'lang'=>$param['from'],'is_del'=>1],'id asc')['data']; |
|
|
|
|
|
|
|
|
// 获取源语言副表内容
|
|
|
|
|
|
$content = $SubContent->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'module_id'=>$module['id'],'lang'=>$param['from'],'is_del'=>1],'id asc')['data']; |
|
|
if(empty($content)){ |
|
|
if(empty($content)){ |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
// 主表内容
|
|
|
|
|
|
|
|
|
// 源语言sub_content ID列表
|
|
|
$contentIds = array_column($content,'id'); |
|
|
$contentIds = array_column($content,'id'); |
|
|
// 主表ID累加映射
|
|
|
|
|
|
$subIds = $this->getMapIds('sub_content',$contentIds); |
|
|
|
|
|
|
|
|
// 源语言主表内容
|
|
|
$mainContent = Db::name($module['table'])->where([['sub_id','in',$contentIds]])->select()->toArray(); |
|
|
$mainContent = Db::name($module['table'])->where([['sub_id','in',$contentIds]])->select()->toArray(); |
|
|
// 附表ID累加映射
|
|
|
|
|
|
$mainIds = $this->getMapIds($module['table'],array_column($mainContent,'id')); |
|
|
|
|
|
$tempContent = []; |
|
|
|
|
|
|
|
|
// 源语言主表 sub_id → 主表记录 的映射
|
|
|
|
|
|
$mainContentBySubId = []; |
|
|
|
|
|
foreach($mainContent as $mc){ |
|
|
|
|
|
$mainContentBySubId[$mc['sub_id']] = $mc; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ========== 逐条插入副表(sub_content),获取实际新ID ==========
|
|
|
foreach($content as $item){ |
|
|
foreach($content as $item){ |
|
|
|
|
|
$originalId = $item['id']; |
|
|
$item['category_id'] = $categoryMap[$item['category_id']] ?? 0; |
|
|
$item['category_id'] = $categoryMap[$item['category_id']] ?? 0; |
|
|
$item['main_id'] = $mainIds[$item['main_id']] ?? 0; |
|
|
|
|
|
|
|
|
$item['main_id'] = 0; // 先设为0,插入主表后再回填
|
|
|
$item['lang'] = $param['to']; |
|
|
$item['lang'] = $param['to']; |
|
|
$item['sub_id_map'] = $item['id']; |
|
|
|
|
|
|
|
|
$item['sub_id_map'] = $originalId; |
|
|
$subCategoryIds = !empty($item['sub_category_ids']) ? explode(',',$item['sub_category_ids']) : []; |
|
|
$subCategoryIds = !empty($item['sub_category_ids']) ? explode(',',$item['sub_category_ids']) : []; |
|
|
$subCategoryIds = array_map(function($v) use($categoryMap){ |
|
|
$subCategoryIds = array_map(function($v) use($categoryMap){ |
|
|
if(!empty($categoryMap[$v])){ |
|
|
|
|
|
return $categoryMap[$v]; |
|
|
|
|
|
}else{ |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $categoryMap[$v] ?? ''; |
|
|
},$subCategoryIds); |
|
|
},$subCategoryIds); |
|
|
$item['sub_category_ids'] = implode(',', array_filter($subCategoryIds)); |
|
|
$item['sub_category_ids'] = implode(',', array_filter($subCategoryIds)); |
|
|
unset($item['id']); |
|
|
unset($item['id']); |
|
|
@ -748,44 +765,58 @@ class ContentController extends BaseController |
|
|
if(!empty($item['update_time']) && !is_numeric($item['update_time'])){ |
|
|
if(!empty($item['update_time']) && !is_numeric($item['update_time'])){ |
|
|
$item['update_time'] = strtotime($item['update_time']); |
|
|
$item['update_time'] = strtotime($item['update_time']); |
|
|
} |
|
|
} |
|
|
$tempContent[] = $item; |
|
|
|
|
|
|
|
|
$newSubId = Db::name('sub_content')->insertGetId($item); |
|
|
|
|
|
if($newSubId > 0){ |
|
|
|
|
|
$subIdMap[$originalId] = $newSubId; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
$res = Db::name('sub_content')->insertAll($tempContent); |
|
|
|
|
|
var_dump(123); |
|
|
|
|
|
$tmpMainContent = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 逐条插入主表,获取实际新ID ==========
|
|
|
foreach($mainContent as $value){ |
|
|
foreach($mainContent as $value){ |
|
|
$value['sub_id'] = $subIds[$value['sub_id']] ?? 0; |
|
|
|
|
|
|
|
|
$originalMainId = $value['id']; |
|
|
|
|
|
$originalSubId = $value['sub_id']; |
|
|
|
|
|
$value['sub_id'] = $subIdMap[$originalSubId] ?? 0; |
|
|
$value['lang'] = $param['to']; |
|
|
$value['lang'] = $param['to']; |
|
|
$value['lang_pid'] = $value['id'] ?? 0; |
|
|
|
|
|
|
|
|
$value['lang_pid'] = $originalMainId; |
|
|
unset($value['id']); |
|
|
unset($value['id']); |
|
|
// 时间字段转回时间戳
|
|
|
|
|
|
if(!empty($value['create_time']) && !is_numeric($value['create_time'])){ |
|
|
if(!empty($value['create_time']) && !is_numeric($value['create_time'])){ |
|
|
$value['create_time'] = strtotime($value['create_time']); |
|
|
$value['create_time'] = strtotime($value['create_time']); |
|
|
} |
|
|
} |
|
|
if(!empty($value['update_time']) && !is_numeric($value['update_time'])){ |
|
|
if(!empty($value['update_time']) && !is_numeric($value['update_time'])){ |
|
|
$value['update_time'] = strtotime($value['update_time']); |
|
|
$value['update_time'] = strtotime($value['update_time']); |
|
|
} |
|
|
} |
|
|
$tmpMainContent[] = $value; |
|
|
|
|
|
|
|
|
$newMainId = Db::name($module['table'])->insertGetId($value); |
|
|
|
|
|
if($newMainId > 0){ |
|
|
|
|
|
$mainIdMap[$originalMainId] = $newMainId; |
|
|
|
|
|
// 回填 sub_content 的 main_id
|
|
|
|
|
|
if($value['sub_id'] > 0){ |
|
|
|
|
|
Db::name('sub_content')->where('id', $value['sub_id'])->update(['main_id' => $newMainId]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
$res2 = Db::name($module['table'])->insertAll($tmpMainContent); |
|
|
|
|
|
// 栏目和内容关系
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 插入栏目和内容关系 ==========
|
|
|
$CateSub = Db::name('category_sub_content')->where([['sub_content_id','in',$contentIds]])->select()->toArray(); |
|
|
$CateSub = Db::name('category_sub_content')->where([['sub_content_id','in',$contentIds]])->select()->toArray(); |
|
|
$tmpCategorySub = []; |
|
|
|
|
|
foreach($CateSub as $val){ |
|
|
foreach($CateSub as $val){ |
|
|
$val['category_id'] = $categoryMap[$val['category_id']] ?? 0; |
|
|
|
|
|
$val['sub_content_id'] = $subIds[$val['sub_content_id']] ?? 0; |
|
|
|
|
|
unset($val['id']); |
|
|
|
|
|
$tmpCategorySub[] = $val; |
|
|
|
|
|
|
|
|
$newCategoryId = $categoryMap[$val['category_id']] ?? 0; |
|
|
|
|
|
$newSubContentId = $subIdMap[$val['sub_content_id']] ?? 0; |
|
|
|
|
|
if($newSubContentId > 0){ |
|
|
|
|
|
Db::name('category_sub_content')->insert([ |
|
|
|
|
|
'seller_id' => $val['seller_id'] ?? $this->admin['seller_id'], |
|
|
|
|
|
'website_id' => $val['website_id'] ?? null, |
|
|
|
|
|
'category_id' => $newCategoryId, |
|
|
|
|
|
'sub_content_id' => $newSubContentId, |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
$res3 = Db::name('category_sub_content')->insertAll($tmpCategorySub); |
|
|
|
|
|
} |
|
|
} |
|
|
// 导航分类
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 导航分类 ==========
|
|
|
$NavCate = new NavCate(); |
|
|
$NavCate = new NavCate(); |
|
|
$navCate = $NavCate->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'lang'=>$param['from']],'id asc')['data']; |
|
|
$navCate = $NavCate->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'lang'=>$param['from']],'id asc')['data']; |
|
|
$navCateIds = array_column($navCate,'id'); |
|
|
|
|
|
$navCateIdMap = $this->getMapIds('nav_cate',$navCateIds); |
|
|
|
|
|
$tmpNavCate =[]; |
|
|
|
|
|
|
|
|
$navCateIdMap = []; |
|
|
foreach($navCate as $v){ |
|
|
foreach($navCate as $v){ |
|
|
|
|
|
$originalId = $v['id']; |
|
|
$v['lang'] = $param['to']; |
|
|
$v['lang'] = $param['to']; |
|
|
unset($v['id']); |
|
|
unset($v['id']); |
|
|
if(!empty($v['create_time']) && !is_numeric($v['create_time'])){ |
|
|
if(!empty($v['create_time']) && !is_numeric($v['create_time'])){ |
|
|
@ -794,21 +825,22 @@ class ContentController extends BaseController |
|
|
if(!empty($v['update_time']) && !is_numeric($v['update_time'])){ |
|
|
if(!empty($v['update_time']) && !is_numeric($v['update_time'])){ |
|
|
$v['update_time'] = strtotime($v['update_time']); |
|
|
$v['update_time'] = strtotime($v['update_time']); |
|
|
} |
|
|
} |
|
|
$tmpNavCate[] = $v; |
|
|
|
|
|
|
|
|
$newNavCateId = Db::name('nav_cate')->insertGetId($v); |
|
|
|
|
|
if($newNavCateId > 0){ |
|
|
|
|
|
$navCateIdMap[$originalId] = $newNavCateId; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
$res4 = Db::name('nav_cate')->insertAll($tmpNavCate); |
|
|
|
|
|
// 导航
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 导航 ==========
|
|
|
$Nav = new Nav(); |
|
|
$Nav = new Nav(); |
|
|
$navs = $Nav->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'lang'=>$param['from']],'id asc')['data']; |
|
|
$navs = $Nav->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id'],'lang'=>$param['from']],'id asc')['data']; |
|
|
$navIds = array_column($navs,'id'); |
|
|
|
|
|
$navMapIds = $this->getMapIds('nav',$navIds); |
|
|
|
|
|
$navMapIds[0]=0; |
|
|
|
|
|
$tmpNav = []; |
|
|
|
|
|
|
|
|
$navIdMap = [0 => 0]; |
|
|
foreach($navs as $nav){ |
|
|
foreach($navs as $nav){ |
|
|
|
|
|
$originalId = $nav['id']; |
|
|
$nav['lang'] = $param['to']; |
|
|
$nav['lang'] = $param['to']; |
|
|
$nav['nav_cate_id'] = $navCateIdMap[$nav['nav_cate_id']] ?? 0; |
|
|
$nav['nav_cate_id'] = $navCateIdMap[$nav['nav_cate_id']] ?? 0; |
|
|
$nav['category_id'] = $categoryMap[$nav['category_id']] ?? 0; |
|
|
$nav['category_id'] = $categoryMap[$nav['category_id']] ?? 0; |
|
|
$nav['parent_id'] = $navMapIds[$nav['parent_id']] ?? 0; |
|
|
|
|
|
|
|
|
$nav['parent_id'] = $navIdMap[$nav['parent_id']] ?? 0; |
|
|
unset($nav['id']); |
|
|
unset($nav['id']); |
|
|
if(!empty($nav['create_time']) && !is_numeric($nav['create_time'])){ |
|
|
if(!empty($nav['create_time']) && !is_numeric($nav['create_time'])){ |
|
|
$nav['create_time'] = strtotime($nav['create_time']); |
|
|
$nav['create_time'] = strtotime($nav['create_time']); |
|
|
@ -816,9 +848,12 @@ class ContentController extends BaseController |
|
|
if(!empty($nav['update_time']) && !is_numeric($nav['update_time'])){ |
|
|
if(!empty($nav['update_time']) && !is_numeric($nav['update_time'])){ |
|
|
$nav['update_time'] = strtotime($nav['update_time']); |
|
|
$nav['update_time'] = strtotime($nav['update_time']); |
|
|
} |
|
|
} |
|
|
$tmpNav[] = $nav; |
|
|
|
|
|
|
|
|
$newNavId = Db::name('nav')->insertGetId($nav); |
|
|
|
|
|
if($newNavId > 0){ |
|
|
|
|
|
$navIdMap[$originalId] = $newNavId; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
$res5 = Db::name('nav')->insertAll($tmpNav); |
|
|
|
|
|
|
|
|
|
|
|
// 关联内容更新
|
|
|
// 关联内容更新
|
|
|
$contentService->exchangeRelationContent($this->admin['seller_id'],$param['to']); |
|
|
$contentService->exchangeRelationContent($this->admin['seller_id'],$param['to']); |
|
|
|
|
|
|
|
|
@ -828,21 +863,8 @@ class ContentController extends BaseController |
|
|
dump($item,123); |
|
|
dump($item,123); |
|
|
dump($e->getMessage()); |
|
|
dump($e->getMessage()); |
|
|
dd($e->getLine()); |
|
|
dd($e->getLine()); |
|
|
die; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
dd($categoryMap); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取搬运的内容和原始内容的映射关系
|
|
|
|
|
|
public function getMapIds($table,$ids) |
|
|
|
|
|
{ |
|
|
|
|
|
$total = count($ids); |
|
|
|
|
|
$table = env('database.prefix').$table; |
|
|
|
|
|
$res = Db::query("SHOW TABLE STATUS WHERE NAME = '$table'"); |
|
|
|
|
|
$maxId = $res[0]['Auto_increment']; |
|
|
|
|
|
$targetIds = range($maxId, $maxId + $total - 1); |
|
|
|
|
|
return array_combine($ids, $targetIds); |
|
|
|
|
|
|
|
|
return jsonReturn(200, '迁移完成'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |