<?php
namespace uhome\controller;

/**
 * 控制器
 * 
 */
class Products extends Uhome {
	

	public function index(){
		$uid=I('uid',0);
		$userconfig=userconfig_get($uid);
		$service_qq=$userconfig['service_qq'];
		$service_qq=preg_split("/[\r\n]+/s", $service_qq,-1,PREG_SPLIT_NO_EMPTY);
		$service_qq=$service_qq[0];
		$this->service_qq=preg_split("/[\|]+/s", $service_qq,-1,PREG_SPLIT_NO_EMPTY);
		$this->tpl=$userconfig['shoumaidanye_tpl'];
		$this->uid=$uid;
		$this->display("Products_index/{$userconfig['shoumaidanye_tpl']}/index");
    }
	
	/**
	 * 文件夹
	 */
	public function folder($uid){
		$list=O('folder')->select(array('filter'=>array('pk1'=>array('eq',$uid),'shoumaifenlei'=>array('eq',1),'status'=>array('eq','0'))));
		$this->ajaxReturn($list);
	}
	
	/**
	 * 文件
	 */
	public function files($uid,$folder){
		$list=O('file')->select(array('filter'=>array('pk1'=>array('eq',$uid),'price'=>array('gt',0),'folder'=>array('eq',$folder))));
		$this->ajaxReturn($list);
	}
	
	
	/**
	 * 价格
	 */
	public function getPrice(){
		$mobile=I('mobile','');
		$pk=I('pk',false);
		if($pk){
		    $pk=json_decode(base64_decode($pk),true);
		}else{
			$pk=array(
				'pk1'=>I('pk1',''),
				'pk2'=>I('pk2',''),
				'pk3'=>I('pk3',''),
				'pk4'=>I('pk4',''),
			);
		}
		$info_file=O('file')->find(array(
			'pk'=>$pk
		));
		$info_file['youhui']=preg_split("/[\r\n]+/s",$info_file['youhui'] ,-1,PREG_SPLIT_NO_EMPTY);
		foreach ($info_file['youhui'] as $k => &$v) {
			$v=preg_split("/[=]+/s", $v,-1,PREG_SPLIT_NO_EMPTY);
			if(I('num')>=$v[0]){
			    $info_file['price']=$v[1];
			}
		}
		$amount = $info_file['price']*I('num',1);
		unset($v);
		if($mobile){
		    $amount+=0.1;
		}
		$this->ajaxReturn(array('amount'=>$amount,'status'=>1,'info_file'=>$info_file));
	}
}


