<?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\Article as LogicArticle;

use app\common\logic\Page as LogicPage;

use app\common\controller\Base as BaseController;

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

	/**
	 * 定义逻辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	private static $ArticleLogic = null;
	private static $PageLogic = 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::$ArticleLogic = get_sington_object('LogicArticle', LogicArticle::class);
        self::$PageLogic = get_sington_object('LogicPage', LogicPage::class);
    }
    
	/**
	 * 文章列表
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function index()
	{
		return view();
	}

	/**
	 * 文章添加
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function add()
	{
        $menuinfo = Db::name('menu')->where('type',0)->find();
        $columninfo = Db::name('column')->where('pid',$menuinfo['id'])->find();
		$data = Db::name('assortment')->where('pid',$columninfo['id'])->select();
		$this->request->isPost() && $this->jump(self::$ArticleLogic->formdata(input('post.')));
		return view('',compact('data'));
	}

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

	/**
	 * 文章编辑
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function edit()
	{
        $menuinfo = Db::name('menu')->where('type',0)->find();
        $columninfo = Db::name('column')->where('pid',$menuinfo['id'])->find();
		$res = Db::name('assortment')->where('pid',$columninfo['id'])->select();
		$data = self::$ArticleLogic->getArticleInfo(['id'=>input('id')]);
		$this->request->isPost() && $this->jump(self::$ArticleLogic->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::$ArticleLogic->getArticleDel($id);
        return json($data);
    }

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

	/**
	 * 单页列表
	 * @Author: 闻子 < QQ：270988107 >
	 */
	public function page()
	{
		return view();
	}

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

	public function page_edit()
	{
		$data = self::$PageLogic->getPageInfo(['id'=>input('id')]);
		$this->request->isPost() && $this->jump(self::$PageLogic->formdata(input('post.')));
		return view('',compact('data'));
	}

}