<?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\Assortment as LogicAssortment;

use app\common\controller\Base as BaseController;

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

	/**
	 * 定义逻辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	private static $AssortmentLogic = 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::$AssortmentLogic = get_sington_object('LogicAssortment', LogicAssortment::class);
    }
    
	/**
	 * 分类列表
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function index()
	{
		return view();
	}

	/**
	 * 分类添加
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function add()
	{
		$data = Db::name('column')->select();
		$this->request->isPost() && $this->jump(self::$AssortmentLogic->formdata(input('post.')));
		return view('',compact('data'));
	}

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

	/**
	 * 分类编辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function edit()
	{
		$res = Db::name('column')->select();
		$data = self::$AssortmentLogic->getAssortmentInfo(['id'=>input('id')]);
		$this->request->isPost() && $this->jump(self::$AssortmentLogic->formdata(input('post.')));
		return view('',compact('data','res'));
	}

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

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

}