<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use Think\Config;
/*
商品页面
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://myucms.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Content extends Common
{
    //分类首页
    public function cate()
    {
		return md5Qm();

    }
    //分类编辑添加
    public function cate_add()
    {
		$c=Db::name('cate')->find(get('id',0));
        $this->assign('c',$c);
        return md5Qm();
    }
    //商品首页
    public function index()
    {
        $id = input('id');
        $this->assign('id', $id);
        //输出模型
        $model = 'article';
        $this->assign('model', $model);
        $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
        $perpage = isset($_REQUEST['perpage']) ? $_REQUEST['perpage'] : 10;
        $keyword = isset($_REQUEST['keyword']) ? trim($_REQUEST['keyword']) : '';
        $tid = isset($_REQUEST['tid']) ? trim($_REQUEST['tid']) : 0;
        $open = isset($_REQUEST['open']) ? trim($_REQUEST['open']) : '';
        $settop = isset($_REQUEST['settop']) ? trim($_REQUEST['settop']) : '';
        $map = [];
        if ($open != '') {
            $map['f.open'] = $open;
        }
        if ($settop != '') {
            $map['f.settop'] = $settop;
        }
        if ($keyword) {
            $map['f.title'] = ['like', "%{$keyword}%"];
        }
        if ($tid == 0) {
            $html = Db::name($model)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->order('f.times desc,f.id desc')->where($map)->paginate($perpage, false, $config = ['query' => array('settop' => $settop, 'open' => $open, 'tid' => $tid, 'keyword' => $keyword, 'perpage' => $perpage)]);
        } else {
            $html = Db::name($model)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->where("f.tid=$tid or c.tid=$tid")->order('f.times desc,f.id desc')->where($map)->paginate($perpage, false, $config = ['query' => array('settop' => $settop, 'open' => $open, 'tid' => $tid, 'keyword' => $keyword, 'perpage' => $perpage)]);
        }
        $this->assign(array('settop' => $settop, 'open' => $open, 'tid' => $tid, 'keyword' => $keyword, 'perpage' => $perpage));
        return $this->fetch('index', ['html' => $html]);
        //return md5Qm();
    }
    //文章添加编辑
    public function add()
    {
		$c=Db::name('article')->find(get('id',0));
        $this->assign('c',$c);
        return md5Qm();
    }
	//订单管理
	public function dingdan_index()
    {
        $ks = input('ks');
		if (empty(input('id'))) {
            $html = Db::name('shop_dingdan')->order('id desc')->where(array('gouwu' => 0))->where('title|oid|dizhi', 'like', '%' . $ks . '%')->paginate(15, false, $config = ['query' => array('ks' => $ks)]);
		} else if (input('id')==9) {
			//购物车
			$html = Db::name('shop_dingdan')->order('id desc')->where(array('gouwu' => 1))->where('title|oid|dizhi', 'like', '%' . $ks . '%')->paginate(15, false, $config = ['query' => array('ks' => $ks)]);
		} else {
            $html = Db::name('shop_dingdan')->order('id desc')->where(array('open' => input('id'),'gouwu' => 0))->where('title|oid', 'like', '%' . $ks . '%')->paginate(15, false, $config = ['query' => array('ks' => $ks)]);
		}
		$this->assign('html', $html);
        return md5Qm();
    }

    //留言管理
    public function comment()
    {
        return md5Qm();
    }
    //留言查看
    public function comment_add()
    {
		$c=Db::name('comment')->find(input('id'));
        $this->assign('c',$c);
        return md5Qm();
    }
}