12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use App\Modules\Book\Models\Chapter;
- use App\Modules\Book\Models\Book;
- class BookAdjust extends Command
- {
-
- protected $signature = 'book:adjust';
-
- protected $description = '调整所有章节顺序prev_cid和next_cid';
-
- public function __construct()
- {
- parent::__construct();
- }
-
- public function handle()
- {
- $this->adjustSequentAll();
- return 1;
- }
-
- public function adjustSequentAll(){
- set_time_limit(0);
- Book::where('last_cid','!=',0)->where('id','>=',807)->select('id')->get()->map(function ($item, $key){
- $this->adjustSequentOne($item->id);
- });
- }
-
- public function adjustSequentOne($bid){
- $chapter_list = Chapter::getChapterLists($bid);
- $prev = 0;
- foreach ($chapter_list as $chapter){
- if($prev){
- Chapter::where('id',$chapter->id)->update(['prev_cid'=>$prev]);
- Chapter::where('id',$prev)->update(['next_cid'=>$chapter->id]);
- }
- $prev = $chapter->id;
- }
- }
- }
|