Ver Fonte

cplit content 3

zz há 6 anos atrás
pai
commit
cdf51073d9

+ 39 - 10
app/Console/Commands/BookUpdateOne.php

@@ -9,6 +9,7 @@ use App\Modules\Book\Models\Chapter;
 use App\Modules\Book\Services\ChapterService;
 use App\Modules\Book\Services\BookConfigService;
 use DB;
+use Log;
 
 class BookUpdateOne extends Command
 {
@@ -75,10 +76,22 @@ class BookUpdateOne extends Command
         $book_info = Book::find($bid);
         if(empty($book_info) || empty($book_info->ly_bid)) return -1;
         $this->bookStatus($bid,$book_info->ly_bid);
-        $max_sequence = Chapter::where('bid',$bid)->max('sequence');
-        $max_sequence = $max_sequence?$max_sequence:-1;
-        $max_sequence_chapter = Chapter::where('bid',$bid)->where('sequence',$max_sequence)->select('id')->first();
-        $max_sequence_chapter_id = isset($max_sequence_chapter->id)?$max_sequence_chapter->id:0;
+        //$max_sequence = Chapter::where('bid',$bid)->max('sequence');
+        //$max_sequence = $max_sequence?$max_sequence:-1;
+        //$max_sequence_chapter = Chapter::where('bid',$bid)->where('sequence',$max_sequence)->select('id')->first();
+        //$max_sequence_chapter_id = isset($max_sequence_chapter->id)?$max_sequence_chapter->id:0;
+
+        $last_chapter = Chapter::where('bid',$bid)
+            ->select('id','name','sequence','prev_cid','next_cid')
+            ->orderBy('sequence','desc')
+            ->first();
+        $last_chapter_from_third = Chapter::where('bid',$bid)
+            ->where('ly_chapter_id','>',0)
+            ->select('id','name','sequence','prev_cid','next_cid','ly_chapter_id')
+            ->orderBy('sequence','desc')
+            ->first();
+        $max_sequence_chapter_id = isset($last_chapter->id)?$last_chapter->id:0;
+        $max_sequence = isset($last_chapter->sequence)?$last_chapter->sequence:0;
 
         $chapter_list_fromat = "http://www.leyuee.com/services/zwfx.aspx?method=chapterlist&bid=%s&token=sefaf23h7face";
         $res = $this->client->get(sprintf($chapter_list_fromat,$book_info->ly_bid));
@@ -88,7 +101,7 @@ class BookUpdateOne extends Command
         $res = json_decode($res,true);
         $j = 0;
         $size = 0;
-        $local_count = Chapter::where('bid',$bid)->count();
+        $local_count = Chapter::where('bid',$bid)->where('ly_chapter_id','>',0)->count();
         $remote_count = 0;
 
         foreach ($res['data'] as $item1) {
@@ -96,16 +109,32 @@ class BookUpdateOne extends Command
             $item1 = null;
         }
         if($remote_count == $local_count) return '';
+        $start = false;
+        if(!$last_chapter){
+            $start = true;
+        }
+        $ly_last_chapter_id = 0;
+        if($last_chapter_from_third && isset($last_chapter_from_third->ly_chapter_id)){
+            $ly_last_chapter_id = $last_chapter_from_third->ly_chapter_id;
+        }
 
         foreach ($res['data'] as $v1) {
             foreach ($v1['chapters'] as $v) {
-                if ($v['chapter_order_number'] <= $max_sequence-1) {
+                /*if ($v['chapter_order_number'] <= $max_sequence-1) {
                     continue;
+                }*/
+                if(!$start){
+                    if($v['chapter_id'] != $ly_last_chapter_id){
+                        continue;
+                    }else{
+                        \Log::info($v1);
+                        $start = true;
+                        continue;
+                    }
                 }
-
-                if (Chapter::where('bid', $bid)->where('ly_chapter_id', $v['chapter_id'])->count()) {
+                /*if (Chapter::where('bid', $bid)->where('ly_chapter_id', $v['chapter_id'])->count()) {
                     continue;
-                }
+                }*/
 
                 $chapter_fromat = "http://www.leyuee.com/services/zwfx.aspx?method=chapter&bid=%s&cid=%s&token=sefaf23h7face";
                 $cahpter_content_res = $this->client->get(sprintf($chapter_fromat, $book_info->ly_bid, $v['chapter_id']));
@@ -114,7 +143,7 @@ class BookUpdateOne extends Command
                 $temp = [
                     'bid' => $bid,
                     'name' => $v['chapter_name'],
-                    'sequence' => $v['chapter_order_number']+1,
+                    'sequence' => ++$max_sequence,
                     'is_vip' => $v['chapter_need_pay'],
                     'prev_cid' => $max_sequence_chapter_id,
                     'next_cid' => '',

+ 1 - 1
app/Modules/Book/Services/ChapterService.php

@@ -357,7 +357,7 @@ class ChapterService
     public static function createSplitContent($chapter_id,$data,$is_adjust = true)
     {
         if(count($data) <= 1){
-            return ;
+            return 0;
         }
         Chapter::where('bid',$data[0]['bid'])->where('sequence','>=',$data[0]['sequence']+1)->increment('sequence',count($data)-1);
         Chapter::where('id',$chapter_id)->update([