<?php
namespace member\controller;
class Index extends Member {
    public function index(){
 /**
 * 106云盘自动发卡平台网盘系统
 * ============================================================================
 * 版权所有 2016-2028 扎兰屯市姝妍计算机服务有限公司，并保留所有权利。
 * 网站地址: http://www.106ym.com
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 */
		$uid=session("user_auth.id");
		if($uid){
		    $this->userconfig=O('userconfig')->find(array(
				'pk'=>array(
					'pk1'=>$uid,
					'pk2'=>'',
					'pk3'=>'',
					'pk4'=>'',
				),
			));
		}
		
		//余额
		$this->shouru_yue=M('money')->where(array('uid'=>$uid))->sum('price');
		
		//可提现金额
		$time=strtotime("-".C('MONEY_JIESUANZHOUQI')." day");
		$time=mktime(23,59,59,date('m',$time),date('d',$time),date('Y',$time));
		//结算周期后收入
		$bunengtixian=M('money')->where(array('uid'=>$uid,'price'=>array('gt',0),'ctime'=>array('egt',$time)))->sum('price');
		$this->shouru_ktx=$this->shouru_yue-$bunengtixian;
		
		if($this->shouru_yue<$this->shouru_ktx){
		    $this->shouru_ktx=0;
		}
		
		//冻结金额
		$this->dongjiejine=M('money')->where(array('uid'=>$uid,'type'=>8))->sum('price');
		
		//今日收入
		$time=mktime(0,0,0,date('m'),date('d'),date('Y'));
		$this->shouru_today=M('file_log')->where(array('ctime'=>array('gt',$time),'status'=>1,'uid'=>$uid))->sum('price');
		
		//最近一个月收入
		$time=time()-2592000;
		$this->shouru_month=M('file_log')->where(array('ctime'=>array('gt',$time),'status'=>1,'uid'=>$uid))->sum('price');
		
		//最近三个月收入
		$time=time()-2592000*3;
		$this->shouru_jidu=M('file_log')->where(array('ctime'=>array('gt',$time),'status'=>1,'uid'=>$uid))->sum('price');
		
		
    	//今日流量数据
    	$spk = array (
		    'pk1' => $uid,
		    'pk2' => (string)(mktime(0,0,0,date('m'),date('d'),date('Y'))*1000),
	        'pk3' => '',
	        'pk4' => '',
		);
		$epk = array (
		    'pk1' => $uid,
		    'pk2' => array('type' => 'INF_MAX'),
	        'pk3' => '',
	        'pk4' => '',
		);
		$list_downlog=O('downlog')->select(array(
			'spk'=>$spk,
			'epk'=>$epk,
			'filter'=>array('status'=>array('eq',0)),
			'order'=>'asc',
			'field'=>'pk2,size'
		));
		$list_hour_data=array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
		foreach ($list_downlog as $k => &$v) {
			$v['hour']=(int)date('H',floor($v['pk2']/1000));
		}
		$list_downlog=array_group($list_downlog, 'hour');
		foreach ($list_downlog as $k => $v) {
			foreach ($v as $k1 => $v1) {
				$list_hour_data[$k]+=$v1['size'];
			}
			$list_hour_data[$k]=floor($list_hour_data[$k]/1048576);
		}
		
		$this->list_hour_data=json_encode($list_hour_data);
    	
		//本小时下载量
		$this->nowhour=$list_hour_data[(int)date('H')];
		
		//公告
		$this->list_gonggao=M('gonggao')->order('id desc')->where(array('cate'=>1))->limit(0,10)->select();
		
    	$this->display();
    }
	
	public function del_more(){
		$uid=session("user_auth.id");
		$pk_arr=I('pk');
		foreach ($pk_arr as $k => $v) {
			$pk=explode(',', $v);
			$type=$pk[4];
			$pk=array(
				'pk1'=>$pk[0],
				'pk2'=>$pk[1],
				'pk3'=>$pk[2],
				'pk4'=>$pk[3],
			);
			if($type=='folder'){
			    $pk['pk1']=$uid;
				$pk4=$pk['pk4'];
				O('folder')->save(array(
					'pk'=>$pk,
					'attr'=>array('status'=>-1),
				));
				
				//删除子文件夹
		    	$spk = array (
				    'pk1' => $uid,
				    'pk2' => array('type' => 'INF_MAX'),
			        'pk3' => '',
			        'pk4' => '',
				);
				$epk = array (
				    'pk1' => $uid,
				    'pk2' => array('type' => 'INF_MIN'),
			        'pk3' => '',
			        'pk4' => '',
				);
				
				$list_folder=O('folder')->select(array(
					'spk'=>$spk,
					'epk'=>$epk,
					'filter'=>array(
						'status'=>array('eq',0),
					),
				));
				foreach ($list_folder as $k => $v) {
					$pids=explode(',', $v['pids']);
					if(in_array($pk4, $pids)){
					    $pk=array(
							'pk1'=>$v['pk1'],
							'pk2'=>$v['pk2'],
							'pk3'=>$v['pk3'],
							'pk4'=>$v['pk4'],
						);
						$attr=array(
							'status'=>-1
						);
						O('folder')->save(array(
							'pk'=>$pk,
							'attr'=>$attr,
						));
					}
				}
				
				//删除子文件
				$spk = array (
				    'pk1' => $uid,
				    'pk2' => '',
			        'pk3' => '',
			        'pk4' => array('type' => 'INF_MAX'),
				);
				$epk = array (
				    'pk1' => $uid,
				    'pk2' => '',
			        'pk3' => '',
			        'pk4' => array('type' => 'INF_MIN'),
				);
				
				$list_file=O('file')->select(array(
					'spk'=>$spk,
					'epk'=>$epk,
					'filter'=>array(
						'status'=>array('eq',0),
					),
				));
				foreach ($list_file as $k => $v) {
					$pids=explode(',', $v['folder_pids']);
					if(in_array($pk4, $pids)){
					    $pk=array(
							'pk1'=>$v['pk1'],
							'pk2'=>$v['pk2'],
							'pk3'=>$v['pk3'],
							'pk4'=>$v['pk4'],
						);
						$attr=array(
							'status'=>-1
						);
						O('file')->save(array(
							'pk'=>$pk,
							'attr'=>$attr,
						));
					}
				}
			}else if($type=='file'){
				$pk['pk1']=$uid;
				O('file')->save(array(
					'pk'=>$pk,
					'attr'=>array('status'=>-1),
				));
			}
		}
		$this->ajaxReturn(array('status'=>1));
    }
	
}