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

namespace app\common\logic;

use think\Db;

class Menu extends Basedata
{
    /**
     * 定义模型
     * @Author 闻子 <270988107@qq.com>
     */
    public static $MenuModel = null;

    /**
     * 实例化模型
     * @Author 闻子 <270988107@qq.com>
     */
    public function __construct()
    {
        parent::__construct();
        self::$MenuModel = model($this->name);
    }

    /**
     * 获取菜单数据逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getMenuInfo($where = [], $field = true)
    {
        return self::$MenuModel->getInfo($where, $field);
    }

    /**
     * 获取菜单第一个数据逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getMenuOrderInfo($where = [], $field = true, $order = '')
    {
        return self::$MenuModel->getOrderInfo($where, $field, $order);
    }

    /**
     * 获取菜单列表逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getMenuList($where = [], $data = '')
    {
        return self::$MenuModel->getWhereOrder($where, $data);
    }

    /**
     * 菜单统计数据逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getMenuCount($where = [])
    {
        return self::$MenuModel->stat($where);
    }

    /**
     * 菜单数据提交逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function formdata($data)
    {
    	$data['create_time'] = date('Y-m-d H:i:s');
        $url = url('/ohbbs/'.$this->name.'/index');
        return self::$MenuModel->setInfo($data) ? [RESULT_SUCCESS, '提交成功', $url] : [RESULT_ERROR, self::$MenuModel->getError()];
    }

    /**
     * 菜单编辑逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getedit($data)
    {
        $url = url('/ohbbs/'.$this->name.'/index');
        return self::$MenuModel->setInfo($data) ? ['code' => 1, 'msg' => '提交成功', 'data' => '', 'url' => $url] : ['code' => 0, 'msg' => '提交失败', 'data' => '', 'url' => $url];
    }

    /**
     * 菜单删除逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getMenuDel($id)
    {
        if (empty($id)) {
            return ["ERROR", '参数异常'];
        }
        $data['id'] = $id;
        $url = url('/ohbbs/'.$this->name.'/index');
        return self::$MenuModel->deleteyi($data) ? ['code' => 1, 'msg' => '删除成功', 'data' => '', 'url' => $url] : ['code' => 0, 'msg' => '删除失败', 'data' => '', 'url' => $url];
    }

    /**
     * 批量删除菜单逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getMenualldel($data)
    {
        $str = rtrim($data, ","); 
        $row = self::$MenuModel->deleteyi($str);
        $url = url('/ohbbs/'.$this->name.'/index');
        return $row ? ['code' => 1, 'msg' => '删除成功', 'data' => '', 'url' => $url] : ['code' => 1, 'msg' => '删除失败', 'data' => '', 'url' => $url];
    }

}