1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use DB;
- class BookAdjustOne extends Command
- {
-
- protected $signature = 'book:adjustone {--bid= : the id of a book}';
-
- protected $description = '调整所有章节顺序prev_cid和next_cid';
-
- public function __construct()
- {
- parent::__construct();
- }
-
- public function handle()
- {
- $bid = $this->option('bid');
- if(empty($bid)) return 0;
- $this->adjustSequentOne($bid);
- }
-
- public function adjustSequentOne($bid){
- $chapter_list = DB::table('chapters')->orderBy('sequence')->where('bid',$bid)->select('id')->get();
- $prev = 0;
- foreach ($chapter_list as $chapter){
- if($prev){
- DB::table('chapters')->where('id',$chapter->id)->update(['prev_cid'=>$prev]);
- DB::table('chapters')->where('id',$prev)->update(['next_cid'=>$chapter->id]);
- }
- $prev = $chapter->id;
- }
- }
- }
|