<?php
 /**
 * SuKeCMS 搜索功能
 * ============================================================================
 * 版权所有 2014 速科网络，并保留所有权利。
 * 网站地址: http://www.sukewl.com；
 * ----------------------------------------------------------------------------
 * 未获商业授权之前，不得将SuKeCMS用于商业用途（包括但不限于企业网站、经营性网站
 * 以营利为目的或实现盈利的网站）未经官方许可，禁止在SuKeCMS的整体或任何部分基础
 * 上以发展任何派生版本、修改版本或第三方版本用于重新分发。如果您未能遵守本协议的
 * 条款，您的授权将被终止，所被许可的权利将被收回，并承担相应法律责任。
 * ============================================================================
 * Author: Shiang.Chin
 * Date:2014/12/31
**/
class IndexPlugin extends CommonModule{
	public function index(){
		$cate_id = Q('get.id');
		$type    = Q('get.type');

		
		
		$type  = empty($type) ? 'article' : $type;
		
		if($type=='product'){
			$tpl = 'product_search';

			$cz      = Q('get.cz');
			$gg      = Q('get.gg');
			$gy      = Q('get.gy');
			$bm      = Q('get.bm');
			$rz      = Q('get.rz');

			$where = "a.status=1 AND a.model='".$type."'";

			if(!empty($cate_id)){
				$where .= " AND a.pid ='".$cate_id."'";
			}

			if(!empty($cz)){
				$where .= " AND b.size LIKE '%".$cz."%'";
			}
			if(!empty($gg)){
				$where .= " AND b.weight LIKE '%".$gg."%'";
			}
			if(!empty($gy)){
				$where .= " AND b.color  ='".$gy."'";
			}
			if(!empty($bm)){
				$where .= " AND b.brand ='".$bm."'";
			}

			if(!empty($rz)){
				$where .= " AND b.pmodel LIKE '%".$rz."%'";
			}
			$count = M()->join('__artlibrary__ a LEFT JOIN __artproduct__ b ON a.id=b.pid')->field('a.id')->where($where)->count();
			$page  = new Page($count,20);
			
			$list = M()
					->join('__artlibrary__ a LEFT JOIN __artproduct__ b ON a.id=b.pid')
					->where($where)
					->limit($page->limit())
					->all();
			foreach($list as $k=>$vo){
				$list[$k]['user'] = self::userinfo($vo['uid']);
			}

		}elseif($type=='company'){
			$tpl = 'company_search';
			$kw      = Q('get.kw');
			if(!empty($kw)){
				$count = M('user_field_2')->field('id')->where("comname LIKE '% ". $kw ." %'")->count();
				$page  = new Page($count,20);
				$list = M('user_field_2')
						->where("comname LIKE '%". $kw ."%'")
						->limit($page->limit())
						->all();
		
			}

		}else{
			$tpl = 'art_search';
		}

		

		$authen = M('user_field_2')->where('authen=1')->limit(10)->all();
		$huoyue = M('user_field_2')->limit(20)->order('uid desc')->all();

		$this->assign('authen',$authen);
		$this->assign('list',$list);
		$this->assign('page',$page->show());
		$this->assign('attrlist',$attrlist);
		$this->display($tpl);
	}


}