<?php if( !defined( 'ONGPHP')) exit( 'Error ONGSOFT');
	$D = db('');
	$action = isset($_POST['action']) ? $_POST['action'] :'';



	// 获取get参数
$getac = isset($_GET['upload']) ? $_GET['upload'] :'';

/***************************************************************
	处理上传
****************************************************************/
if($getac=='yes'){

	   if( isset($_GET['uplx']) ){	
		
               $_GET['uplx'] = isset($_GET['uplx'])?$_GET['uplx']:'image';

                     // 上传图片	

         		$DATAS = update($USER['id']);
         		
         //dump($DATAS);exit;
		 if(  $DATAS['code'] == 1 ) {

		 	exit( json_encode( array('error' => 0 , 'url' =>  $DATAS['content']['pic'] )  ));
		 	
		 }else{

		 	exit( json_encode( array('error' => 1 , 'message' =>  $DATAS['msg']) ));

		 } 

	    }
}

$shezhi = $Mem1 -> g('shezhi');


if ($action=='ajaxzuobi') {			
			$status=isset($_POST['number']) ? $_POST['number'] :0;	
			
			$D ->setbiao('shezhi')-> where('id=7') -> update(array('data'=>$status));
			$info=$D ->setbiao('shezhi')-> where('id=7') ->find();
			if($info['data']==1){ 
				$info['code'] =1;				
				$info['msg'] = "设置成功";				
			}else{ 
				$info['code'] =0;				
				$info['msg'] = "设置成功";
			}
			exit(json_encode($info));
}elseif ($action=='ajaxzuobic') {			
			$info=$D ->setbiao('shezhi')-> where('id=7') ->find();
			if($info['data']==1){ 
				$info['code'] =1;				
				$info['msg'] = "设置成功";				
			}else{ 
				$info['code'] =0;				
				$info['msg'] = "设置成功";
			}
			exit(json_encode($info));

}elseif ($action=='shezhi') {

	

		/*设置抓娃娃*/


	$data = isset($_POST['data']) ? $_POST['data'] :'';

	if ($data['youxiyuming']!='') {

		$tiaojian = array(
				'data' => $data['youxiyuming']
				);
		$fan = $D ->setbiao('shezhi')->where( array("id"=>4))-> update( $tiaojian );

	}


	if ($data['appid']!='') {

		$tiaojian = array(
				'data' => $data['appid']
				);
		$fan = $D ->setbiao('shezhi')->where( array("id"=>5))-> update( $tiaojian );

	}

	if ($data['appsecret']!='') {

		$tiaojian = array(
				'data' => $data['appsecret']
				);
		$fan = $D ->setbiao('shezhi')->where( array("id"=>6))-> update( $tiaojian );

	}

	if (is_array($data)) {

		$cun = $Mem1 -> s('shezhi',$data);

		if ($cun) {
			$arr['o'] ='yes';
		}else{
			$arr['o'] = 'no';
		}

	}

	echo json_encode($arr);




	
}elseif ($action=='genggaijine') {	/*更改价格*/

	$D = db('');

	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';
	$jine = isset($_POST['jine']) ? $_POST['jine'] :'';
	$jine = sprintf("%0.2f",$jine);

	
	/*加钱*/
	$jiaqian = jiaqian( $zhi , $TYPE = 5 , $JINE = $jine,$JIFEN = 0 , $HUOBI = 0  , $DATA = '管理员更改金额' , $ip = '');

	if ($jiaqian) {
		$arr['o'] ='yes';
	}else{
		$arr['o'] ='no';
	}

	echo json_encode($arr);

}elseif ($action=='jiayongjin') {
	
	$D = db('');

	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';
	$jine = isset($_POST['jine']) ? $_POST['jine'] :'';
	$jine = sprintf("%0.2f",$jine);

	$TYPE = 2;

	/*加钱*/
	$jiaqian = jiaqian( $zhi , $TYPE , $JINE = 0,$JIFEN = 0 , $HUOBI = $jine  , $DATA = '管理员更改佣金' , $ip = '');

	


	if ($jiaqian) {
		$arr['o'] ='yes';
	}else{
		$arr['o'] ='no';
	}

	echo json_encode($arr);
}elseif ($action=='duihuanshenhe') {/*审核*/
	
   
    
   
    
	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';
	$uu = isset($_POST['uu']) ? $_POST['uu'] :'';
		/*领钱到账*/
	
	
	$key = $shezhi['lingkey'];
	
	$linguid = $shezhi['linguid'];

	
	
	if ($shezhi['linguid']!='') {
	    
		$mid = $shezhi['linguid'];
	}else{
	    
		exit('没有设置零钱uid');
	}
	
	
	$tiaojian = array( 
				'id' => $zhi
			) ;
	$order = '  ';
	$jiang = $D -> setbiao('tixian') -> where( $tiaojian ) ->order(  ) -> find();
	
	
	
	$jine = $jiang['jine'];
	
	
	
	$uid = $jiang['uid'];
	$huiyuan = $D ->setbiao('user')-> where( array( "uid" => $uid ) ) -> find();

	
	if($uu == 2){//拒绝
	
	    if($jiang['type']==1){
	        
	        $jianjian = jiaqian( $uid , $TYPE = 6 , $JINE = $jine  , $JIFEN = 0 , $HUOBI = 0  , $DATA = '特殊原因拒绝提现' , $ip = ip());
	        
	    }else{
	        $jianjian = jiaqian( $uid , $TYPE = 3 , $JINE = 0  , $JIFEN = 0 , $HUOBI = $jine  , $DATA = '特殊原因拒绝提现' , $ip = ip());
	    }
	    
	
	    if($jianjian){
	        
	        $fan = $D ->setbiao('tixian')->where( array("id"=>$jiang['id']))-> update(array(
	        
	            'off' => 2,
	            'data' => "拒绝成功",
	            'atime'=>time(),
	        
	        ));
	        
	        
	        
	        if ($fan) {
	            $arr['o']  = 'yes';
	        }
	        
	    }
	    
	    exit(json_encode($arr));
	
	}
	
	
	
	if ($shezhi['tixianfee']>0) {
	     
	     
	    $left = (int)100-(int)$shezhi['tixianfee'];
	    $jine = ( (float)$left/100 ) * (float)$jine;
	    $jine = sprintf("%0.2f",$jine);
	     
	    //dump($jine);exit;
	     
	}
	
	if (!$huiyuan) {
		exit('没有此会员');
	}
	
	
	
	$openid = $huiyuan['txopenid'];
	if ($openid=='') {
	    
		exit('此人没有openid');
		
	}

	
	
	
	
	if ($shezhi['lingurl']!='') {
	    
	    
		$lailu = WZHOST.'ajax.php';

		$post_data = array (
		    'mid' => $mid, //在掌上零钱里面获取的uid
		    'jine' => $jine, //要请求发放的金额
		    'openid'=>$openid, //第二步获取的openid
		    'tixianid'=>$jiang['id'], //本地的提现id【要求唯一】字符串类型的数字，最大长度11位数
		    'lailu' =>$lailu, //可选参数
		);
		$mkey = md5($post_data['mid'].$post_data['jine'].$post_data['openid'].$key);
		
		$post_data['mkey'] = $mkey;
		$post_data['lx'] = 4;//4是时间夺宝 5是是采水果8尾号竞猜
		
		$url = $shezhi['lingurl'].'jieru.php';
		$da = post($post_data,$url);

		//dump($da);exit;
		if ($da=='此帐号已经提现') {

			exit(json_encode(array('o' => '此订单已经提现')));

		}
		
		$daa = json_decode($da,true);

		//dump($daa );exit;
		if($daa['o']=='-1'){
		    exit(json_encode(array('o' => '商户没钱')));//-2报错
		}
		if($daa['o']=='-2'){
		    exit(json_encode(array('o' => $daa['msg'])));//-2报错
		}
		if ($daa['o']=='yes') {

			$fan = $D ->setbiao('tixian')->where( array("id"=>$jiang['id']))-> update(array(

				'off' => 1,
				'data' => $daa['orderid']

				));
			if ($fan) {
				$arr['o']  = 'yes';
			}
		}
		
//exit($daa['msg']);

	}else{
		
		exit('没有设置领钱到账网址');

	}

	echo json_encode($arr);

}elseif ($action=='dailishenhe') {/*审核*/
	
   
    
   
    
	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';
		/*领钱到账*/
	
	
	
	$tiaojian = array( 
				'id' => $zhi
			) ;
	$order = '  ';
	$jiang = $D -> setbiao('dailitixian') -> where( $tiaojian ) ->order(  ) -> find();
	$jine = $jiang['jine'];
	$uid = $jiang['adminid'];
	$huiyuan = $D ->setbiao('admin')-> where( array( "id" => $uid ) ) -> find();

	if (!$huiyuan) {
		exit('没有此代理商');
	}
	
	
	
	$zhanghao = $jiang['zhanghao'];
	if ($zhanghao=='') {
		exit('未填写支付宝账号');
	}

	$fan = $D ->setbiao('dailitixian')->where( array("id"=>$jiang['id']))-> update(array(
	
	    'off' => 1,
	    
	
	));
	if ($fan) {
	    $arr['o']  = 'yes';
	}
	

		
	echo json_encode($arr);

}


?>