|
@@ -970,6 +970,7 @@ class AnimeService
|
|
|
'role' => 'user',
|
|
'role' => 'user',
|
|
|
'content' => $prompt,
|
|
'content' => $prompt,
|
|
|
'segment_id' => $segment_id,
|
|
'segment_id' => $segment_id,
|
|
|
|
|
+ 'pic_task_id' => $task_id,
|
|
|
'image_url' => '',
|
|
'image_url' => '',
|
|
|
'created_at' => $now,
|
|
'created_at' => $now,
|
|
|
'updated_at' => $now
|
|
'updated_at' => $now
|
|
@@ -981,6 +982,7 @@ class AnimeService
|
|
|
'role' => 'assistant',
|
|
'role' => 'assistant',
|
|
|
'content' => $pic_prompt,
|
|
'content' => $pic_prompt,
|
|
|
'segment_id' => $segment_id,
|
|
'segment_id' => $segment_id,
|
|
|
|
|
+ 'pic_task_id' => $task_id,
|
|
|
'image_url' => $img_url,
|
|
'image_url' => $img_url,
|
|
|
'created_at' => $now,
|
|
'created_at' => $now,
|
|
|
'updated_at' => $now
|
|
'updated_at' => $now
|
|
@@ -1010,7 +1012,7 @@ class AnimeService
|
|
|
|
|
|
|
|
if (!$segment_id) Utils::throwError('20003:请选择分镜!');
|
|
if (!$segment_id) Utils::throwError('20003:请选择分镜!');
|
|
|
|
|
|
|
|
- $query = DB::table('mp_anime_records')->where('segment_id', $segment_id)->select('role', 'content', 'segment_id', 'image_url', 'video_url', 'created_at');
|
|
|
|
|
|
|
+ $query = DB::table('mp_anime_records')->where('segment_id', $segment_id)->select('role', 'content', 'segment_id', 'image_url', 'video_url', 'video_task_id', 'pic_task_id', 'created_at');
|
|
|
|
|
|
|
|
$chat = $query->orderBy('id')->get()->map(function ($value) {
|
|
$chat = $query->orderBy('id')->get()->map(function ($value) {
|
|
|
$value = (array)$value;
|
|
$value = (array)$value;
|
|
@@ -2380,6 +2382,7 @@ class AnimeService
|
|
|
'role' => 'user',
|
|
'role' => 'user',
|
|
|
'content' => '重新生成',
|
|
'content' => '重新生成',
|
|
|
'segment_id' => $segment_id,
|
|
'segment_id' => $segment_id,
|
|
|
|
|
+ 'pic_task_id' => $task_id,
|
|
|
'image_url' => '',
|
|
'image_url' => '',
|
|
|
'created_at' => $now,
|
|
'created_at' => $now,
|
|
|
'updated_at' => $now
|
|
'updated_at' => $now
|
|
@@ -2391,6 +2394,7 @@ class AnimeService
|
|
|
'role' => 'assistant',
|
|
'role' => 'assistant',
|
|
|
'content' => $pic_prompt,
|
|
'content' => $pic_prompt,
|
|
|
'segment_id' => $segment_id,
|
|
'segment_id' => $segment_id,
|
|
|
|
|
+ 'pic_task_id' => $task_id,
|
|
|
'image_url' => $img_url,
|
|
'image_url' => $img_url,
|
|
|
'created_at' => $now,
|
|
'created_at' => $now,
|
|
|
'updated_at' => $now
|
|
'updated_at' => $now
|
|
@@ -3335,7 +3339,7 @@ class AnimeService
|
|
|
|
|
|
|
|
if (!$act_id) Utils::throwError('20003:请选择片段!');
|
|
if (!$act_id) Utils::throwError('20003:请选择片段!');
|
|
|
|
|
|
|
|
- $query = DB::table('mp_anime_records')->where('act_id', $act_id)->select('role', 'content', 'act_id', 'image_url', 'video_url', 'reference_images', 'created_at');
|
|
|
|
|
|
|
+ $query = DB::table('mp_anime_records')->where('act_id', $act_id)->select('role', 'content', 'act_id', 'image_url', 'video_url', 'video_task_id', 'pic_task_id', 'reference_images', 'created_at');
|
|
|
|
|
|
|
|
$chat = $query->orderBy('id')->get()->map(function ($value) {
|
|
$chat = $query->orderBy('id')->get()->map(function ($value) {
|
|
|
$value = (array)$value;
|
|
$value = (array)$value;
|
|
@@ -5871,11 +5875,12 @@ class AnimeService
|
|
|
* 根据 inner_prompt_type 获取生成图片数量
|
|
* 根据 inner_prompt_type 获取生成图片数量
|
|
|
*
|
|
*
|
|
|
* @param int $innerPromptType 内置提示词类型
|
|
* @param int $innerPromptType 内置提示词类型
|
|
|
|
|
+ * @param int $imageNum 传入的图片张数
|
|
|
* @return int 图片数量
|
|
* @return int 图片数量
|
|
|
*/
|
|
*/
|
|
|
- public static function getInnerImageNum($innerPromptType = 0)
|
|
|
|
|
|
|
+ public static function getInnerImageNum($innerPromptType = 0, $imageNum)
|
|
|
{
|
|
{
|
|
|
- return (int)$innerPromptType === 2 ? 9 : 1;
|
|
|
|
|
|
|
+ return (int)$innerPromptType === 2 ? 9 : $imageNum;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -5908,6 +5913,7 @@ class AnimeService
|
|
|
$ratio = getProp($data, 'ratio', '9:16');
|
|
$ratio = getProp($data, 'ratio', '9:16');
|
|
|
$resolution = getProp($data, 'resolution', '2k');
|
|
$resolution = getProp($data, 'resolution', '2k');
|
|
|
$inner_prompt_type = getProp($data, 'inner_prompt_type', 0);
|
|
$inner_prompt_type = getProp($data, 'inner_prompt_type', 0);
|
|
|
|
|
+ $imageNum = (int)getProp($data, 'image_num', 1);
|
|
|
|
|
|
|
|
// 定义分辨率和宽高比对应的尺寸映射表
|
|
// 定义分辨率和宽高比对应的尺寸映射表
|
|
|
$sizeMap = [
|
|
$sizeMap = [
|
|
@@ -5996,7 +6002,7 @@ class AnimeService
|
|
|
|
|
|
|
|
// 根据 inner_prompt_type 附加内置提示词并确定生成图片数量
|
|
// 根据 inner_prompt_type 附加内置提示词并确定生成图片数量
|
|
|
$prompt = self::appendInnerPrompt($prompt, $inner_prompt_type);
|
|
$prompt = self::appendInnerPrompt($prompt, $inner_prompt_type);
|
|
|
- $imageNum = self::getInnerImageNum($inner_prompt_type);
|
|
|
|
|
|
|
+ $imageNum = self::getInnerImageNum($inner_prompt_type, $imageNum);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// 创建图片生成任务
|
|
// 创建图片生成任务
|
|
@@ -6027,6 +6033,7 @@ class AnimeService
|
|
|
$start_time = time();
|
|
$start_time = time();
|
|
|
$timeout = 300; // 5分钟
|
|
$timeout = 300; // 5分钟
|
|
|
$img_url = '';
|
|
$img_url = '';
|
|
|
|
|
+ $img_urls = [];
|
|
|
|
|
|
|
|
while (time() - $start_time < $timeout) {
|
|
while (time() - $start_time < $timeout) {
|
|
|
sleep(3);
|
|
sleep(3);
|
|
@@ -6037,7 +6044,14 @@ class AnimeService
|
|
|
$task = MpGeneratePicTask::where('id', $task_id)->first();
|
|
$task = MpGeneratePicTask::where('id', $task_id)->first();
|
|
|
|
|
|
|
|
if ($task->status === 'success' && $task->result_url) {
|
|
if ($task->status === 'success' && $task->result_url) {
|
|
|
- $img_url = self::extractResultUrls($task->result_url, $inner_prompt_type);
|
|
|
|
|
|
|
+ $resultUrls = is_array($task->result_url) ? $task->result_url : json_decode((string)$task->result_url, true);
|
|
|
|
|
+ $resultUrls = is_array($resultUrls) ? array_values(array_filter($resultUrls)) : [];
|
|
|
|
|
+ if (!empty($resultUrls)) {
|
|
|
|
|
+ $img_urls = $resultUrls;
|
|
|
|
|
+ $img_url = $resultUrls[0];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $img_url = (string)$task->result_url;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
} elseif ($task->status === 'failed') {
|
|
} elseif ($task->status === 'failed') {
|
|
|
$errorMsg = mapErrorMessage($task->error_message ?? '');
|
|
$errorMsg = mapErrorMessage($task->error_message ?? '');
|
|
@@ -6056,7 +6070,14 @@ class AnimeService
|
|
|
'result_json' => $statusInfo['result_json'] ?? []
|
|
'result_json' => $statusInfo['result_json'] ?? []
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
- $img_url = self::extractResultUrls($statusInfo['result_url'], $inner_prompt_type);
|
|
|
|
|
|
|
+ $resultUrls = is_array($statusInfo['result_url']) ? $statusInfo['result_url'] : json_decode((string)$statusInfo['result_url'], true);
|
|
|
|
|
+ $resultUrls = is_array($resultUrls) ? array_values(array_filter($resultUrls)) : [];
|
|
|
|
|
+ if (!empty($resultUrls)) {
|
|
|
|
|
+ $img_urls = $resultUrls;
|
|
|
|
|
+ $img_url = $resultUrls[0];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $img_url = (string)$statusInfo['result_url'];
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
} elseif ($statusInfo['status'] === 'failed') {
|
|
} elseif ($statusInfo['status'] === 'failed') {
|
|
|
$task->updateStatus('failed', [
|
|
$task->updateStatus('failed', [
|
|
@@ -6076,6 +6097,14 @@ class AnimeService
|
|
|
Utils::throwError('20003:图片生成超时,请稍后重试');
|
|
Utils::throwError('20003:图片生成超时,请稍后重试');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 多张图片返回全部URL数组(配合控制器输出image_urls字段)
|
|
|
|
|
+ if (count($img_urls) > 1) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'img_url' => $img_url,
|
|
|
|
|
+ 'image_urls' => $img_urls
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return $img_url;
|
|
return $img_url;
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|