|
|
|
|
@ -17,14 +17,14 @@ class UpdateBookIsbnData extends Command
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $signature = 'book:update-isbn-data';
|
|
|
|
|
protected $signature = 'book:update-isbn-data {--book_id=} ';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = '从ISBN接口获取书籍数据并下载封面图片';
|
|
|
|
|
protected $description = '从ISBN接口获取书籍数据,更新出版社、作者、出版年份、简介等信息并下载封面图片';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new command instance.
|
|
|
|
|
@ -44,16 +44,30 @@ class UpdateBookIsbnData extends Command
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$apiKey = Config::getValueByKey('book_key');
|
|
|
|
|
$book_id = $this->option('book_id');
|
|
|
|
|
|
|
|
|
|
// 获取所有有ISBN的书籍
|
|
|
|
|
$books = Book::whereNotNull('isbn')
|
|
|
|
|
->where('isbn', '!=', '')
|
|
|
|
|
->whereNull('cover_id')
|
|
|
|
|
// ->where('id', 1)
|
|
|
|
|
->get();
|
|
|
|
|
->where(function ($query) use ($book_id) {
|
|
|
|
|
if ($book_id) {
|
|
|
|
|
$query->where('id', $book_id);
|
|
|
|
|
}
|
|
|
|
|
})->where('isbn', '!=', '')
|
|
|
|
|
->where(function ($query) {
|
|
|
|
|
// 如果没有封面或者缺少基本信息字段,都需要处理
|
|
|
|
|
$query->whereNull('cover_id')
|
|
|
|
|
->orWhereNull('publisher')
|
|
|
|
|
->orWhereNull('author')
|
|
|
|
|
->orWhereNull('publish_year')
|
|
|
|
|
->orWhereNull('description')
|
|
|
|
|
->orWhere('publisher', '')
|
|
|
|
|
->orWhere('author', '')
|
|
|
|
|
->orWhere('publish_year', '')
|
|
|
|
|
->orWhere('description', '');
|
|
|
|
|
})->get();
|
|
|
|
|
|
|
|
|
|
if ($books->isEmpty()) {
|
|
|
|
|
$this->info('没有找到未处理封面的书籍');
|
|
|
|
|
$this->info('没有找到需要更新数据的书籍');
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -169,7 +183,24 @@ class UpdateBookIsbnData extends Command
|
|
|
|
|
|
|
|
|
|
$bookData = $data['data'];
|
|
|
|
|
|
|
|
|
|
// 更新书籍的other_data字段
|
|
|
|
|
// 更新书籍的基本信息字段
|
|
|
|
|
if (!empty($bookData['publisher'])) {
|
|
|
|
|
$book->publisher = $bookData['publisher'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($bookData['author'])) {
|
|
|
|
|
$book->author = $bookData['author'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($bookData['pubdate'])) {
|
|
|
|
|
$book->publish_year = $bookData['pubdate'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($bookData['summary'])) {
|
|
|
|
|
$book->description = $bookData['summary'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新书籍的other_data字段(保存完整的API响应数据)
|
|
|
|
|
$book->other_data = $bookData;
|
|
|
|
|
|
|
|
|
|
// 如果有图片URL,下载图片
|
|
|
|
|
|