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