<?php
class IndexModel extends CmlModel {
	public function indexclass(){
		
		$cachegetc = $this->cache()->get('classall');
		if($cachegetc!=false){
			$classdata=$cachegetc;
		}else{
			$classdata=$this->db()->table('article_class')->orderBy('cid', 'DESC')->select();
			$this->cache()->set('classall',$classdata,0);
		}
		return $classdata;
	}
	
	public function indexarticle($classid,$sqlfirst,$pagesize,$status){
		if($classid>=0){
			
			if($status>=0){
				
				if($status==0){
					
					$cachegeta = $this->cache()->get('articleall-cid-'.$classid.'-status-'.$status);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
						$articledata=$this->db()->table('article')->where($column = array('gcmsclass'=>$classid,'status'=>0),true)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-cid-'.$classid.'-status-'.$status,$articledata,0);
					}
					
				}
				
				if($status==1){
					
					$cachegeta = $this->cache()->get('articleall-cid-'.$classid.'-status-'.$status);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
					  $articledata=$this->db()->table('article')->where($column = array('gcmsclass'=>$classid,'status'=>1),true)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-cid-'.$classid.'-status-'.$status,$articledata,0);
					}
					
				}
				
				if($status==2){
					
					$cachegeta = $this->cache()->get('articleall-cid-'.$classid.'-status-'.$status);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
					  $articledata=$this->db()->table('article')->where($column = array('gcmsclass'=>$classid,'status'=>2),true)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-cid-'.$classid.'-status-'.$status,$articledata,0);
					}

				}

			}else{
				
					if($sqlfirst==0){
						
					$cachegeta = $this->cache()->get('articleall-cid-'.$classid);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
						$articledata=$this->db()->table('article')->where('gcmsclass',$classid)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-cid-'.$classid,$articledata,0);
					}
					
					}else{
						$articledata=$this->db()->table('article')->where('gcmsclass',$classid)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
					}
					
			}
			
		}else{
			
			if($status>=0){
				
				if($status==0){
					
					if($sqlfirst==0){
						
					$cachegeta = $this->cache()->get('articleall-status-'.$status);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
					  $articledata=$this->db()->table('article')->where('status',0)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-status-'.$status,$articledata,0);
					}
					
					}else{
					  $articledata=$this->db()->table('article')->where('status',0)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
					}

				}
				if($status==1){
										
					if($sqlfirst==0){
						
					$cachegeta = $this->cache()->get('articleall-status-'.$status);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
					  $articledata=$this->db()->table('article')->where('status',1)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-status-'.$status,$articledata,0);
					}

					}else{
					  $articledata=$this->db()->table('article')->where('status',1)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
					}
					
				}
				if($status==2){
					
					if($sqlfirst==0){
						
					$cachegeta = $this->cache()->get('articleall-status-'.$status);
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
					  $articledata=$this->db()->table('article')->where('status',2)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall-status-'.$status,$articledata,0);
					}
					}else{
					  $articledata=$this->db()->table('article')->where('status',2)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
					}
					

				}

			}else{
				
					if($sqlfirst==0){
						
					$cachegeta = $this->cache()->get('articleall');
					if($cachegeta!=false){
						$articledata=$cachegeta;
					}else{
					  $articledata=$this->db()->table('article')->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
						$this->cache()->set('articleall',$articledata,0);
					}

					}else{
						
					  $articledata=$this->db()->table('article')->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();

						}
											
											
			}
			
		}
		return $articledata;
		
	}
	
	public function countarticle($classid){
		if($classid){
		$countdata=$this->db()->table('article')->where('gcmsclass',$classid)->count();
		}else{
		$countdata=$this->db()->table('article')->count();
			}
		return $countdata;
	}
		
	public function countarticle2($status){
		$countdata=$this->db()->table('article')->where('status',$status)->count();
		return $countdata;
	}
	
	public function countsearch($key,$s){
		if($s==1){
		$countdata=$this->db()->table('article')->whereLike('gcmstags',$leftDeper = true,$key,$rightDeper = true)->count();
		}elseif($s==2){
		$countdata=$this->db()->table('article')->whereLike('gcmstime',$leftDeper = true,$key,$rightDeper = true)->count();
		}else{
		$countdata=$this->db()->table('article')->whereLike('gcmstitle',$leftDeper = true,$key,$rightDeper = true)->count();
		}
		return $countdata;
	}
	
	public function article($id){
		$articledata=$this->db()->get('article-id-'.$id);
		return $articledata;
	}	
	public function searchtags($key,$sqlfirst,$pagesize,$s){
		if($s==1){
			$articledata=$this->db()->table('article')->whereLike('gcmstags',$leftDeper = true,$key,$rightDeper = true)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
		}elseif($s==2){
			$articledata=$this->db()->table('article')->whereLike('gcmstime',$leftDeper = true,$key,$rightDeper = true)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
		}else{
			$articledata=$this->db()->table('article')->whereLike('gcmstitle',$leftDeper = true,$key,$rightDeper = true)->columns($columns = array('id','gcmsclass','gcmsclassseo','gcmstitle','gcmstags','gcmsdesc','gcmspic','gcmsauthor','gcmstime','status'))->orderBy('id','DESC')->limit($sqlfirst,$pagesize)->select();
		}
		
		return $articledata;
	}
	
	public function indexnav(){
		
		$url1 = 'good';
		$cachegetn = $this->cache()->get('navall');
		if($cachegetn!=false){
			$navdata=$cachegetn;
		}else{
			$navdata=$this->db()->table('nav')->orderBy('cid', 'DESC')->select();
			$this->cache()->set('navall',$navdata,0);
		}
		$url2 = 'text';
		$fruit2 = array(array("id"=>"0", "cid"=>"0", "link"=>"http://$url1$url2.org/", "linkname"=>"GCMS", "linkclass"=>"2"));
		$navdata = array_merge_recursive($navdata, $fruit2);
		return $navdata;
	}
		
	public function pagelist(){
		$pagedata=$this->db()->table('pages')->orderBy('id', 'ASC')->select();
		return $pagedata;
	}
	
	public function indexpage($id){
		$pagedata=$this->db()->get('pages-id-'.$id);
		return $pagedata;
	}

	public function indextags($sqlfirst,$pagesize){
		
		$cachegetn = $this->cache()->get('tagsall');
		if($cachegetn!=false){
			$tagdata=$cachegetn;
		}else{
			$tagdata=$this->db()->table('tags')->orderBy('id', 'ASC')->limit($sqlfirst,$pagesize)->select();
			$this->cache()->set('tagsall',$tagdata,0);
		}
		return $tagdata;
	}
	
	//展示图集
	public function indexpv($sqlfirst,$pagesize){	
		$cachegetn = $this->cache()->get('picall');
		if($cachegetn!=false){
			$picdata=$cachegetn;
		}else{
		$picdata=$this->db()->table('pv')->where('class',0)->orderBy('id', 'ASC')->limit($sqlfirst,$pagesize)->select();
		$this->cache()->set('picall',$picdata,0);
		}
		return $picdata;
	}
	//首页焦点图
	public function indexslide(){	
		$cachegetn = $this->cache()->get('slide');
		if($cachegetn!=false){
			$slidedata=$cachegetn;
		}else{
		$slidedata=$this->db()->table('slide')->orderBy('id', 'ASC')->select();
		$this->cache()->set('slide',$slidedata,0);
		}
		return $slidedata;
	}
	
	//展示图片
	public function indexpvs($class){
		$picdata=$this->db()->table('pv')->where('class',$class)->orderBy('id', 'ASC')->select();
		return $picdata;
	}
	
}