<?php
namespace app\controller;

use app\model\DocumentImages;
use app\model\GetGuide;
use app\model\Zskjsys;
use think\facade\Request;

class Zskjsy extends CommonTwoController
{

    /**
     * 搜索框下展示标签
     */
    public function searchLable()
    {
        $searchLabels = Zskjsys::$searchLable;
        $result = [];
        foreach($searchLabels as $key => $value)
        {
            $result[] = [
                'key'   => $key ,
                'value' => $value
            ];
        }
        return $this->_json_succ($result);
    }


    public function guideDetail()
    {
        if(!$id = Request::param('id') ?? '') {
            return $this->_json_error('请求参数有误！');
        }

        $guide    = GetGuide::find($id);
        if($guide['pdf']) {
            $pdfFileUrl = 'https://zskadmin.jiankangche.cn/uploads/'.$guide['pdf'];
        } elseif($guide['pdf_file']) {
            $pdfFileUrl = 'https://file.jiankangche.cn/'.$guide['pdf_file'].'.pdf';
        } else {
            $pdfFileUrl = 'https://jm.jiankangche.cn/zlznguidefile/' . $guide['title_trans'] . '.pdf';
        }

        $newGuide = [
            'title'         => $guide['title_trans'],
            'enTitle'       => $guide['title'],
            'source'        => $guide['source'],
            'abstract'      => $guide['abstract'],
            'abstract_trans'=> $guide['abstract_trans'],
            'constitutor'   => $guide['author'],
            'year'          => $guide['publish_time'],
            'full_text_url' => $guide['full_text_url'],
            'onlineRead'    => $pdfFileUrl
        ];
        return $this->_json_succ($newGuide);
    }




    /**
     * 检测pdf链接是否可访问
     */
    protected function checkDocPdfIsExist($url)
    {
        $check = get_headers($url);
        if(stripos($check[0] , '200') !== false) {
            return $url;
        }
        return "";
    }
}