Browse Source

add week bugs

zz 5 years ago
parent
commit
7a0c3d631c

+ 74 - 14
app/Console/Commands/UpdateOuter.php

@@ -2,11 +2,14 @@
 
 namespace App\Console\Commands;
 
+use App\Modules\Book\Models\BookConfig;
+use App\Modules\Book\Services\BookConfigService;
 use GuzzleHttp\Cookie\SetCookie;
 use Illuminate\Console\Command;
 use GuzzleHttp\Client;
 use App\Modules\Book\Models\Book;
 use App\Modules\Book\Models\Chapter;
+use DB;
 
 class UpdateOuter extends Command
 {
@@ -46,31 +49,88 @@ class UpdateOuter extends Command
 
     //微月云
     private function updateOneFromWyy($bid,$wyy_bid){
-        $jar = new \GuzzleHttp\Cookie\CookieJar(false,[
-            new SetCookie(['Name'=>'PHPSESSID','Value'=>'np1pu5oj2taacado7h4gn0usf2']),
-            new SetCookie(['Name'=>'getuserinfo','Value'=>'1']),
-            new SetCookie(['Name'=>'user_id','Value'=>'268860471']),
-            new SetCookie(['Name'=>'subscribe','Value'=>'1']),
-            new SetCookie(['Name'=>'user_name','Value'=>'we20190312']),
-            new SetCookie(['Name'=>'admin_id','Value'=>'326695218']),
-            new SetCookie(['Name'=>'shell','Value'=>'8de1e2d1789ed1a7a6f1673d9373123d']),
-            new SetCookie(['Name'=>'OPENID','Value'=>'olpZ50lR6G-pLQ8WYiQXVw6Wg8U0']),
-            new SetCookie(['Name'=>'VALIDON','Value'=>'1566467472']),
-            new SetCookie(['Name'=>'CRC','Value'=>'5e3a06c9424d5c3c80ad82371d5dec16'])
-        ]);
         $last_chapter = Chapter::where('bid',$bid)
             ->select('id','name','sequence','prev_cid','next_cid')
             ->orderBy('sequence','desc')
             ->first();
         $now_sequence  = $last_chapter->sequence+1;
         $url_format = 'https://wxg6y88rwiqvjkvx.weiyueyunsc.com/ChapterContent/content/fromaid/326695218.html?bookid=%s&num=%s';
+        $client = new Client();
+        $cookie = 'prid=0;uid=2;user_id=268860471;user_name=we20190312pen_name妙妙;portrait=http://thirdwx.qlogo.cn/mmopen/EH4aHSGnx7EU03AbVwKkQZoHH4kd3W3iarLibW9XqQuUfTjs7ZBnsmZZaficujibBl144FH9yWfNKaRLxUWc8N4G1FHDBv9wOUH8/132;admin_id=326695218;subscribe=1;shell=8de1e2d1789ed1a7a6f1673d9373123d;OPENID=olpZ50lR6G-pLQ8WYiQXVw6Wg8U0;PHPSESSID=gdps01shh5ood1e75prvkuihp2;VALIDON=1569237596;CRC=be4cea518f4058b00a80c8ce03333178;';
+        $last_chapter_id = $last_chapter->id;
+
+        $j = 0;
+        $word = 0;
         while (true){
+            $url = sprintf($url_format,$wyy_bid,$now_sequence);
+            $result = $client->request('get',$url,[
+                'headers'=>[
+                    'cookie'=>$cookie,
+                    'User-Agent'=>'Mozilla/5.0 (Linux; Android 8.0.0; MI 6 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 XWEB/882 MMWEBSDK/190503 Mobile Safari/537.36 MMWEBID/223 MicroMessenger/7.0.5.1420(0x27000530) Process/tools NetType/WIFI Language/zh_CN',
+                    'X-Requested-With'=>'XMLHttpRequest'
+                ]
+            ])->getBody()->getContents();
+            $result = json_decode($result,1);
+            if(!isset($result['content_title']) || !isset($result['content_contents'])){
+                break;
+            }
+            $title = $result['content_title'];
+            $content = $result['content_contents'];
+            $content = str_replace('</p>',"\r\n",$content);
+            $content = str_replace('<p>',"",$content);
 
+            $temp = [
+                'bid' => $bid,
+                'name' => $title,
+                'sequence' => $now_sequence,
+                'is_vip' => 1,
+                'prev_cid' => $last_chapter_id,
+                'next_cid' => '',
+                'recent_update_at' => date('Y-m-d H:i:s'),
+                'ly_chapter_id' => 0,
+                'content'=>$content,
+                'size'=>mb_strlen($content)
+            ];
+
+            $word +=  mb_strlen($content);
+            $insert_res = Chapter::create($temp);
+            $last_chapter_id = $insert_res->id;
+            $now_sequence++;
+            $j++;
+        }
+        $chapter_count = Chapter::where('bid', $bid)->count();
+        $chapter_size = Chapter::where('bid', $bid)->sum('size');
+        if ($j > 0) {
+            Book::where('id', $bid)->update(['chapter_count' => $chapter_count, 'last_cid' => $last_chapter_id, 'size' => $chapter_size, 'last_chapter' => $title]);
+            $book_info = BookConfigService::getBookById($bid);
+            $data = [
+                'book_name'=>$book_info->book_name,
+                'channel_name'=>$book_info->category_id >=13 ? '女频':'男频',
+                'update_type'=>'add_chapter',
+                'update_chapter_count'=>0,
+                'update_words'=>0,
+            ];
+            $data['update_chapter_count'] = $j;
+            $data['update_words'] = $word;
+            $this->recordUpdateInfo($bid,$data);
         }
+    }
 
-        $url = sprintf($url_format,$wyy_bid,1);
-        $client = new Client();
 
+    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')
+        ]);
     }
 
 }

+ 1 - 1
app/Modules/Subscribe/Services/YearOrderService.php

@@ -101,7 +101,7 @@ class YearOrderService
                 $old->save();
             } else {
                 //旧的包年过期了
-                $old->end_time = date('Y-m-d H:i:s', $insert_data['end_time']);
+                $old->end_time = $insert_data['end_time'];
                 $old->fee = $old->fee + $data['fee'];
                 $old->save();
             }