<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use Think\Config;
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021 http://mifenlei.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Shangjia extends Common
{
    //商家首页
    public function index()
    {
        $id = input('id');
        $this->assign('id', $id);
        //输出模型
        $model = 'shangjia';
        $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_shangjia 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_shangjia 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]);
    }
    // 商家分类管理
    public function cate()
    {
		return md5Qm();
    }
    // 商家分类添加编辑
    public function cate_add()
    {
        $c=Db::name('cate_shangjia')->where(array('id' => get('id',0)))->find();
        $this->assign('c',$c);
		return md5Qm();
    }
    // 添加编辑商家内容
    public function add()
    {
        $c=Db::name('shangjia')->find(get('id',0));
        $this->assign('c',$c);
		return md5Qm();
    }
}