|
|
@@ -3448,6 +3448,20 @@ class DeepSeekService
|
|
|
$generated_scenes = isset($episode_arr['scenes']) && is_array($episode_arr['scenes']) ? $episode_arr['scenes'] : [];
|
|
|
$merged_roles = $this->mergeEpisodeResourceItems($existing_roles, $generated_roles, 'role');
|
|
|
$merged_scenes = $this->mergeEpisodeResourceItems($existing_scenes, $generated_scenes, 'scene');
|
|
|
+
|
|
|
+ // 获取 mp_animes 表中的全局 roles 和 scenes 用于对比
|
|
|
+ $anime = DB::table('mp_animes')->where('id', $anime_id)->first();
|
|
|
+ $global_roles = json_decode(getProp($anime, 'roles'), true);
|
|
|
+ $global_scenes = json_decode(getProp($anime, 'scenes'), true);
|
|
|
+ $global_roles = is_array($global_roles) ? $global_roles : [];
|
|
|
+ $global_scenes = is_array($global_scenes) ? $global_scenes : [];
|
|
|
+ $art_style = getProp($episode_arr, 'art_style') ?: getProp($anime, 'art_style');
|
|
|
+
|
|
|
+ // 检查并创建 roles 的图片生成任务
|
|
|
+ $merged_roles = $this->checkAndCreateImageTasks($merged_roles, $global_roles, 'role', $art_style);
|
|
|
+
|
|
|
+ // 检查并创建 scenes 的图片生成任务
|
|
|
+ $merged_scenes = $this->checkAndCreateImageTasks($merged_scenes, $global_scenes, 'scene', $art_style);
|
|
|
|
|
|
$role_arr = [];
|
|
|
foreach ($merged_roles as $item) {
|
|
|
@@ -4651,4 +4665,98 @@ class DeepSeekService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查并创建图片生成任务
|
|
|
+ *
|
|
|
+ * @param array $merged_items 合并后的资源列表(roles 或 scenes)
|
|
|
+ * @param array $global_items 全局资源列表(来自 mp_animes 表)
|
|
|
+ * @param string $nameKey 资源名称字段('role' 或 'scene')
|
|
|
+ * @param string $art_style 美术风格
|
|
|
+ * @return array 更新后的资源列表
|
|
|
+ */
|
|
|
+ private function checkAndCreateImageTasks(array $merged_items, array $global_items, string $nameKey, string $art_style = ''): array
|
|
|
+ {
|
|
|
+ // 构建全局资源映射表,用于快速查找
|
|
|
+ $global_map = [];
|
|
|
+ foreach ($global_items as $item) {
|
|
|
+ $itemKey = $this->normalizeEpisodeResourceKey(getProp($item, $nameKey));
|
|
|
+ if ($itemKey === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $global_map[$itemKey] = $item;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历合并后的资源列表,检查是否需要创建图片生成任务
|
|
|
+ foreach ($merged_items as &$item) {
|
|
|
+ $item_name = getProp($item, $nameKey);
|
|
|
+ $item_description = getProp($item, 'description');
|
|
|
+ // $item_url = getProp($item, 'url');
|
|
|
+
|
|
|
+ // // 如果已有图片URL,跳过
|
|
|
+ // if (!empty($item_url)) {
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 如果是旁白角色,跳过
|
|
|
+ if ($nameKey === 'role' && $item_name === '旁白') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $itemKey = $this->normalizeEpisodeResourceKey($item_name);
|
|
|
+ if ($itemKey === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $need_create_task = false;
|
|
|
+
|
|
|
+ // 条件1:在全局资源中找不到匹配的名称
|
|
|
+ if (!isset($global_map[$itemKey])) {
|
|
|
+ $need_create_task = true;
|
|
|
+ } else {
|
|
|
+ // 条件2:名称匹配但描述不一致
|
|
|
+ $global_description = trim((string)getProp($global_map[$itemKey], 'description'));
|
|
|
+ $current_description = trim((string)$item_description);
|
|
|
+
|
|
|
+ if ($global_description !== $current_description) {
|
|
|
+ $need_create_task = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果需要创建任务,调用图片生成服务
|
|
|
+ if ($need_create_task) {
|
|
|
+ try {
|
|
|
+ $description = $item_description;
|
|
|
+
|
|
|
+ // 添加美术风格前缀
|
|
|
+ if ($art_style) {
|
|
|
+ $prefix = $nameKey === 'role' ? '主体描述' : '场景描述';
|
|
|
+ $description = "美术风格:\n{$art_style}\n\n{$prefix}:{$description}";
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ 'prompt' => $description,
|
|
|
+ 'ref_img_urls' => []
|
|
|
+ ];
|
|
|
+
|
|
|
+ $task = $this->aiImageGenerationService->createImageGenerationTask($params);
|
|
|
+ $task_id = $task->id;
|
|
|
+
|
|
|
+ if ($task_id) {
|
|
|
+ $item['task_id'] = $task_id;
|
|
|
+ $item['task_status'] = 'processing';
|
|
|
+
|
|
|
+ $resource_type = $nameKey === 'role' ? '角色' : '场景';
|
|
|
+ dLog('deepseek')->info("{$resource_type}({$item_name})创建图片生成任务成功", ['task_id' => $task_id]);
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $resource_type = $nameKey === 'role' ? '角色' : '场景';
|
|
|
+ dLog('deepseek')->error("{$resource_type}({$item_name})创建图片生成任务失败: " . $e->getMessage());
|
|
|
+ // 不抛出异常,继续处理其他资源
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $merged_items;
|
|
|
+ }
|
|
|
+
|
|
|
}
|