123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Http\Controllers\Channel\Book;
- use GuzzleHttp\Client;
- use GuzzleHttp\Exception\RequestException;
- use Hashids;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Channel\BaseController;
- use App\Http\Controllers\Channel\Book\Transformers\ChapterImageTransformer;
- use App\Libs\ChapterToImage;
- use App\Modules\Book\Services\ChapterImageService;
- use App\Modules\Book\Services\ChapterService;
- use Psr\Http\Message\ResponseInterface;
- class ChapterImageController extends BaseController
- {
-
-
- public function getTopFiveChapter(Request $request) {
- $bid = $request->has('bid') ? $request->input('bid') : '';
- if (empty($bid)) return response()->error("PARAM_EMPTY");
- $bid = Hashids::decode($bid)[0];
- $chapter_count = ChapterImageService::getChapterImgCount($bid);
- $chapters = ChapterService::getTopFiveChapter($bid);
- $result = ChapterImageService::getChapterImage($bid);
- if(empty($result) || sizeof($result) == 0 || $chapter_count < sizeof($chapters)) {
- ChapterToImage::createChapterImage($bid,'',$chapters);
- $result = ChapterImageService::getChapterImage($bid);
- }
- $resultAA = array();
- if($result && sizeof($result) > 0) {
- foreach ($result as $rr) {
- $cid = $rr['cid'];
- $resultAA[$cid][] = ['image_url'=>$rr['image_url'],'height'=>$rr['image_height'],'id'=>$rr['id']];
- }
- }
- $resultBB = array();
- $client = new Client();
- if($resultAA && sizeof($resultAA) > 0) {
- foreach ($resultAA as $key => $value) {
-
- $temp = [];
- foreach ($value as $img){
- $height = $img['height'];
-
- if(!$height){
- preg_match("/(\w+:\/\/)([^\/:]+)([^?]+)?([\/s\/S]*)/",$img['image_url'],$matches);
- $imageInfo = $client->request('GET', env('OSS_INTERNAL_DOMAIN').$matches[3].'?x-oss-process=image/info')->getBody()->getContents();
-
- if($imageInfo){
- $imageInfo = json_decode($imageInfo,true);
- if(isset($imageInfo['ImageHeight']['value'])){
- $height = $imageInfo['ImageHeight']['value'];
- $param = array(
- 'file_size'=>$imageInfo['FileSize']['value'],
- 'image_height'=>$imageInfo['ImageHeight']['value'],
- 'image_width'=>$imageInfo['ImageWidth']['value']
- );
- ChapterImageService::updateChapterImage($img['id'],$param);
- }
- }
- if(!$height){
- $height = 300;
- }
- }
- $temp[] = ['image_url'=>$img['image_url'],'height'=>$height];
- }
- $resultBB[] = $temp;
- }
- }
- return response()->success($resultBB);
- }
- }
|