浏览代码

book update record

zz 6 年之前
父节点
当前提交
dc001fdc9b
共有 3 个文件被更改,包括 63 次插入3 次删除
  1. 35 1
      app/Console/Commands/BookAfterSpider.php
  2. 26 0
      app/Console/Commands/BookUpdateOne.php
  3. 2 2
      app/Libs/Helpers.php

+ 35 - 1
app/Console/Commands/BookAfterSpider.php

@@ -30,6 +30,8 @@ class BookAfterSpider extends Command
      *
      * @return void
      */
+     private $update_info = [];
+
     public function __construct()
     {
         parent::__construct();
@@ -54,12 +56,13 @@ class BookAfterSpider extends Command
                 $this->starts($value);
             }
         }
+        $this->recordUpdateInfo();
     }
 
     private function starts($bid)
     {
-        $this->bookChapterInfo($bid);
         $this->addbookConfig($bid);
+        $this->bookChapterInfo($bid);
         $this->adjustSequentOne($bid);
     }
 
@@ -98,6 +101,11 @@ class BookAfterSpider extends Command
             if ($vip && isset($vip->sequence)) {
                 $vip_seq = $vip->sequence;
             }
+            $this->update_info[$bid] = [];
+            $this->update_info[$bid]['add'] = true;
+            $this->update_info[$bid]['channel_name'] = $book_info->category_id >=13 ? '女频':'男频';
+            $this->update_info[$bid]['update_type'] = 'add_book';
+            $this->update_info[$bid]['book_name'] = $book_info->name;
             DB::table('book_configs')->insert([
                 'bid' => $bid,
                 'force_subscribe_chapter_seq' => 10,
@@ -123,6 +131,10 @@ class BookAfterSpider extends Command
         $res3 = DB::table('chapters')->where('bid', $bid)->count();
 
         $res4 = DB::table('chapters')->where('bid', $bid)->sum('size');
+        if(isset($this->update_info[$bid])){
+            $this->update_info[$bid]['update_words'] = $res4;
+            $this->update_info[$bid]['update_chapter_count'] = $res3;
+        }
         DB::table('books')->where('id', $bid)->update(
             [
                 'chapter_count' => $res3,
@@ -161,4 +173,26 @@ class BookAfterSpider extends Command
             $prev = $chapter->id;
         }
     }
+
+    private function recordUpdateInfo()
+    {
+        if(!$this->update_info) {
+            return;
+        }
+        foreach ($this->update_info as $k=>$v){
+            if(!$v['add']) continue;
+            // 2 book_updates 的更新记录
+            DB::table('book_updates')->insert([
+                'bid' => $k,
+                'book_name' => $v['book_name'],
+                'channel_name' => $v['channel_name'],
+                'update_date' => date('Y-m-d'),
+                'update_chapter_count' => $v['update_chapter_count'],
+                'update_words' => $v['update_words'],
+                'update_type' => $v['update_type'],
+                'created_at' => date('Y-m-d H:i:s'),
+                'updated_at' => date('Y-m-d H:i:s')
+            ]);
+        }
+    }
 }

+ 26 - 0
app/Console/Commands/BookUpdateOne.php

@@ -80,8 +80,10 @@ class BookUpdateOne extends Command
         $res = $this->client->get(sprintf($chapter_list_fromat,$book_info->ly_bid));
         $res = $res->getBody()->getContents();
         if(!$res) return '';
+        $book_config_info = DB::table('book_configs')->where('bid',$bid)->first();
         $res = json_decode($res,true);
         $j = 0;
+        $size = 0;
         $local_count = Chapter::where('bid',$bid)->count();
         $remote_count = 0;
 
@@ -119,6 +121,7 @@ class BookUpdateOne 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]);
@@ -131,6 +134,13 @@ class BookUpdateOne 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']]);
+            $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;
     }
@@ -195,4 +205,20 @@ class BookUpdateOne extends Command
             }
         }
     }
+
+    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')
+        ]);
+    }
 }

+ 2 - 2
app/Libs/Helpers.php

@@ -223,7 +223,7 @@ function ImageNewsToArray($datas){
  * 加密site id
  */
 function encodeDistributionChannelId($id){
-    $encrypt_pool = ['14'=>'xyvz5MEXLL52Mzn4','13'=>'laosiji','4372'=>'qhyeyue','365'=>'vciam5tg71','384'=>'sdxisd'];
+    $encrypt_pool = ['14'=>'xyvz5mexll52mzn4','13'=>'laosiji','4372'=>'qhyeyue','365'=>'vciam5tg71','384'=>'sdxisd'];
     if(isset($encrypt_pool[$id])){
         return $encrypt_pool[$id];
     }
@@ -244,7 +244,7 @@ function encodeDistributionChannelId($id){
  * 解密密site id
  */
 function decodeDistributionChannelId($code){
-    $encrypt_pool = ['xyvz5MEXLL52Mzn4'=>'14','laosiji'=>'13','qhyeyue'=>'4372','vciam5tg71'=>'365','sdxisd'=>'384'];
+    $encrypt_pool = ['xyvz5mexll52mzn4'=>'14','laosiji'=>'13','qhyeyue'=>'4372','vciam5tg71'=>'365','sdxisd'=>'384'];
     if(isset($encrypt_pool[$code])){
         return $encrypt_pool[$code];
     }