<?php

namespace admin\controller;
/**
 * 
 */
class Folder extends Admin {
	
	
	public function lists(){
		$spk = array (
		    'pk1' => array('type' => 'INF_MAX'),
		    'pk2' => '',
		    'pk3' => '',
		    'pk4' => '',
		);
		$epk = array (
		    'pk1' => array('type' => 'INF_MIN'),
		    'pk2' => '',
		    'pk3' => '',
		    'pk4' => '',
		);
		
		//搜索
		if(I('uid')){
			$spk['pk1']=I('uid');
			$epk['pk1']=I('uid');
			$spk['pk2']=array('type' => 'INF_MAX');
			$epk['pk2']=array('type' => 'INF_MIN');
			if(I('pk4')){
				$list[0]=O('folder')->find(array('pk'=>array(
					'pk1'=>I('uid'),
					'pk2'=>'',
					'pk3'=>'',
					'pk4'=>I('pk4'),
				)));
			}else{
				$list=O('folder')->select(array(
					'spk'=>$spk,
					'epk'=>$epk,
				));
			}
		}else if(I('pk4')){
			$this->error('请输入用户ID');
		}else{
			$filter=array(
				'pk4'=>array('gt',mktime(0,0,0,date('m'),date('d')-1,date('Y'))*1000),
				'status'=>array('eq',0),
			);
			$list=O('folder')->select(array(
				'spk'=>$spk,
				'epk'=>$epk,
				'filter'=>$filter,
			));
		}
		
//		$filter=array(
//			'pk4'=>array('gt',mktime(0,0,0,date('m'),date('d')-1,date('Y'))*1000),
//			'status'=>array('eq',0),
//		);
//		if(I('uid')){
//			unset($filter['pk4']);
//		    $filter['pk1']=array('eq',I('uid'));
//		}
//		if(I('pk4')){
//		    $filter['pk4']=array('eq',I('pk4'));
//		}
//		$list=O('folder')->select(array(
//			'spk'=>$spk,
//			'epk'=>$epk,
//			'filter'=>$filter,
//		));
		foreach ($list as $k => &$v) {
			$v['ctime']=date('Y-m-d H:i:s',$v['pk4']/1000);
		}
		$this->list=$list;
		$this->display();
	}
	
	/**
	 * 删除
	 */
	public function del($pk=''){
		$id=I('id',false);
		if($id){
		    foreach ($id as $k => $v) {
		    	$pk=explode(',', $v);
				$pk=array(
					'pk1'=>$pk[0],
					'pk2'=>$pk[1],
					'pk3'=>$pk[2],
					'pk4'=>$pk[3],
				);
				O('folder')->delete(array('pk'=>$pk));
		    }
		}else{
			$pk=json_decode(base64_decode($pk),true);
			O('folder')->delete(array('pk'=>$pk));
		}
		$this->ajaxReturn(array(
			'status'=>1
		));
		
	}
	
	public function recycle(){
		$spk = array (
		    'pk1' => array('type' => 'INF_MAX'),
		    'pk2' => '',
		    'pk3' => '',
		    'pk4' => '',
		);
		$epk = array (
		    'pk1' => array('type' => 'INF_MIN'),
		    'pk2' => '',
		    'pk3' => '',
		    'pk4' => '',
		);
		
		$list=O('folder')->select(array(
			'spk'=>$spk,
			'epk'=>$epk,
			'filter'=>array(
				'pk4'=>array('gt',mktime(0,0,0,date('m'),date('d')-1,date('Y'))*1000),
				'status'=>array('eq',-1)
			),
		));
		foreach ($list as $k => &$v) {
			$v['uid']=substr($v['pk1'], 5);
			$v['ctime']=date('Y-m-d H:i:s',$v['pk4']/1000);
		}
		$this->list=$list;
		$this->display();
	}
}
