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

namespace app\ohbbs\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 Base;

	/**
	 * 定义逻辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	private static $MenuLogic = null;

    /**
     * 实例化逻辑
     * @Author: 闻子 < QQ：270988107 >
     */
    public function __construct()
    {
        parent::__construct();
        $userinfo = Db::name('user')->where('id',session('admin.id'))->find();
        if ($userinfo['manager'] != 1) {
        	$this->redirect('/member/index');
        }
        self::$MenuLogic = get_sington_object('LogicMenu', LogicMenu::class);
    }
    
	/**
	 * 菜单列表
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function index()
	{
		return view();
	}

	/**
	 * 菜单添加
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function add()
	{
		$this->request->isPost() && $this->jump(self::$MenuLogic->formdata(input('post.')));
		return view();
	}

	/**
	 * 菜单编辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function getedit()
	{
		$data = self::$MenuLogic->getedit(input('post.'));
		return $data;
	}

	/**
	 * 菜单编辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function edit()
	{
		$data = self::$MenuLogic->getMenuInfo(['id'=>input('id')]);
		$this->request->isPost() && $this->jump(self::$MenuLogic->formdata(input('post.')));
		return view('',compact('data'));
	}

	/**
	 * 菜单删除
	 * @Author: 闻子 < QQ：270988107 >
	 */
    public function del($id = 0)
    {
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '请求参数异常', 'data' => '']);
        }
        $data = self::$MenuLogic->getMenuDel($id);
        return json($data);
    }

	/**
	 * 菜单批量删除
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function alldel()
	{
		$data = self::$MenuLogic->getMenualldel(input('ids'));
		return $data;
	}

}