|
|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\AIGeneration;
|
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
|
use App\Libs\Utils;
|
|
|
use App\Services\AIGeneration\AIVideoGenerationService;
|
|
|
+use App\Services\PointsService;
|
|
|
use App\Transformer\AIGeneration\AIGenerationTransformer;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
@@ -17,11 +18,14 @@ class VideoGenerationController extends BaseController
|
|
|
{
|
|
|
use ApiResponse;
|
|
|
private $aiVideoGenerationService;
|
|
|
+ private $pointsService;
|
|
|
|
|
|
public function __construct(
|
|
|
- AIVideoGenerationService $aiVideoGenerationService
|
|
|
+ AIVideoGenerationService $aiVideoGenerationService,
|
|
|
+ PointsService $pointsService
|
|
|
) {
|
|
|
$this->aiVideoGenerationService = $aiVideoGenerationService;
|
|
|
+ $this->pointsService = $pointsService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -154,6 +158,21 @@ class VideoGenerationController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 余额预检:按预估时长计算所需积分,不足直接报错
|
|
|
+ $chargeDuration = (int)getProp($data, 'video_duration', 5);
|
|
|
+ if ($chargeDuration <= 0) {
|
|
|
+ $chargeDuration = 5;
|
|
|
+ }
|
|
|
+ $this->pointsService->checkUserPointsEnough(
|
|
|
+ $this->pointsService->getVideoChargePoints([
|
|
|
+ 'model' => (string)getProp($data, 'model', ''),
|
|
|
+ 'video_resolution' => strtolower((string)getProp($data, 'video_resolution', '720p')),
|
|
|
+ 'video_duration' => $chargeDuration,
|
|
|
+ 'ratio' => (string)getProp($data, 'ratio', '9:16'),
|
|
|
+ 'generate_audio' => (int)getProp($data, 'generate_audio', 1),
|
|
|
+ ])
|
|
|
+ );
|
|
|
+
|
|
|
$task = $this->aiVideoGenerationService->createJimengTask($data);
|
|
|
return $this->success(['task_id' => $task->id, 'status' => $task->status]);
|
|
|
}
|
|
|
@@ -451,6 +470,21 @@ class VideoGenerationController extends BaseController
|
|
|
// 验证 content 数组内容
|
|
|
$this->validateSeedanceContent($data['content']);
|
|
|
|
|
|
+ // 余额预检:按预估时长计算所需积分,不足直接报错
|
|
|
+ $chargeDuration = (int)getProp($data, 'video_duration', 5);
|
|
|
+ if ($chargeDuration <= 0) {
|
|
|
+ $chargeDuration = 5;
|
|
|
+ }
|
|
|
+ $this->pointsService->checkUserPointsEnough(
|
|
|
+ $this->pointsService->getVideoChargePoints([
|
|
|
+ 'model' => (string)getProp($data, 'model', ''),
|
|
|
+ 'video_resolution' => strtolower((string)getProp($data, 'video_resolution', '720p')),
|
|
|
+ 'video_duration' => $chargeDuration,
|
|
|
+ 'ratio' => (string)getProp($data, 'ratio', '9:16'),
|
|
|
+ 'generate_audio' => (int)getProp($data, 'generate_audio', 1),
|
|
|
+ ])
|
|
|
+ );
|
|
|
+
|
|
|
$task = $this->aiVideoGenerationService->createSeedanceTask($data);
|
|
|
return $this->success(['task_id' => $task->id, 'status' => $task->status]);
|
|
|
}
|
|
|
@@ -823,6 +857,21 @@ class VideoGenerationController extends BaseController
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ // 余额预检:按预估时长计算所需积分,不足直接报错
|
|
|
+ $chargeDuration = (int)getProp($data, 'video_duration', 5);
|
|
|
+ if ($chargeDuration <= 0) {
|
|
|
+ $chargeDuration = 5;
|
|
|
+ }
|
|
|
+ $this->pointsService->checkUserPointsEnough(
|
|
|
+ $this->pointsService->getVideoChargePoints([
|
|
|
+ 'model' => (string)getProp($data, 'model', ''),
|
|
|
+ 'video_resolution' => strtolower((string)getProp($data, 'video_resolution', '720p')),
|
|
|
+ 'video_duration' => $chargeDuration,
|
|
|
+ 'ratio' => (string)getProp($data, 'aspect_ratio', getProp($data, 'ratio', '9:16')),
|
|
|
+ 'generate_audio' => (int)getProp($data, 'generate_audio', 1),
|
|
|
+ ])
|
|
|
+ );
|
|
|
+
|
|
|
$task = $this->aiVideoGenerationService->createKelingOmniTask($data);
|
|
|
return $this->success(['task_id' => $task->id, 'status' => $task->status]);
|
|
|
}
|