zz 6 anni fa
parent
commit
dac90ab2de

+ 4 - 0
app/Console/Commands/BookSpider.php

@@ -159,4 +159,8 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
         echo 'del ' . $i . PHP_EOL;
         return "";
     }
+
+    private function newYunQi(){
+        \App\Modules\Book\Services\BookService::newYunQiBook(1);
+    }
 }

+ 49 - 1
app/Modules/Book/Services/BookService.php

@@ -3,9 +3,11 @@
 namespace App\Modules\Book\Services;
 
 use App\Modules\Book\Models\Book;
+use App\Modules\Book\Models\Chapter;
+use GuzzleHttp\Client;
 use Redis;
 use App\Modules\Statistic\Services\WapVisitStatService;
-
+use DB;
 
 class BookService
 {
@@ -80,4 +82,50 @@ class BookService
     public static function getBookById($bid){
         return Book::find($bid);
     }
+
+    public static function newYunQiBook($bid){
+        $old = DB::table('book_yunqi')->where('yq_bid',$bid)->where('type','NEW_YUNQI')->first();
+        if($old){
+            return -1;
+        }
+        $new_yunqi_book = DB::connection('new_yunqi')->table('books')->where('id',$bid)->fist();
+        if(!$new_yunqi_book){
+            return -2;
+        }
+
+        $book = Book::create(
+            [
+                'ly_bid'=>0,'name'=>$new_yunqi_book->name,'author'=>$new_yunqi_book->author,'intro'=>$new_yunqi_book->intro,'cover'=>$new_yunqi_book->cover,
+                'category_name'=>$new_yunqi_book->category_name,'keyword'=>$new_yunqi_book->keyword,'category_id'=>0,'status'=>$new_yunqi_book->status,
+                'chapter_count'=>$new_yunqi_book->chapter_count,'first_cid'=>0,'last_cid'=>0,'size'=>$new_yunqi_book->size,'last_chapter'=>$new_yunqi_book->last_chapter,
+                'sequence'=>0,'yq_bid'=>$bid
+            ]
+        );
+        DB::table('book_yunqi')->insert([
+            'bid'=>$book->id,
+            'yq_bid'=>$bid,
+            'type'=>'NEW_YUNQI',
+            'created_at'=>date('Y-m-d H:i:s'),
+            'updated_at'=>date('Y-m-d H:i:s')
+        ]);
+        for ($i = 1;$i<=$new_yunqi_book->chapter_count;$i++){
+            $temp = DB::connection('new_yunqi')->table('chapters')->where('bid',$bid)->where('sequence',$i)->select('name','content','is_vip','size')->first();
+            if($new_yunqi_book){
+                Chapter::create([
+                    'bid'=>$book->id,
+                    'name'=>$temp->name,
+                    'sequence'=>$i,
+                    'is_vip'=>$temp->is_vip,
+                    'size'=>$temp->size,
+                    'prev_cid'=>0,
+                    'next_cid'=>0,
+                    'recent_update_at'=>date('Y-m-d H:i:s'),
+                    'content'=>$temp->content,
+                    'ly_chapter_id'=>0
+                ]);
+            }
+        }
+        \Artisan::callSilent('book:afs',['bid'=>[$book->id]]);
+        return 0;
+    }
 }

+ 13 - 0
config/database.php

@@ -84,6 +84,19 @@ return [
             'strict' => false,
             'engine' => null,
         ],
+        'new_yunqi'=>[
+            'driver' => 'mysql',
+            'host' => env('NEW_YUNQI_DB_HOST', 'localhost'),
+            'port' => env('NEW_YUNQI_DB_PORT', '3306'),
+            'database' => env('NEW_YUNQI_DB_DATABASE', 'forget'),
+            'username' => env('NEW_YUNQI_DB_USERNAME', 'forget'),
+            'password' => env('NEW_YUNQI_DB_PASSWORD', ''),
+            'charset' => 'utf8',
+            'collation' => 'utf8_unicode_ci',
+            'prefix' => '',
+            'strict' => false,
+            'engine' => null,
+        ],
         'pgsql' => [
             'driver' => 'pgsql',
             'host' => env('DB_HOST', 'localhost'),