diff --git a/app/controller/backend/CategoryController.php b/app/controller/backend/CategoryController.php index b638526..a753df9 100644 --- a/app/controller/backend/CategoryController.php +++ b/app/controller/backend/CategoryController.php @@ -496,6 +496,7 @@ class CategoryController extends BaseController public function copyCategoryToOtherLang(CategoryService $categoryService): \think\response\Json { $param = $this->request->only(['from','to','site_id']); + dd($param); try { validate(CategoryValidate::class)->scene('copyCategoryToAnotherLang')->check($param); } catch (ValidateException $e) { diff --git a/app/controller/backend/ContentController.php b/app/controller/backend/ContentController.php index 1fc4778..965696d 100644 --- a/app/controller/backend/ContentController.php +++ b/app/controller/backend/ContentController.php @@ -800,4 +800,15 @@ class ContentController extends BaseController 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); + } + } diff --git a/app/service/ContentService.php b/app/service/ContentService.php index 3aa8fd9..d3c7048 100644 --- a/app/service/ContentService.php +++ b/app/service/ContentService.php @@ -2386,5 +2386,73 @@ class ContentService { return $dataArr; } + public function exchangeRelationContent($sellerId, $lang) + { + // 查找所有内容 + $SubContent = new SubContent(); + $subContent = $SubContent->getAllCustomArrayData(['seller_id' => $sellerId, 'lang' => $lang], 'id asc', '*', ['module.moduleField'])['data']; + foreach ($subContent as $content) { + $relationFlag = false; + $relationField = []; + foreach ($content['module']['moduleField'] as $field) { + if ($field['type'] == '关联字段') { + $relationFlag = true; + $relationField[] = $field; + } + } + if (!$relationFlag) { + continue; + } + $selectField = array_column($relationField, 'table_field'); + $self = $this->getSelf(); + $self::setModel($content['module']['table']); + $field = array_merge(['id', 'sub_id'], $selectField); + $fieldStr = implode(',', $field); + $article = self::$model->field($fieldStr)->where(['sub_id' => $content['id'], 'seller_id' => $sellerId])->findOrEmpty()->toArray(); + if (empty($article)) { + continue; + } + $tmpUpdate = []; + foreach ($relationField as $item) { + $setting = $item['settings']; + $table = $setting['table']; + $field = $item['table_field']; + $referenceId = []; + $dataType = ''; + if (is_string($article[$field])) { + $referenceId = json_decode($article[$field], true); + $dataType = 'string'; + } + if (is_int($article[$field])) { + $referenceId = [$article[$field]]; + $dataType = 'int'; + } + if ($table !== 'sub_content') { + continue; + } + + $mapContent = Db::name('sub_content')->field('id,title,sub_id_map')->where('sub_id_map', 'in', $referenceId)->select()->toArray(); + + if (empty($mapContent)) { + continue; + } + $ids = array_column($mapContent, 'id'); + if ($dataType == 'string') { + $ids = json_encode($ids); + $tmpUpdate[$field] = $ids; + } + if ($dataType == 'int') { + $tmpUpdate[$field] = $mapContent[0]['id']; + } + } + self::$model->where(['id' => $article['id']])->update($tmpUpdate); + } + } + + public function getSelf() + { + return app()->make(self::class); + } + }