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

namespace app\api\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 >
	 */
	private static $MenuLogic = null;

    /**
     * 实例化逻辑
     * @Author: 闻子 < QQ：270988107 >
     */
    public function __construct()
    {
        parent::__construct();
        self::$MenuLogic = get_sington_object('LogicMenu', LogicMenu::class);
    }

    /**
     * 管理员检测
     * @Author: 闻子 < QQ：270988107 >
     */
    public function getManager()
    {
        $userinfo = Db::name('user')->where('id',session('admin.id'))->find();
        if ($userinfo['manager'] != 1) {
            $this->redirect('/member/index');
        } elseif (!$userinfo) {
            return $this->error('登录超时，请重新登录','index/member/login');
        }
    }

    /**
     * 菜单接口
     * @Author: 闻子 < QQ：270988107 >
     */
    public function getMenu()
    {
        $this->getManager();
        $count = self::$MenuLogic->getMenuCount();
        $page = $this->request->param('page',1,'intval');
        $limit = $this->request->param('limit',10,'intval');
        $all = Db::name('menu')->limit(($page-1)*$limit,$limit)->order('sort asc')->select();
        $data['code'] = 0;
        $data['msg'] = '';
        $data['count'] = $count;
        $data['data'] = $all;
        return json($data);
    }
}