Esempio n. 1
0
 public function actionScan()
 {
     $type = trim($this->post("type", "EAN_13"));
     $code = trim($this->post("isbn"));
     $date_now = date("Y-m-d H:i:s");
     //$this->recode("test");
     if (!$type || !$code) {
         return $this->renderJSON([], "请输入参数type 和 isbn", -1);
     }
     $book_info = Book::find()->where(['isbn' => $code])->one();
     if ($book_info) {
         return $this->renderJSON(["name" => $book_info['subtitle'], "origin_image_url" => $book_info['origin_image_url'], "isbn" => $book_info['isbn']]);
     }
     $ret = $this->doubanApi($code, $type);
     if (!$ret) {
         return $this->render([], "无法从豆瓣获取数据信息", -1);
     }
     $ret_upload = UploadService::uploadByUrl($ret['origin_image_url']);
     $model_book = new Book();
     $model_book->isbn = $ret['isbn'];
     $model_book->bartype = $ret['bartype'];
     $model_book->name = $ret['name'];
     $model_book->subtitle = $ret['subtitle'];
     $model_book->creator = json_encode($ret['creator']);
     $model_book->binding = $ret['binding'];
     $model_book->pages = $ret['pages'];
     $model_book->publish_date = date("Y-m-d", strtotime($ret['publish_date']));
     $model_book->publishing_house = $ret['publishing_house'];
     $model_book->tags = $ret['tags'];
     $model_book->summary = $ret['summary'];
     $model_book->image_url = $ret_upload ? $ret_upload['uri'] : '';
     $model_book->origin_image_url = $ret['origin_image_url'];
     $model_book->status = 0;
     $model_book->updated_time = $date_now;
     $model_book->created_time = $date_now;
     $model_book->save(0);
     return $this->renderJSON(["name" => $ret['subtitle'], "origin_image_url" => $ret['origin_image_url'], "isbn" => $code]);
 }
Esempio n. 2
0
 private function downImg($src_url)
 {
     $ret = UploadService::uploadByUrl($src_url);
     return $ret ? $ret['url'] : false;
 }