<?php
/**
 *  Guojiz网址导航系统
 *	www.guojiz.com
 *  作者：梦雨
 *  @ QQ50361804
 */
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Cache;
use Qcloud\SmsSingleSender;
use app\index\model\Comment as CommentModel;
class Index extends Controller
{
    public function _initialize()
    {
    }
    public function de()
    {
        $or = input('or');
        $this->assign('or', $or);
        return view();
    }
    //自定义页面
    public function guojiz()
    {
        if (isMobile() == true) {
            if (config('muban.wap_open') == 1) {
                return view('application/template/wap/' . MBWAP() . '/wap/'.input('or').'.html');
            } else {
                return view('application/template/pc/' . MBPC() . '/pc/'.input('or').'.html');
            }
        } else {
            return view('application/template/pc/' . MBPC() . '/pc/'.input('or').'.html');
        }
    }
    public function index()
    {
        $show['show'] = 1;
        $map['open'] = 1;
        $map['choice'] = 1;
        $time = time();
        //时间
        $end_stime = strtotime(date('Y-m-d'));
        $time1 = strtotime(date('Y-m-d', strtotime('-30 day')));
        //今天数据
        $to1 = Db::name('top')->where("time > {$end_stime}")->sum('view');
        $this->assign('to1', $to1);
        $to2 = Db::name('top')->where("time > {$end_stime}")->group('tid')->count();
        $this->assign('to2', $to2);
        //查询今日来路最多的域名
        $lailu = Db::name('html')->alias('h')->join('lailu t', 't.tid=h.id')->where("t.time > {$end_stime}")->field('count(t.tid),h.*')->orderRaw('count(t.tid) desc')->group('t.lianjie')->select();
        $lailus = Db::name('html')->alias('h')->join('lailu t', 't.tid=h.id')->where("t.time > {$end_stime}")->field('count(t.tid),h.*')->orderRaw('t.id desc')->group('t.lianjie')->select();
        $this->assign('lailu', $lailu);
        $this->assign('lailus', $lailus);
        //本月数据
        $to3 = Db::name('top')->where("time > {$time1}")->sum('view');
        $this->assign('to3', $to3);
        $to4 = Db::name('top')->where("time > {$time1}")->group('tid')->count();
        $this->assign('to4', $to4);
        //全部数据
        $to5 = Db::name('top')->sum('view');
        $this->assign('to5', $to5);
        $to6 = Db::name('top')->group('tid')->count();
        $this->assign('to6', $to6);
        //今日最受欢迎网站
        $to7 = Db::name('top')->alias('t')->join('html h', 'h.id=t.tid')->where("t.time > {$end_stime}")->field('h.*')->order('t.view desc')->value('h.title');
        $this->assign('to7', $to7);
        //分类展示网址
        $artbycatelist = Db::name('category')->where($show)->order('sort desc')->select();
        foreach ($artbycatelist as $k => $v) {
            $artbycatelist[$k]['artlists'] = get_articles_by_cid($v['id'], 5);
        }
        $this->assign('artbycatelist', $artbycatelist);
        //最近30天文章排行
        $maptop30['open'] = 1;
        $maptop30['time'] = array('egt', strtotime("-1 month"));
        $news_top30 = Db::name('news')->where($show)->order('view desc')->select();
        $this->assign('news_top30', $news_top30);
        //猜你喜欢
        $guojizcai = Db::name('html')->where('open = 1')->orderRaw('rand()')->select();
        $this->assign('guojizcai', $guojizcai);
        return view(WEB('index_index.html'));
    }
    //ajax获取首页分类数据
    public function ajax()
    {
        $id = input('id');
        if ($id == '') {
            $wanneng = Db::name('html')->where('open', 1)->order('px desc,id desc')->limit(27)->select();
        } else {
            $wanneng = Db::name('html')->where('open', 1)->where('tid', $id)->order('px desc')->limit(27)->select();
        }
        print '{"status":200,"html":"';
        foreach ($wanneng as $html) {
            echo '<li><a href=\\"/daohang/' . $html['id'] . '.html\\"> <div class=\\"ulimg\\"><img  onerror=\\"javascript:this.src=\'/favicon.ico\';\\" src=\\"' . $html['ico'] . '\\"/></div><div class=\\"program-title\\">' . $html['title'] . '</div></a></li>\\n';
        }
        print '"}';
    }
    //获取用户自定义收藏数据
    public function url()
    {
        if (!user('userid')) {
            return json(array('code' => 0, 'msg' => '请登录'));
        }
        $arr = Db::name('user_url')->where(array('uid' => user('userid')))->order('px desc,id desc')->select();
        $msg['data'] = $arr;
        echo json_encode($msg, true);
    }
    //用户自定义添加链接
    public function url_add()
    {
        if (!user('userid')) {
            return json(array('code' => 0, 'msg' => '请登录'));
        }
        $data['title'] = get('title');
        $data['url'] = get('url');
        $data['time'] = time();
        $data['uid'] = user('userid');
        $data['colour'] = get('colour');
        $data['px'] = get('px');
        $c = Db::name('user_url')->where(array('url' => get('url'), 'uid' => user('userid')))->find();
        if (vip() == 0) {
            if (funt('user_url', array('uid' => user('userid'))) >= guojiz('user_url_s')) {
                return json(array('code' => 0, 'msg' => '最多可以自定义添加' . guojiz('user_url_s') . '个网站'));
            }
        } else {
        	if (funt('user_url', array('uid' => user('userid'))) >= guojiz('user_url_sv')) {
                return json(array('code' => 0, 'msg' => '最多可以自定义添加' . guojiz('user_url_sv') . '个网站'));
            }
        }
        if ($c['url']) {
            return json(array('code' => 0, 'msg' => '当前链接存在'));
        }
        if (Db::name('user_url')->data($data)->insert()) {
            return json(array('code' => 1, 'msg' => '添加成功'));
        } else {
            return json(array('code' => 0, 'msg' => '添加失败'));
        }
    }
    //用户修改url数据
    public function url_update()
    {
        if (!user('userid')) {
            return json(array('code' => 0, 'msg' => '请登录'));
        }
        $data['title'] = get('title');
        $data['url'] = get('url');
        $data['time'] = time();
        $data['uid'] = user('userid');
        $data['colour'] = get('colour');
        $data['px'] = get('px');
        if (Db::name('user_url')->where(array('id' => get('id')))->update($data)) {
            return json(array('code' => 1, 'msg' => '更新成功'));
        } else {
            return json(array('code' => 0, 'msg' => '更新失败'));
        }
    }
	//用户删除链接
    public function url_un()
    {
        if (!user('userid')) {
            return json(array('code' => 0, 'msg' => '请登录'));
        }
        if (Db::name('user_url')->where(array('id' => get('id')))->delete()) {
            return json(array('code' => 1, 'msg' => '删除成功'));
        } else {
            return json(array('code' => 0, 'msg' => '删除失败'));
        }
    }


    public function view()
    {
        if (!preg_match("/^\d*$/",input('id'))) {
            return $this->error('亲！你迷路了');
        }
        $id = get('id');
        $or = input('or');
        if ($or!='') {
            if ($or!='id' && $or!='view') {
                return $this->error('亲！你迷路了.');
            }
        }
        if (empty($id)) {
            $this->error('亲！你迷路了', '/');
        } else {
            $category = Db::name('category');
            $c = $category->where("show", 1)->where("id = {$id}")->find();
            if ($c) {
                $html = Db::name('html');
                $open['open'] = 1;
                $id = $c['id'];
                $description = $c['description'];
                $keywords = $c['keywords'];
                $name = $c['name'];
                if (empty($or)) {
                    $guojiz = $html->alias('f')->join('category c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,m.userid,m.userhead,m.username,c.name,c.keywords,c.description')->where("f.tid={$id} or c.tid={$id}")->where($open)->order('f.px desc,f.id desc')->paginate(24);
                } else {
                    $guojiz = $html->alias('f')->join('category c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,m.userid,m.userhead,m.username,c.name,c.keywords,c.description')->where("f.tid={$id} or c.tid={$id}")->where($open)->order('f.' . $or . ' desc')->paginate(24);
                }
                $this->assign('guojiz', $guojiz);
                $this->assign('or', $or);
                $this->assign('name', $name);
                $this->assign('keywords', $keywords);
                $this->assign('description', $description);
                $this->assign('id', $id);
                $this->assign('c', $c);
                return view(WEB('index_view.html'));
            } else {
                $this->error('亲！你迷路了', '/');
            }
        }
    }
    public function zan()
    {
        $id = input('tid');
        $map['ip'] = array('eq', $_SERVER['REMOTE_ADDR']);
        $cha = Db::name('zan')->where('tid', $id)->where($map)->count();
        if ($cha > 0) {
            return json(array('code' => 0, 'msg' => '不能重复评分'));
        } else {
            $data['tid'] = $id;
            $data['pf'] = input('pf');
            $data['time'] = time();
            $data['ip'] = $_SERVER['REMOTE_ADDR'];
            if (Db::name('zan')->insert($data)) {
                return json(array('code' => 200, 'msg' => '评分成功'));
            } else {
                return json(array('code' => 0, 'msg' => '评分失败'));
            }
        }
    }
    public function news()
    {
        $html = Db::name('news');
        $show['show'] = 1;
        $news = $html->where($show)->where('time', '<', time())->order('id desc')->paginate(15);
        $this->assign('news', $news);
        return view(WEB('index_news.html'));
    }
    public function newsso()
    {
        $ks = input('ks');
        if (empty($ks)) {
            $this->error('亲！你迷路了', '/');
        } else {
            $new = Db::name('news');
            $show['show'] = 1;
            $news = $new->order('id desc')->where($show)->where('time', '<', time())->where('title', 'like', '%' . $ks . '%')->paginate(15, false, $config = ['query' => array('ks' => $ks)]);
            $this->assign('news', $news);
            return view(WEB('index_newsso.html'));
        }
    }
    public function search()
    {
        $ks = input('ks');
        if (empty($ks)) {
            $this->error('亲！你迷路了', '/');
        } else {
            $html = Db::name('html');
            $show['open'] = 1;
            $tptc = $html->order('id desc')->where($show)->where('title|keywords', 'like', '%' . $ks . '%')->paginate(12, false, $config = ['query' => array('ks' => $ks)]);
            $this->assign('tptc', $tptc);
            return view(WEB('index_search.html'));
        }
    }
    public function tag()
    {
        $tag = input('tag');
        $html = Db::name('html');
        $show['open'] = 1;
        $tptc = $html->order('id desc')->where($show)->where('title|keywords', 'like', '%' . $tag . '%')->paginate(12);
        $this->assign('tptc', $tptc);
        return view(WEB('index_tag.html'));
    }
    public function tags()
    {
        $tag = input('tag');
        $html = Db::name('news');
        $show['show'] = 1;
        $news = $html->order('id desc')->where('time', '<', time())->where($show)->where('title|keywords', 'like', '%' . $tag . '%')->paginate(12);
        $this->assign('news', $news);
        return view(WEB('index_tags.html'));
    }
    public function article()
    {
        if (!preg_match("/^\d*$/",input('id'))) {
            return $this->error('亲！你迷路了');
        }
        $id = get('id');
        if (empty($id)) {
            $this->error('亲！你迷路了', '/');
        } else {
            $newscate = Db::name('newscate');
            $c = $newscate->where("show", 1)->where("id = {$id}")->find();
            if ($c) {
                $news = Db::name('news');
                $id = $c['id'];
                $name = $c['name'];
                $news = $news->alias('f')->join('newscate c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,m.userid,m.userhead,m.username,c.name,c.keywords,c.description')->where('f.time', '<', time())->where("f.tid={$id} or c.tid={$id}")->where('f.show = 1')->order('f.id desc')->paginate(12);
                $this->assign('news', $news);
                $this->assign('name', $name);
                $this->assign('id', $id);
                return view(WEB('index_article.html'));
            } else {
                $this->error('亲！你迷路了', '/');
            }
        }
    }
    public function dan()
    {
        $id = get('id');
        if (empty($id)) {
            $this->error('亲！你迷路了', '/');
        } else {
            $dans = Db::name('dan');
            if (is_numeric($id)) {
                $t = $dans->where("id = {$id}")->find();
                $alias = 'id';
            } else {
                $t = $dans->where(array('alias' => $id))->find();
                $alias = 'alias';
            }
            if ($t) {
                $map['show'] = 1;
                $dans->where(array($alias => $id))->setInc('view', 1);
                $this->assign('t', $t);
                $content = $t['content'];
                $content = htmlspecialchars_decode($content);
                $this->assign('content', $content);
                return view(WEB($t['muban']));
            } else {
                $this->error('亲！你迷路了', '/');
            }
        }
    }
    public function lists()
    {
        $id = get('id');
        $this->assign('id', $id);
        //分类展示网址
        $show['show'] = 1;
        $artbycatelist = Db::name('category')->where($show)->order('sort desc')->select();
        foreach ($artbycatelist as $k => $v) {
            $artbycatelist[$k]['artlists'] = get_articles_by_cid($v['id'], 5);
        }
        $this->assign('artbycatelist', $artbycatelist);
        return view(WEB('index_lists.html'));
    }
    public function topdj()
    {
        $id = get('id');
        $time0 = strtotime(date('Y-m-d'));
        $today_update = Db::name('top')->where(array('tid' => $id))->where("time > {$time0}")->count();
        $this->assign('today_update', $today_update);
        if ($today_update > 0) {
            Db::name('top')->where("time > {$time0}")->where(array('tid' => $id))->setInc('view', 1);
        } else {
            $data['tid'] = $id;
            $data['show'] = 1;
            $data['time'] = time();
            Db::name('top')->insert($data);
        }
        if(Db::name('html')->where(array('id' => $id))->count()==0){
            Db::name('top')->where(array('tid' => $id))->delete();
        }
         
        Db::name('html')->where(array('id' => $id))->setInc('view', 1);
        $this->success("正在跳转到 - ".fun_sc_p('html', array('id' => $id),  'title'),'http://'.fun_sc_p('html', array('id' => $id),  'lianjie').'?lailu='.get('lailu','guojiz.com'));
    }
    public function top()
    {
        $id = get('id');
        $time = time();
        $map['open'] = 1;
        $type = input('type');
        if ($type == 'art' || $type == '') {
            $tops = Db::name('html')->where($map)->order('view desc')->limit(24)->select();
            foreach ($tops as $k => $v) {
                $tops[$k]['count'] = Db::name('top')->where('tid', $v['id'])->count();
            }
            $this->assign('tops', $tops);
        } elseif ($type == 'today') {
            $end_stime = strtotime(date('Y-m-d'));
            $tops = Db::name('html')->alias('h')->join('top t', 't.tid=h.id')->where("t.time > {$end_stime}")->field('h.*')->order('t.view desc')->where($map)->limit(24)->select();
            foreach ($tops as $k => $v) {
                $end_stime = strtotime(date('Y-m-d'));
                $tops[$k]['count'] = Db::name('top')->where("time > {$end_stime}")->where('tid', $v['id'])->value('view');
            }
            $this->assign('tops', $tops);
        }
        $this->assign('type', $type);
        return view(WEB('index_top.html'));
    }
    public function xq()
    {
        if (!preg_match("/^\d*$/",input('id'))) {
            return $this->error('亲！你迷路了');
        }
        $id = get('id');
        if (empty($id)) {
            $this->error('亲！你迷路了', '/');
        } else {
            $news = Db::name('news');
            //附件
            $a = $news->where("show", 1)->where('time', '<', time())->where("id = {$id}")->find();
            if ($a['fujian'] != '') {
                $arr = explode(',', $a['fujian']);
                for ($i = 0; $i < count($arr); $i++) {
                    $arr2 = explode('|', $arr[$i]);
                    $lianjie[$i]['name'] = $arr2[0];
                    $lianjie[$i]['url'] = $arr2[1];
                    $lianjie[$i]['urls'] = $i;
                }
                $this->assign('lianjie', $lianjie);
            }
            //提交下载
            if (request()->isPost()) {
                if (warning() == shul()) {
                    $times = Db::name('member')->where('userid', session('userid'))->value('times');
                    if ($times >= time()) {
                        $vip = Db::name('member')->where('userid', session('userid'))->value('vip');
                    } else {
                        $vip = 0;
                    }
                    if ($vip == 1 || $vip == 2) {
                        $data = $this->request->post();
                        $urls = input('urls');
                        return array('code' => 200, 'msg' => '开始下载', 'path' => $lianjie[$urls]['url']);
                    } else {
                        if ($a['jifen'] == 0) {
                            $data = $this->request->post();
                            $urls = input('urls');
                            return array('code' => 200, 'msg' => '开始下载', 'path' => $lianjie[$urls]['url']);
                        } else {
                            if (!session('userid') || !session('username')) {
                                return json(array('code' => 0, 'msg' => '请登录'));
                            } else {
                                $data = $this->request->post();
                                $urls = input('urls');
                                $uid = session('userid');
                                $point = Db::name('member')->where('userid', session('userid'))->value('point');
                                if ($point < $a['jifen'] && $a['jifen'] > 0) {
                                    return array('code' => 0, 'msg' => '余额不足,请充值..');
                                } else {
                                    Db::name('member')->where('userid', $uid)->setDec('point', $a['jifen']);
                                    return array('code' => 200, 'msg' => '开始下载', 'path' => $lianjie[$urls]['url']);
                                }
                            }
                        }
                    }
                } else {
                    return array('code' => 0, 'msg' => config('web.sq'));
                }
            }
            if ($a) {
                $map['show'] = 1;
                $news->where("id = {$id}")->setInc('view', 1);
                $t = $news->alias('f')->join('newscate c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,c.name,m.userid,m.grades,m.point,m.userhead,m.username')->find($id);
                $this->assign('t', $t);
                $content = $t['content'];
                $content = htmlspecialchars_decode($content);
                $this->assign('content', $content);
                //上一篇
                $open['open'] = 1;
                $tptf = Db::name('news')->where('id > ' . $id)->limit(1)->select();
                $this->assign('tptf', $tptf);
                //下一篇
                $tpta = Db::name('news')->where('id < ' . $id)->order('id desc')->limit('1')->select();
                $this->assign('tpta', $tpta);
                //同类随机
                $choice['tid'] = $t['tid'];
                $artchoice = $news->where($choice)->where($map)->orderRaw('rand()')->limit(12)->select();
                $this->assign('artchoice', $artchoice);
                $tptc = Db::name('comment')->alias('c')->join('member m', 'm.userid=c.uid')->where("fid = {$id}")->order('c.id asc')->paginate(8);
                $this->assign('tptc', $tptc);
                return view(WEB('index_xq.html'));
            } else {
                $this->error('亲！你迷路了', '/');
            }
        }
    }
    public function wzadd()
    {
        if (!session('userid') || !session('username')) {
            $this->error('亲！请登录');
        } else {
            $comment = new CommentModel();
            $id = get('id');
            $uid = session('userid');
            if (request()->isPost()) {
                $data = input('post.');
                if (empty($data['content'])) {
                    $this->error('说点什么吧!');
                }
                $data['time'] = time();
                $data['fid'] = $id;
                $data['tid'] = 1;
                $data['uid'] = session('userid');
                $k = preg_replace("/<|>/s", "", $data['content']);
                $data['content'] = remove_xss($k);
                $member = Db::name('member');
                $member->where('userid', session('userid'))->setInc('point', config('point.EDIT_POINT'));
                $jz = Date_k(0);
                $jw = Date_k(1);
                $cha = Db::name('comment')->where('uid', session('userid'))->where("time > {$jz} and time < {$jw}")->count();
                if ($cha >= guojiz('pinglunxz')) {
                    return json(array('code' => 0, 'msg' => '今天评论次数过多明天再来'));
                }
                if ($comment->add($data)) {
                    return json(array('code' => 200, 'msg' => '评论成功'));
                } else {
                    return json(array('code' => 0, 'msg' => '评论失败'));
                }
            }
        }
    }
    public function html()
    {
        if (!preg_match("/^\d*$/",input('id'))) {
            return $this->error('亲！你迷路了');
        }
        $id = get('id');
        if (empty($id)) {
            $this->error('亲！你迷路了', '/');
        } else {
            //查询评分数量
            $zanpx = Db::name('zan')->where('tid', $id)->count();
            $this->assign('zanpx', $zanpx);
            //查询记录和
            $zanhe = Db::name('zan')->where('tid', $id)->avg('pf');
            $this->assign('zanhe', $zanhe);
            $member = Db::name('member')->where('userid', session('userid'))->find();
            $this->assign('member', $member);
            $html = Db::name('html');
            $a = $html->where("open", 1)->where("id = {$id}")->find();
            if ($a) {
                $open = $html->where("id = {$id}")->value('open');
                if ($open == '1') {
                    $html->where("id = {$id}")->setInc('view', 1);
                    $t = $html->alias('f')->join('category c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,c.name,m.userid,m.grades,m.point,m.userhead,m.username')->find($id);
                    $this->assign('t', $t);
                } else {
                    return $this->error('亲！网站正在审核', 'index/index/index');
                }
                $times = time();
                $tops = Db::name('html')->where("id = {$id}")->order('id desc')->limit(12)->select();
                foreach ($tops as $k => $v) {
                    $tops[$k]['count'] = Db::name('top')->where('time' >= $times)->where('tid', $v['id'])->count();
                }
                //点击 2019 06 20
                $time0 = strtotime(date('Y-m-d'));
                //今天
                $this->assign('time0', $time0);
                $time1 = strtotime(date('Y-m-d', strtotime('-1 day')));
                $this->assign('time1', $time1);
                $time2 = strtotime(date('Y-m-d', strtotime('-2 days')));
                $this->assign('time2', $time2);
                $time3 = strtotime(date('Y-m-d', strtotime('-3 days')));
                $this->assign('time3', $time3);
                $time4 = strtotime(date('Y-m-d', strtotime('-4 days')));
                $this->assign('time4', $time4);
                $time5 = strtotime(date('Y-m-d', strtotime('-5 days')));
                $this->assign('time5', $time5);
                $time6 = strtotime(date('Y-m-d', strtotime('-6 days')));
                $this->assign('time6', $time6);
                $time7 = strtotime(date('Y-m-d', strtotime('-7 days')));
                $this->assign('time7', $time7);
                $time8 = strtotime(date('Y-m-d', strtotime('-8 days')));
                $this->assign('time8', $time8);
                $time9 = strtotime(date('Y-m-d', strtotime('-9 days')));
                $this->assign('time9', $time9);
                $today_update = Db::name('top')->where("tid = {$id}")->where("time > {$time0}")->value('view');
                $this->assign('today_update', $today_update);
                $today_update1 = Db::name('top')->where("tid = {$id}")->where("time < {$time0} and time > {$time1}")->value('view');
                $this->assign('today_update1', $today_update1);
                $today_update2 = Db::name('top')->where("tid = {$id}")->where("time < {$time1} and time > {$time2}")->value('view');
                $this->assign('today_update2', $today_update2);
                $today_update3 = Db::name('top')->where("tid = {$id}")->where("time < {$time2} and time > {$time3}")->value('view');
                $this->assign('today_update3', $today_update3);
                $today_update4 = Db::name('top')->where("tid = {$id}")->where("time < {$time3} and time > {$time4}")->value('view');
                $this->assign('today_update4', $today_update4);
                $today_update5 = Db::name('top')->where("tid = {$id}")->where("time < {$time4} and time > {$time5}")->value('view');
                $this->assign('today_update5', $today_update5);
                $today_update6 = Db::name('top')->where("tid = {$id}")->where("time < {$time5} and time > {$time6}")->value('view');
                $this->assign('today_update6', $today_update6);
                $today_update7 = Db::name('top')->where("tid = {$id}")->where("time < {$time6} and time > {$time7}")->value('view');
                $this->assign('today_update7', $today_update7);
                $today_update8 = Db::name('top')->where("tid = {$id}")->where("time < {$time7} and time > {$time8}")->value('view');
                $this->assign('today_update8', $today_update8);
                $today_update9 = Db::name('top')->where("tid = {$id}")->where("time < {$time8} and time > {$time9}")->value('view');
                $this->assign('today_update9', $today_update9);
                $this->assign('tops', $tops);
                //同类随机
                $choice['tid'] = $t['tid'];
                $artchoice = $html->where($choice)->where("open = 1")->orderRaw('rand()')->limit(12)->select();
                $this->assign('artchoice', $artchoice);
                $content = $t['content'];
                $content = htmlspecialchars_decode($content);
                $this->assign('content', $content);
                $tptc = Db::name('comment')->alias('c')->join('member m', 'm.userid=c.uid')->where("fid = {$id}")->order('c.id asc')->paginate(15);
                $this->assign('tptc', $tptc);
                //点击数据
                $timess = strtotime(date('Y-m-d'));
                $today_updatedj = Db::name('top')->where("tid = {$id}")->where("time > {$timess}")->count();
                $this->assign('today_updatedj', $today_updatedj);
                if ($today_update > 0) {
                    Db::name('top')->where("time > {$timess}")->where("tid = {$id}")->setInc('view', 1);
                } else {
                    $data['tid'] = $id;
                    $data['show'] = 1;
                    $data['time'] = time();
                    Db::name('top')->insert($data);
                }
                return view(WEB('index_html.html'));
            } else {
                $this->error('亲！你迷路了', '/');
            }
        }
    }
    //pc设置
    public function cmspc()
    {
        if (!session('usermail') || !session('kouling')) {
            $this->error('请登录', url('admin/login/index'));
        } else {
            if (request()->isPost()) {
                $url = 'application/template/pc/' . mbpc() . '/Cms_pc.php';
                $info = (include $url);
                $config = array();
                $config = $this->request->post();
                $config = preg_replace("/\\[|\\]|'|\\<\\?php|\\?\\>|embed|data:|iframe|code/i", '', $config);
                $res = array_merge($info, $config);
                $str = '<?php return [';
                foreach ($res as $key => $value) {
                    $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
                }
                $str .= ']; ';
                if (file_put_contents($url, $str)) {
                    return json(array('code' => 200, 'msg' => '修改成功'));
                } else {
                    return json(array('code' => 0, 'msg' => '修改失败'));
                }
            }
            return view('application/template/pc/' . mbpc() . '/Cms_pc.html');
        }
    }
    //wap设置
    public function cmswap()
    {
        if (!session('usermail') || !session('kouling')) {
            $this->error('请登录', url('admin/login/index'));
        } else {
            if (request()->isPost()) {
                $url = 'application/template/wap/' . mbwap() . '/Cms_wap.php';
                $info = (include $url);
                $config = array();
                $config = $this->request->post();
                $config = preg_replace("/\\[|\\]|'|\\<\\?php|\\?\\>|embed|data:|iframe|code/i", '', $config);
                $res = array_merge($info, $config);
                $str = '<?php return [';
                foreach ($res as $key => $value) {
                    $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
                }
                $str .= ']; ';
                if (file_put_contents($url, $str)) {
                    return json(array('code' => 200, 'msg' => '修改成功'));
                } else {
                    return json(array('code' => 0, 'msg' => '修改失败'));
                }
            }
            return view('application/template/wap/' . mbwap() . '/Cms_wap.html');
        }
    }
    public function sn()
    {
        if (funt('sn',array('open'=>1,'name'=>input('name')))==0) {
            cookie('sn', 0);
            $this->success('切换成功');
        } else {
            cookie('sn', input('name'));
            $this->success('切换成功');
        }
    }
    public function hover()
    {
        cookie(input('name'), input('id'));
    }
     
}