<?php
/**
 * @Statement: [ An Ordinary Person ]
 * @Author: 闻子 < QQ：270988107 >
 * @Copyright: 闻子 2016-2019 All rights reserved.
 *
 *    .--,       .--,
 *   ( (  \.---./  ) )
 *    '.__/o   o\__.'
 *       {=  ^  =}
 *        >  -  <
 *       /       \
 *      //       \
 *     //|   .   |\
 *     "'\       /'"_.-~^`'-.
 *        \  _  /--'         `
 *      ___)( )(___
 *     (((__) (__)))    高山仰止,景行行止.虽不能至,心向往之.
 *
 */
 
namespace app\index\controller;

use think\Db;

use app\common\logic\Menu as LogicMenu;

use app\common\controller\Base as BaseController;

class Menu extends BaseController
{
	/**
	 * 继承基类
	 * @Author: 闻子 < QQ：270988107 >
	 */
    use Basedata;

	/**
	 * 菜单页面
	 * @Author: 闻子 < QQ：270988107 >
	 */
    public function index()
    {
    	if (empty(input('mid'))) {
    		$where['alias'] = input('name');
    	}else{
    		$where['id'] = input('mid');
    	}
    	$menuinfo = Db::name('menu')->where($where)->find();
    	$data = Db::name('column')->where('pid',$menuinfo['id'])->order('sort asc')->select();
        $test = [];
        foreach ($data as $key => $value) {
            if (input($value['alianc'])) {
                $test[] = input($value['alianc']);
            }
        }
        if (count($test) != 1) {
            $while = implode(",",$test);
            $wheredata['catid'] = $while;
            if (input('popularity') == 1) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where($wheredata)->order(['browser','id'=>'desc'])->paginate(16);
            } elseif (input('popularity') == 2) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where($wheredata)->order(['comment','id'=>'desc'])->paginate(16);
            } elseif (input('popularity') == 3) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where($wheredata)->order(['essence','id'=>'desc'])->paginate(16);
            }else{
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where($wheredata)->order('id desc')->paginate(16);
            }
        } elseif (count($test) == 1) {
            if (input('popularity') == 1) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where("FIND_IN_SET($test[0],catid)")->order(['browser','id'=>'desc'])->paginate(16);
            } elseif (input('popularity') == 2) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where("FIND_IN_SET($test[0],catid)")->order(['comment','id'=>'desc'])->paginate(16);
            } elseif (input('popularity') == 3) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where("FIND_IN_SET($test[0],catid)")->order(['essence','id'=>'desc'])->paginate(16);
            }else{
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->where("FIND_IN_SET($test[0],catid)")->order('id desc')->paginate(16);
            }
        }
        if (count($test) == 0) {
            if (input('popularity') == 1) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->order(['browser','id'=>'desc'])->paginate(16);
            } elseif (input('popularity') == 2) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->order(['comment','id'=>'desc'])->paginate(16);
            } elseif (input('popularity') == 3) {
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->order(['essence','id'=>'desc'])->paginate(16);
            }else{
                $scodedata = Db::name('scode')->where('mid',$menuinfo['id'])->order('id desc')->paginate(16);
            }
        }
    	return view('',compact('data','scodedata','menuinfo'));
    }

    public function article()
    {
        if (empty(input('mid'))) {
            $where['alias'] = input('name');
        }else{
            $where['id'] = input('mid');
        }
        if (!empty(input('type'))) {
            if (input('type') == 0) {
                $info = Db::name('article')->order('id desc')->paginate(7);
            }else{
                $info = Db::name('article')->where('pid',input('type'))->order('id desc')->paginate(7);
            }
        }else{
            $info = Db::name('article')->order('id desc')->paginate(7);
        }
        $menuinfo = Db::name('menu')->where($where)->find();
        $columninfo = Db::name('column')->where('pid',$menuinfo['id'])->find();
        $data = Db::name('assortment')->where('pid',$columninfo['id'])->select();
        //halt($info);
        return view('',compact('data','info','menuinfo'));
    }
}