lh 4 дней назад
Родитель
Сommit
27438752f3
2 измененных файлов с 35 добавлено и 6 удалено
  1. 8 4
      app/Services/Book/BookService.php
  2. 27 2
      app/Services/DeepSeek/DeepSeekService.php

+ 8 - 4
app/Services/Book/BookService.php

@@ -24,6 +24,7 @@ class BookService
         $status = getProp($data, 'status');
 
         $query = DB::table('books as b')->leftJoin('book_configs as bc', 'b.id', '=', 'bc.bid')
+        ->where('b.size', '<', 30000)->where('b.status', 1)
         ->whereIn('bc.cp_source', ['ycsd', 'yqsd'])->whereIn('bc.is_on_shelf', [1,2])->select('b.status', 'bc.*', 
         DB::raw('(select count(id) from mp_book_version where bid = b.id) as version_count'));
 
@@ -66,9 +67,11 @@ class BookService
         $bid = getProp($data, 'bid');
         if (!$bid) Utils::throwError('20003:请选择书籍');
 
-        return DB::table('mp_book_version')->where('bid', $bid)->orderBy('id', 'desc')->select('bid', 'id as version_id', 'version_name')
+        return DB::table('mp_book_version')->where('bid', $bid)->orderBy('id', 'desc')->select('bid', 'book_name', 'id as version_id', 'version_name')
         ->get()->map(function($value) {
-            return (array)$value;
+            $value = (array)$value;
+            $value['version_name'] = $value['book_name']."【{$value['version_name']}】";
+            return $value;
         })->toArray();
     }
 
@@ -79,7 +82,6 @@ class BookService
         $version_name = trim(getProp($data, 'version_name'));
         if (!$version_name) Utils::throwError('20003:请填写版本名');
         $book_name = DB::table('book_configs')->where('bid', $bid)->value('book_name');
-        $version_name = $book_name."【{$version_name}】";
         if (DB::table('mp_book_version')->where('bid', $bid)->where('version_name', $version_name)->exists()) Utils::throwError('20003:版本名已存在');
         
         $all_chapters = DB::table('chapters')->where('bid', $bid)->where('is_check', 1)->where('is_deleted', 0)->select('id', 'name', 'sequence', 'size', 'chapter_content_id')->get();
@@ -88,6 +90,7 @@ class BookService
 
             $version_id = DB::table('mp_book_version')->insertGetId([
                 'bid' => $bid,
+                'book_name' => $book_name,
                 'version_name' => $version_name,
                 'created_at' => date('Y-m-d H:i:s'),
                 'updated_at' => date('Y-m-d H:i:s'),
@@ -103,6 +106,7 @@ class BookService
                     'bid'                   => $bid,
                     'book_name'             => $book_name,
                     'version_id'            => $version_id,
+                    'version_name'          => $version_name, 
                     'cid'                   => getProp($chapter, 'id'),
                     'chapter_name'          => getProp($chapter, 'name'),
                     'sequence'              => getProp($chapter, 'sequence'),
@@ -129,7 +133,7 @@ class BookService
         return [
             'bid'           => $bid,
             'version_id'    => $version_id,
-            'version_name'  => $version_name,
+            'version_name'  => $book_name."【{$version_name}】",
         ];
     }
 

+ 27 - 2
app/Services/DeepSeek/DeepSeekService.php

@@ -142,12 +142,37 @@ class DeepSeekService
                 Utils::throwError('20003:更新角色信息失败');
             }
 
-            // $count = DB::table('mp_chapter_audios')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->count('id');
-            $boolen1 = DB::table('mp_chapter_audios')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->update(['generate_status'=>'执行中', 'generate_json' => $generate_json, 'updated_at' => date('Y-m-d H:i:s')]);
+            $count = DB::table('mp_audio_tasks')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->count('id');
+            $chapter_audio = DB::table('mp_chapter_audios')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->first();
+            if (!$count) {
+                $task_name = getProp($chapter_audio, 'book_name').' '.getProp($chapter_audio, 'chapter_name').'【'.getProp($chapter_audio, 'version_name').'】';
+            }else {
+                $task_name = getProp($chapter_audio, 'book_name').' '.getProp($chapter_audio, 'chapter_name').'【'.getProp($chapter_audio, 'version_name').'】('.($count+1).')';
+            }
+            $boolen1 = DB::table('mp_chapter_audios')->where('bid', $bid)->where('version_id', $version_id)->where('cid', $cid)->update(['generate_status'=>'制作中', 'generate_json' => $generate_json, 'updated_at' => date('Y-m-d H:i:s')]);
             if (!$boolen1) {
                 DB::rollBack();
                 Utils::throwError('20003:更新生成数据失败');
             }
+            $boolen2 = DB::table('mp_audio_tasks')->insert([
+                'audio_id'      => getProp($chapter_audio, 'id'),
+                'status'        => '执行中',
+                'generate_json' => $generate_json,
+                'bid'           => $bid,
+                'book_name'     => getProp($chapter_audio, 'book_name'),
+                'version_id'    => $version_id,
+                'version_name'  => getProp($chapter_audio, 'version_name'),
+                'cid'           => $cid,
+                'chapter_name'  => getProp($chapter_audio, 'chapter_name'),
+                'task_name'     => $task_name,
+                'created_at'    => date('Y-m-d H:i:s'),
+                'updated_at'    => date('Y-m-d H:i:s')
+            ]);
+            if (!$boolen2) {
+                DB::rollBack();
+                Utils::throwError('20003:创建任务失败');
+            }
+
         } catch (\Exception $e) {
             DB::rollBack();
             Utils::throwError('20003:'.$e->getMessage());