zz 5 роки тому
батько
коміт
8e422a1580
1 змінених файлів з 27 додано та 1 видалено
  1. 27 1
      app/Console/Commands/BookUpdate.php

+ 27 - 1
app/Console/Commands/BookUpdate.php

@@ -86,6 +86,7 @@ class BookUpdate extends Command
             ->first();
         $max_sequence_chapter_id = isset($last_chapter->id) ? $last_chapter->id : 0;
         $max_sequence = isset($last_chapter->sequence) ? $last_chapter->sequence : 0;
+        $book_config_info = DB::table('book_configs')->where('bid',$bid)->first();
 
         try {
             $chapter_list_fromat = "http://www.leyuee.com/services/zwfx.aspx?method=chapterlist&bid=%s&token=sefaf23h7face";
@@ -127,7 +128,7 @@ class BookUpdate extends Command
         if ($last_chapter_from_third && isset($last_chapter_from_third->ly_chapter_id)) {
             $ly_last_chapter_id = $last_chapter_from_third->ly_chapter_id;
         }
-
+        $size = 0;
         foreach ($res['data'] as $v1) {
             foreach ($v1['chapters'] as $v) {
 
@@ -167,6 +168,7 @@ class BookUpdate extends Command
                     $cahpter_content = json_decode($cahpter_content, true);
                     $temp['size'] = ceil(strlen($cahpter_content['data']['chapter_content']) / 3);
                     $temp['content'] = $cahpter_content['data']['chapter_content'];
+                    $size += $temp['size'];
                 }
                 $insert_res = Chapter::create($temp);
                 Chapter::where('id', $max_sequence_chapter_id)->update(['next_cid' => $insert_res->id]);
@@ -180,6 +182,14 @@ class BookUpdate extends Command
         $chapter_size = Chapter::where('bid', $bid)->sum('size');
         if ($j > 0) {
             Book::where('id', $bid)->update(['chapter_count' => $chapter_count, 'last_cid' => $max_sequence_chapter_id, 'size' => $chapter_size, 'last_chapter' => $v['chapter_name']]);
+            $book_info = Book::find($bid);
+            $this->recordUpdateInfo($bid,[
+                'book_name'=>$book_config_info->book_name,
+                'update_chapter_count'=>$j,
+                'update_words'=>$size,
+                'update_type'=>'add_chapter',
+                'channel_name'=>$book_info->category_id >=13 ? '女频':'男频'
+            ]);
         }
         return $j;
     }
@@ -205,4 +215,20 @@ class BookUpdate extends Command
             Book::where('id', $bid)->update(['status' => $status]);
         }
     }
+
+    private function recordUpdateInfo($bid, $data)
+    {
+        // 2 book_updates 的更新记录
+        DB::table('book_updates')->insert([
+            'bid' => $bid,
+            'book_name' => $data['book_name'],
+            'channel_name' => $data['channel_name'],
+            'update_date' => date('Y-m-d'),
+            'update_chapter_count' => $data['update_chapter_count'],
+            'update_words' => $data['update_words'],
+            'update_type' => $data['update_type'],
+            'created_at' => date('Y-m-d H:i:s'),
+            'updated_at' => date('Y-m-d H:i:s')
+        ]);
+    }
 }