<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

    public function index(){
        echo "对不起，请回吧！";
    }
	//最新商品
	public function GetShop(){
		$type = $_GET['type'];

		$User = M('shoplist'); // 实例化User对象
		// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
		if($type==1){
			$list = $User->where('shenyurenshu!=0')->order(array('order','qishu'=>'asc'))->page($_GET['p'].',10')->select();
		}
		if($type==2){
			$list = $User->where('shenyurenshu!=0')->order(array('order','shenyurenshu'=>'asc'))->page($_GET['p'].',10')->select();
		}
		if($type==3){
			$list = $User->where('shenyurenshu!=0')->order(array('order','qishu'=>'desc'))->page($_GET['p'].',10')->select();
		}
		if($type==4){
			$list = $User->where('shenyurenshu!=0')->order(array('order','money'=>'asc'))->page($_GET['p'].',10')->select();
		}
		if($type==5){
			$list = $User->where('shenyurenshu!=0')->order(array('order','money'=>'desc'))->page($_GET['p'].',10')->select();
		}
		$this->assign('list',$list);// 赋值数据集
		$count      = $User->where('shenyurenshu!=0')->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->ajaxReturn($list);
		
       // $User = M(); 
		//$data = $User->query("select * from `go_shoplist` where `pos` = '1' and `q_end_time` is null ORDER BY `id` DESC LIMIT 6");
		
		//$this->ajaxReturn($data);where(array('q_end_time'=>array('exp'=>' is null')))

    }
	//人气推荐
    public function GetNewShop(){

        $User = M(); 
		$data = $User->query("select * from `go_shoplist` where `renqi`='1' and `q_end_time` is null ORDER BY id DESC LIMIT 2");

		$this->ajaxReturn($data);
		
		

    }
	//搜索商品
	public function SearchShop(){
		$key_word=$_GET['data'];

		$User = M('shoplist'); // 实例化User对象
		if($key_word==1){
			$list = $User->where( "shenyurenshu<>0")->page($_GET['p'].',10')->select();
		}else{
			$list = $User->where( "title like '$key_word%' AND shenyurenshu<>0")->page($_GET['p'].',10')->select();
		}
		$this->assign('list',$list);// 赋值数据集
		$count      = $User->where('shenyurenshu!=0')->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->ajaxReturn($list);
	}

}