createBook(); if($create_info['error']){ return ; } $filname = $this->option('filename'); if(!$filname){ $this->error('filename empty'); return ; } $result = $create_info['book']; $chapter_result = $this->createChapter( $result->id,$filname); $result->size = $chapter_result['size']; $result->chapter_count = $chapter_result['chapter_count']; $result->first_cid = $chapter_result['first_cid']; $result->last_cid = $chapter_result['last_cid']; $result->last_chapter = $chapter_result['last_chapter']; $result->save(); } private function createBook(){ $cp_id = $this->option('cp_id'); $book_name = $this->option('name'); $author = $this->option('author'); $category_id = $this->option('category_id'); $cp_name = $this->getCpName($cp_id); if(!$cp_name){ $this->error('cp_id不存在'); return ['error'=>1]; } $category_info = $this->getCategoryInfo($category_id); if(!$category_info){ $this->error('分类id不存在'); return ['error'=>2]; } $result = BooksService::createBook([ 'cp_name'=>$cp_name,'cp_id'=>$cp_id,'name'=>$book_name,'author'=>$author ?? '','intro'=>'','cover'=>'','category_id'=>$category_id, 'category_name'=>$category_info->category_name,'status'=>1,'channel'=>$category_info->channel_id ]); if(!$result){ $this->error('已经存在了'); return ['error'=>3]; } return ['error'=>0,'book'=>$result]; } private function createChapter($bid,$filname){ $vip_start = $this->option('vip'); $path = storage_path('app/'.$filname); return ChapterService::createChapterFromFile($bid,1,$vip_start ?? 8,$path); } private function getCpName($cp_id){ $cp_info = Cps::where('cp_id',$cp_id)->select('cp_nick')->first(); if($cp_info){ return $cp_info->cp_nick; } return ''; } private function getCategoryInfo($category_id){ return BookCategories::where('id',$category_id)->first(); } }