<?php
class pagesModel extends Model{
        public function store_page($pagesize=25,$map,$order){
			$data = M('store'); // 实例化User对象
			import('ORG.Util.Page');// 导入分页类
			$map .= " and is_delete= '0' ";
			$count      = $data->where($map)->count();// 查询满足要求的总记录数
			$Page       = new Page($count,$pagesize);// 实例化分页类 传入总记录数和每页显示的记录数
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			// $list = $data->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
			$list = $data->query("select a.*,b.username from ". C('DB_PREFIX') ."store as a left join ". C('DB_PREFIX') ."users as b on a.uid=b.id where ". $map ." ". $order ." limit ". $Page->firstRow . "," . $Page->listRows);
			$return['list'] = $list;
			$return['page'] = $show;
			return $return;
		}
		/*pagesize = 每页显示数量
		map = 查询条件
		order = 排序方式
		url = 增加的url参数
		*/
        public function content_page($pagesize=25,$map,$order,$model='',$url=''){
			$data = M('content_content'); // 实例化User对象
			import('ORG.Util.Page');// 导入分页类
			// $map .= " and is_delete= '0' ";
			$q = str_replace('a.','',$map);
			$count      = $data->where($q)->count();// 查询满足要求的总记录数
			$Page       = new Page($count,$pagesize,'',$model,$url);// 实例化分页类 传入总记录数和每页显示的记录数
			$Page->setConfig('first','1...');
			$Page->setConfig('prev','上一页');
			$Page->setConfig('next','下一页');
			$Page->setConfig('last','尾页');
			$Page->setConfig('theme','%upPage% %first% %linkPage% %downPage% %end%');
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			// $list = $data->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
			$list = $data->query("select a.*,b.value,c.authpic,c.integral from ". C('DB_PREFIX') ."content_content as a left join ". C('DB_PREFIX') ."content_yesno as b on a.id=b.cid left join ". C('DB_PREFIX') ."users as c on a.authorid=c.id where ". $map ." ". $order ." limit ". $Page->firstRow . "," . $Page->listRows);
			foreach($list as $k=>$v){
				$list_data[$k] = $v;
				$list_data[$k]['yi'] = unserialize($v['value']);
			}
			$return['list'] = $list_data;
			$return['page'] = $show;
			return $return;
		}
		public function tags_page($pagesize=25,$map,$order,$model='',$url=''){
			$data = M('tag'); // 实例化User对象
			import('ORG.Util.Page');// 导入分页类
			// $map .= " and is_delete= '0' ";
			$count      = $data->where($map)->count();// 查询满足要求的总记录数
			$Page       = new Page($count,$pagesize,'',$model,$url);// 实例化分页类 传入总记录数和每页显示的记录数
			$Page->setConfig('first','1...');
			$Page->setConfig('prev','上一页');
			$Page->setConfig('next','下一页');
			$Page->setConfig('last','尾页');
			$Page->setConfig('theme','%upPage% %first% %linkPage% %downPage% %end%');
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			// $list = $data->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
			$list = $data->query("select * from ". C('DB_PREFIX') ."tag where ". $map ." ". $order ." limit ". $Page->firstRow . "," . $Page->listRows);
			$return['list'] = $list;
			$return['page'] = $show;
			return $return;
		}
		public function taginfo_page($pagesize=25,$map,$order,$model='',$url=''){
			$data = M('content_tag'); // 实例化User对象
			import('ORG.Util.Page');// 导入分页类
			// $map .= " and is_delete= '0' ";
			$q = str_replace('a.',''. C('DB_PREFIX') .'content_tag.',$map);
			$q = str_replace('b.',''. C('DB_PREFIX') .'content_content.',$q);
			$count      = $data->where($q)->join("". C('DB_PREFIX') ."content_content on ". C('DB_PREFIX') ."content_tag.cid = ". C('DB_PREFIX') ."content_content.id")->count();// 查询满足要求的总记录数
			// echo $data->getLastSql();
			$Page       = new Page($count,$pagesize,'',$model,$url);// 实例化分页类 传入总记录数和每页显示的记录数
			$Page->setConfig('first','1...');
			$Page->setConfig('prev','上一页');
			$Page->setConfig('next','下一页');
			$Page->setConfig('last','尾页');
			$Page->setConfig('theme','%upPage% %first% %linkPage% %downPage% %end%');
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			// $list = $data->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
			$list = $data->query("select b.*,c.value,d.authpic,d.integral from ". C('DB_PREFIX') ."content_tag as a left join ". C('DB_PREFIX') ."content_content as b on a.cid=b.id left join ". C('DB_PREFIX') ."content_yesno as c on b.id=c.cid left join ". C('DB_PREFIX') ."users as d on b.authorid=d.id where ". $map ." ". $order ." limit ". $Page->firstRow . "," . $Page->listRows);
			foreach($list as $k=>$v){
				$list_data[$k] = $v;
				$list_data[$k]['yi'] = unserialize($v['value']);
			}
			$return['list'] = $list_data;
			$return['page'] = $show;
			$return['count'] = $count;
			return $return;
		}
	}