<?php

namespace Main\Src;

use Dever;
use Main\Lib\Core;

class View extends Core
{
    # 获取单页链接
    public function getLink($key, $name, $type = 5)
    {
        $link = Dever::url('agreement?key=' . $key . '&type=' . $type . '&name=' . $name, 'main');
        return $link;
    }

    # 获取单页详情
    public function getPage()
    {
        $this->data['info'] = $this->page();

        return $this->data;
    }

    # 获取单页详情
    public function page()
    {
        $type = Dever::input('type', 1);
        if (!$type) {
            Dever::alert('您访问的页面有误');
        }

        $key = Dever::input('key');
        if (!$key) {
            Dever::alert('您访问的页面有误');
        }

        $name = Dever::input('name');

        $where['type'] = $type;
        $where['key'] = $key;
        $info = Dever::db('main/page')->find($where);

        if (!$info) {
            $insert = $where;
            $insert['name'] = $name;
            $insert['content'] = $name;
            $id = Dever::db('main/page')->insert($insert);
            $info = Dever::db('main/page')->find($id);
        }

        return $info;
    }
}