<?php

namespace Main\Src;

use Dever;

class Preview
{
    # 获取二维码
    public function get()
    {
        $type = Dever::input('type');
        $id = Dever::input('id');

        $audit = Dever::input('audit');
        if ($audit) {
            $audit = Dever::db('audit/data')->one($id);
            $id = $audit['data_id'];
            $type = $audit['type'];
        }

    	$table = Dever::config('base')->type_table[$type];

        $info = Dever::db($table)->one($id);

        if (!$info) {
            return '暂无数据';
        }

    	$table = array();

        $path = Dever::config('base')->applet_index;
        //$scene = Dever::login(-1) . ',' . $type . ',' . $id;
        if ($type == 4 || $type == 13) {
            $scene = -1 . ',' . $type . ',' . 'preview_' . $id;
        } else {
            $scene = -1 . ',' . $type . ',' . $id;
        }
        

        if ($type == 13) {
            $id = $info['info_id'];
            $info = Dever::db('journal/info')->one($id);
        }

        if ($type == 1 || $type == 2 || $type == 3) {
            $info['cate_id'] = 1;
        }

        //echo $scene;die;
        if ($info['cate_id'] >= 4) {
            $info['cate_id'] = 1;
        }
        $send['project'] = $info['cate_id'];
        $send['send'] = $scene;
        $send['width'] = 152;
        $send['path'] = $path; 
        $logo = Dever::load('wechat_applet/code.get', $send);
        $html = '<img src="'.$logo.'" width="150">';

        $table['预览小程序码'] = $html;

        if ($type == 1 || $type == 2 || $type == 3 || $type == 6) {
            $link = Dever::url('view.get?type=' . $type . '&id=' . $id, 'h5');
            $table['h5页面'] = '<a class="clipboard" href="javascript:;" data-clipboard-text="'.$link.'">复制链接</a>';
        }
        

        if ($type == 3) {
            if ($info['url_m3u8']) {
                $table['m3u8回放地址'] = $info['url_m3u8'];
                $table['mp4回放地址'] = $info['url_mp4'];
            }
        }

        return Dever::table($table);
    }
}