<?php if( !defined( 'ONGPHP')) exit( 'Error ONGSOFT');

$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']);
		 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=='getnum') {

	/*查询会员获取铲子*/
	$user = $D -> setbiao('user') -> where( 
		array( 
			"uid" => $_SESSION['uid'],
		) 
	) -> find();

	$tiechan = (float)$user['tiechan'];
	$tongchan = (float)$user['tongchan'];
	$yinchan = (float)$user['yinchan'];
	$jinchan = (float)$user['jinchan'];

	?>

	{"status":"ok","a0":<?php echo $tiechan ?>,"a1":<?php echo $tongchan ?>,"a2":<?php echo $yinchan ?>,"a3":<?php echo $jinchan ?>,"amount":1.65,"jj":<?php echo time() ?>}

	<?php

}elseif ($action=='num') {	/*查询是否可以*/

	$huo = isset($_GET['huo']) ? $_GET['huo'] :'';
	$n = isset($_POST['n']) ? $_POST['n'] :'';
	$jixu = isset($_POST['jixu']) ? $_POST['jixu'] :'';

	/*查询会员看看是否还有铁铲*/
	$user = $D -> setbiao('user') -> where( 
		array( 
			"uid" => $_SESSION['uid'], 
		) 
	) -> find();

	if ($jixu>0) {
		
		$status = 'ok';
		$keynum = 1;

	}else{

		if ($n==0) {

			$tiechan = $user['tiechan'];
			if ($tiechan>0) {

				$status = 'ok';
				$keynum = $user['tiechan'];

			}else{
				
				$status = 'no';
				$keynum = 0;
			}

		}elseif ( $n==1 ) {

			$tongchan = $user['tongchan'];
			if ($tongchan>0) {

				$status = 'ok';
				$keynum = $user['tongchan'];

			}else{

				$status = 'no';
				$keynum = 0;

			}

		}elseif ($n==2) {	/*银铲子*/
			
			$yinchan = $user['yinchan'];
			if ($yinchan>0) {

				$status = 'ok';
				$keynum = $user['yinchan'];

			}else{

				$status = 'no';
				$keynum = 0;

			}


		}elseif ($n==3) {	/*金铲子*/
			
			$jinchan = $user['jinchan'];
			if ($jinchan>0) {
				
				$status = 'ok';
				$keynum = $user['jinchan'];

			}else{

				$status = 'no';
				$keynum = 0;

			}


		}


	}




	?>

	{"status":"<?php echo $status ?>","keynum":<?php echo $keynum ?>,"amount":1.65}


	
	<?php
}elseif ($action=='mingxi') {	/*明细*/

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

	$log = logac('jinelog');
	
	if ($type=='cw') {

		if ($n==1) {	/*余额明细*/

			$order = '  ';
			$rs = $D -> setbiao('jinelog') -> order(  )->where( 
				array(
					'uid' => $_SESSION['uid'],
				)
			)-> select();

			if ($rs) {

				?>
				
				{
				"status":"ok","l":"<em> <\/em><ul><?php 
					foreach($rs as  $k => $v){
				?><li><div class=\"l\"><p class=\"time\"><?php echo date("Y-m-d",$v['atime'])?><\/p><p class=\"time\"><?php echo date("H:i:s",$v['atime'])?><\/p><\/div><div class=\"c\"><?php echo $log[$v['type']] ?><\/div><div class=\"r\"><font color=green><?php echo $v['jine'] ?><\/font><\/div><\/li><?php 
					}
				?><\/ul>"}
				<?php
			}else{
				?>
				{"status":"ok","l":"<em> <\/em><div class=\"loading nodata\">\u6ca1\u6709\u6570\u636e\u54c7<\/div>"} 
				<?php

			}

		}elseif ($n==2) {
			
			/*佣金明细*/

			$order = '  ';
			$rs = $D -> setbiao('jinelog') -> order(  )->where( 
				array(
					'uid' => $_SESSION['uid'],
					'type' => 8,
				)
			)-> select();

			if ($rs) {

				?>
				
				{
				"status":"ok","l":"<em> <\/em><ul><?php 
					foreach($rs as  $k => $v){
				?><li><div class=\"l\"><p class=\"time\"><?php echo date("Y-m-d",$v['atime'])?><\/p><p class=\"time\"><?php echo date("H:i:s",$v['atime'])?><\/p><\/div><div class=\"c\">获取佣金<\/div><div class=\"r\"><font color=green><?php echo $v['jine'] ?><\/font><\/div><\/li><?php 
					}
				?><\/ul>"}
				<?php
			}else{
				?>

				{"status":"ok","l":"<em> <\/em><div class=\"loading nodata\">\u6ca1\u6709\u6570\u636e\u54c7<\/div>"} 
				<?php

			}


		}elseif ($n==3) {
			
				/*铲子明细*/

			$order = '  ';
			$rs = $D -> setbiao('chanlog') -> order(  )->where( 
				array(
					'uid' => $_SESSION['uid'],
				)
			)-> select();

			if ($rs) {

				?>
				
				{
				"status":"ok","l":"<em> <\/em><ul><?php 
					foreach($rs as  $k => $v){
				?><li><div class=\"l\"><p class=\"time\"><?php echo date("Y-m-d",$v['atime'])?><\/p><p class=\"time\"><?php echo date("H:i:s",$v['atime'])?><\/p><\/div><div class=\"c\"><?php echo $v['data'] ?><\/div><div class=\"r\"><font color=green><?php if($v['type']==1 || $v['type']==3 || $v['type']==5 || $v['type']==7 ){  ?>+1<?php  }else{ ?>-1<?php } ?><\/font><\/div><\/li><?php 
					}
				?><\/ul>"}
				<?php
			}else{
				?>
				{"status":"ok","l":"<em> <\/em><div class=\"loading nodata\">\u6ca1\u6709\u6570\u636e\u54c7<\/div>"} 
				<?php

			}

		

		}elseif ($n==4) {
				
					/*挖包明细*/

			$order = '  ';
			$rs = $D -> setbiao('jinelog') -> order(  )->where( 
				array(
					'uid' => $_SESSION['uid'],
					'type IN' => '4,5,6,7',
				)
			)-> select();

			if ($rs) {

				?>
				
				{
				"status":"ok","l":"<em> <\/em><ul><?php 
					foreach($rs as  $k => $v){
				?><li><div class=\"l\"><p class=\"time\"><?php echo date("Y-m-d",$v['atime'])?><\/p><p class=\"time\"><?php echo date("H:i:s",$v['atime'])?><\/p><\/div><div class=\"c\"><?php echo $v['data'] ?><\/div><div class=\"r\"><font color=green><?php echo $v['jine'] ?><\/font><\/div><\/li><?php 
					}
				?><\/ul>"}
				<?php
			}else{
				?>
				{"status":"ok","l":"<em> <\/em><div class=\"loading nodata\">\u6ca1\u6709\u6570\u636e\u54c7<\/div>"} 
				<?php

			}

		


		}



	}elseif ($type=='cb') {	/*挖宝记录*/
			
		if ($n==0) {

			$uu = ','.$_SESSION['uid'].',';

			/*获取用户的挖宝记录*/
			$order = '  ';
			$rs = $D -> setbiao('jiangchi') -> order(  )->where( 
				array(
					'uids LIKE' => '%'.$ju.'%',
				)
			)-> select();

			?>


			{"status":"ok","l":"<ul><?php 
				if (is_array($rs)) {
					foreach($rs as  $k => $v){
						$xiangxi = unserialize($v['xiangxi']);
						$benarr = $xiangxi[$_SESSION['uid']];
						$lx = $v['lx'];
						$zongqian =  @array_sum($benarr);

			?><li onclick=\"lookluck('<?php echo $v['id'] ?>','<?php echo $v['id'] ?>','\u94c1\u94f2','0.00');\"><div class=\"l\"><p class=\"name\">[<?php if($lx==0){echo '铁铲'; } ?>]第<?php echo $v['id'] ?>组红包<\/p><p class=\"num\">\u8fd0\u6c14\u6709\u70b9\u5dee<\/p><\/div><div class=\"r\"><?php echo $zongqian ?><\/div><\/li><?php 
				}}
			?><\/ul>"}
			<?php
		}
	}elseif ($type=='hy') {
		
		if ($n=='1') {	/*一级好友*/
			/*查询一级好友*/
			$order = '  ';
			$tuis = $D -> setbiao('user') -> order(  )->where( 
				array(
					'tuid' => $_SESSION['uid'],
				)
			)-> select();


			if ($tuis) {?>


		{"status":"ok","l":"<em> <\/em><ul><?php 
			foreach($tuis as  $k => $v){

				$huiyuan1 = $D -> setbiao('user') -> where( 
					array( 
						"uid" => $v['uid'], 
					) 
				) -> find();

		?><li><div class=l><img src=<?php if ($huiyuan1['touxiang']) {?><?php echo $huiyuan1['touxiang'] ?><?php } else{ ?><?php echo WZHOST ?>wabao/tou.png<?php } ?>></div><div class=c><p class=name><?php echo $v['name'] ?></p><p>ID:<?php echo $v['uid'] ?></p></div><div class=r ><?php echo date("m-d",$v['atime'])?></div></li><?php }?></ul>"}
			<?php
				
			}else{
				?>
				{"status":"ok","l":"<em> <\/em><div class=\"loading nodata\">\u6ca1\u6709\u4e00\u7ea7\u597d\u53cb<\/div>"}
				<?php
			}

			?>




			<?php

		}elseif ($n=='2') {
			
				/*2级好友*/
			/*查询一级好友*/
			$order = '  ';
			$tuis = $D -> setbiao('user') -> order(  )->where( 
				array(
					'tuid1' => $_SESSION['uid'],
				)
			)-> select();


			if ($tuis) {?>


		{"status":"ok","l":"<em> <\/em><ul><?php 
			foreach($tuis as  $k => $v){
				$huiyuan2 = $D -> setbiao('user') -> where( 
					array( 
						"uid" => $v['uid'], 
					) 
				) -> find();
		?><li><div class=\"l\"><img src=\"<?php if ($huiyuan1['touxiang']) {?><?php echo $huiyuan1['touxiang'] ?>
		<?php
		}else{?><?php echo WZHOST ?>wabao\/tou.png\<?php } ?>"><\/div><div class=\"c\"><p class=\"name\"><?php echo $huiyuan2['name'] ?><\/p><p>ID:<?php echo $huiyuan2['uid'] ?><\/p><\/div><div class=\"r\"><?php echo date("m-d",$huiyuan2['atime'])?><\/div><\/li><?php 
			}
		?><\/ul>"}

			<?php
				
			}else{
				?>
				{"status":"ok","l":"<em> <\/em><div class=\"loading nodata\">没有二级好友<\/div>"}
				<?php
			}

			?>




			<?php

		
		}


	}
	?>




	<?php

}elseif ($action=='yaoqing') {	/**/

	?>
	
	<style type="text/css">
	.loadqr {
	    background: url("http://www.tianlirun.net/themes/2018/res/img/loading.gif") no-repeat top center;
	}
	</style>

	<div class="rule-box service" onClick="show_yaoqing();">
		<span class="rule-btn">邀请规则</span>
	</div>
	<div class="loadqr" style="min-height:100px;">
		<img src="/site/buildyaoqingqr?t=93375" width="100%">
	</div>
	<div class="inter-btn" style=" margin-top:20px;">
		<a href="javascript:void(0);" onclick="record_haoyou();"><div class="img"><img src="http://www.tianlirun.net/themes/2018/res/img/inter-btn.png"></div></a>
	</div>

	<?php

}elseif ($action=='song') {	/*赠送*/

	$user = $D -> setbiao('user') -> where( 
		array( 
			"uid" => $_SESSION['uid'], 
		) 
	) -> find();

	$tiechan = $user['tiechan'];

	$geshu = (float)$shezhi['geshu'];

	$newtiechan = $tiechan+$geshu;

	if ($user['islingqu']==0) {	/*更新铁铲,和是否领取*/

		$fan = $D ->setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(
			array(
				'islingqu' => 1,
				'tiechan' => $newtiechan
			)
		);



		if ($fan) {
			?>

			{"status":"ok","msg":"领取成功"}

			<?php
		}


	}else{
		?>

		{"status":"no","msg":"已经领取过了"}
		
		<?php
	}
	?>

	

	<?php

}elseif ($action=='wa') {
	/*判断客户端是否是微信*/
	// if (!is_weixin()) {
	// 	exit('fuck');

	// }

	$headers = apache_request_headers();

	// $Mem->s('lanjie/'.$_SESSION['uid'].'-'.time(),$headers);

	if ($_SESSION['uid']=='' || $_SESSION['uid']==0 ) {

		exit('fuck');
	}

	// $Mem->s('wuwei/'.$_SESSION['uid'].'-'.time(),$_POST);

	$D = db('');
		/*获取参数*/
	$n = isset($_POST['n']) ? $_POST['n'] :0;
	$jixu = isset($_POST['jixu']) ? $_POST['jixu'] :'1';	/*继续*/
	$token = isset($_POST['token']) ? $_POST['token'] :'';
	$time = isset($_POST['time']) ? $_POST['time'] :'';
	$yaa = md5($mima1.$time);

	// $kkk = 
	$jj = isset($_POST['jj']) ? $_POST['jj'] :'wuwei';
	$kkk = isset($_POST['kkk']) ? $_POST['kkk'] :'';



	if ($jixu>1 || $jixu<0) {
			
		exit('fuckjixu');

	}

	if ($jj=='wuwei') {

		$yanzheng  = md5($jj);

	}else{
		$yanzheng  = md5((int)$jj);
	}

	if ($yanzheng!= $kkk ) {
		exit('fuck');
	}

	if ($token!=$yaa) {

		exit('fuck');

	}

	$md5 = md5('wuweiwa'.$time);

	$user = $huiyuan = $D ->setbiao('user')-> where( array( "uid" => $_SESSION['uid'] ) ) -> find();

	$shifouwan  = $user['iszuobi'] ;

	if ($jixu==1) {

		if ($shifouwan==0) {

			exit('fuck1');

		}


	}elseif ($jixu==0) {

		$tiechanz = $user['tiechan'];
		$tongchanz = $user['tongchan'];
		$yinchanz = $user['yinchan'];
 		$jinchanz = $user['jinchan'];
		/*验证是否有铁铲*/

		if ($n==0) {/*看是够有铁铲*/
			if ($tiechanz<1) {
				exit('没有铁铲fuck');
			}
		}elseif ($n==1) {
			if ($tongchanz<1) {
				exit('没有铜铲fuck');
			}
		}elseif ($n==2) {

			if ($yinchanz<1) {
				exit('没有银铲fuck');
			}

		}elseif ($n==3) {
			
			if ($jinchanz<1) {
				exit('没有金铲fuck');
			}

		}

	}

	$ishiwan = $huiyuan['ishiwan'];
	/**/
	$bili = $shezhi['bili']/100;
		
	if ($ishiwan==0) {

		$n= 5;

	}else{

	}
	/*铁铲子*/
	if ($n==0) {

		/*铁铲*/
		$max = $shezhi['tiemax'];
		$qian = tongjiqian( $bili  ,$max ,$shezhi['fenbao'],$shezhi['zuida']);

		$order = ' id desc ';
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			);

		/*查询奖池中的随机数*/
		$tiaojian = array( 
					'jiangchi' => (int)$_SESSION['qishu'],
					'num !='=>'0',
					'uid' => $_SESSION['uid'],
					'lx' => 0,
				) ;
		$order = '  ';
		$jiangchix = $D -> setbiao('jiangchix') -> where( $tiaojian )->order(  ) -> find();

		if (!$jiangchix) {
			exit('fuck2');
		}

		$suijishu =  $jiangchix['num'];

		/*统计本奖池里本期抢了多少个了*/

		$order = '  ';
		$tiaojian = array(
			'jiangchi' => $_SESSION['qishu'],
			'num' => 0,
			'uid' => $_SESSION['uid'],
			'lx' => 0,
			);
		$nnd = $D -> setbiao('jiangchix') -> order( 'id asc' )->where( $tiaojian )-> select();

		if ($jixu==1) {
			
			if (!$nnd[0]['beizhu']=='1') {
				exit('fuck作弊');
			}

		}


		if (is_array($nnd)) {
			$nn = count($nnd);
		}

		$jisuanqian = (float)$shezhi['tiee'] - (float)$qian;	/*这里计算出随机钱*/

		
		// if ($tiechanz<1) {
		// 	exit('没有铁铲fuck');
		// }
		

		if ($qian==0) {	/*如果得出的钱等于0的话*/
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );
		}else{

		}

		if ($nn>=$suijishu) {

			$qian = 0;
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}

		/*在这里处理随机钱*/

		/*计算随机红包*/
		if ($jisuanqian==0) {
			
			$money=$shezhi['tiee'];

		}else{

			$money=$jisuanqian;    #总共要发的红包数;

		}

		if ($jisuanqian==0) {

			$people=7;        #总共要发的人数

		}else{

			$people=6;        #总共要发的人数

		}
		
		$scatter=100;    #分散度
		$reward=new reward();
		$rewardArr=$reward->splitReward($money,$people,$scatter);

		if ($jisuanqian==0) {

		}else{
			$rewardArr[] = 0;
		}

		$rewardStr = implode(',', $rewardArr);
		$sql = '';

		/*将中奖结果插入到数据*/
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			'jine' => $qian,
			'atime' => time(),
			'jiangchi' => $_SESSION['qishu'],
			'lx' => $n
			);

		if ($jixu==0) {
			
			$tiaojian['beizhu'] = '1';

		}

		if ($jisuanqian==0) {

			$tiaojian['isover'] = 1;

		}else{

			$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 4 , $JINE = $qian,$JIFEN = 0 , $HUOBI = 0  , $DATA = '铁铲获取金额' , $ip = $ip);

			if ($qian11) {	/*计算佣金*/

				/*获取佣金比例*/
				$aji = isset($shezhi['yiji']) ? $shezhi['yiji'] :'0';
				$bji = isset($shezhi['erji']) ? $shezhi['erji'] :'0';
				$cji = isset($shezhi['sanji']) ? $shezhi['sanji'] :'0';

				/*这里考虑到三级分销*/
				/*获取一级分销会员*/
				$tuid = $user['tuid'];
				if ( $tuid>0 ) {	/*说明存在一级会员*/
					/*查询一级会员是否存在*/
					$tui0 = $D ->setbiao('user')-> where( array( "uid" => $tuid ) ) -> find();

					if ($tui0) {	/*如果存在的话*/

						$yonghuo = ( (float)$aji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;
						
						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui0['uid'],
							'guanxi' => 1,
							'lx' => 0,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui0['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}

				}

				$tuid1 = $user['tuid1'];
				if ($tuid1>0) {	/*二级*/

					/*查询一级会员是否存在*/
					$tui1 = $D ->setbiao('user')-> where( array( "uid" => $tuid1 ) ) -> find();
					
					if ($tui1) {	/*如果存在的话*/

						$yonghuo = ( (float)$bji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);

						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui1['uid'],
							'guanxi' => 2,
							'lx' =>0 ,
							'deqian' => $yonghuo, 
							);

						$shuzustr = serialize($shuzu);

						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr, $ip = ip() );

					}

				}

				$tuid2 = $user['tuid2'];
				if ($tuid2>0) {

					/*查询一级会员是否存在*/
					$tui2 = $D ->setbiao('user')-> where( array( "uid" => $tuid2 ) ) -> find();
					
					if ($tui2) {	/*如果存在的话*/

						$yonghuo = ( (float)$cji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui2['uid'],
							'guanxi' => 3,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

			}
		}

		$sql.= $D->setshiwu(1)-> setbiao('jiangchix')-> insert( $tiaojian );
		/*更新铲子*/
		if ($jixu==0) {

			if ( (float)$huiyuan['tiechan'] >=1 ) {

			}else{
				exit('fuck');
			}

			$newtiechan = (float)$huiyuan['tiechan']-1;

			$sql.= $D -> setshiwu(1)-> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
				'tiechan' => $newtiechan,
				'iszuobi' => 1,
				));

			// 当没有的时候，插入数据到表里
			$sql.= $D->setshiwu(1)->setbiao('chanlog')-> insert(array(
				'uid' => $_SESSION['uid'],
				'type' => 0,
				'data' => '消耗铁铲',
				'ip' => ip(),
				'atime' => time(),
				'num' => 1
				));
		}


		// 执行事务
		$fanhui = $D ->qurey( $sql , 'shiwu');

	}elseif ($n==1) {

		/*铜铲*/
		$max = $shezhi['tongmax'];
		$qian = tongjiqian( $bili  ,$max,$shezhi['fenbao'],$shezhi['zuida']);

		$order = ' id desc ';
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			);

		/*查询奖池中的随机数*/
		$tiaojian = array( 
					'jiangchi' => (int)$_SESSION['qishu1'],
					'lx' => 1,
					'uid' => $_SESSION['uid'],
					'num !='=>'0',
				) ;
		$order = '  ';
		$jiangchix = $D -> setbiao('jiangchix') -> where( $tiaojian )->order(  ) -> find();
		if (!$jiangchix) {
			exit('fuck2');
		}

		$suijishu =  $jiangchix['num'];

		/*统计本奖池里本期抢了多少个了*/
		
		$order = '  ';
		$tiaojian = array(
			'jiangchi' => $_SESSION['qishu'],
			'num' => 0,
			'uid' => $_SESSION['uid'],
			'lx' => 1,
			);
		$nnd = $D -> setbiao('jiangchix') -> order( 'id asc' )->where( $tiaojian )-> select();


		if ($jixu==1) {
			
			if (!$nnd[0]['beizhu']=='1') {
				exit('fuck作弊');
			}

		}

		if (is_array($nnd)) {
			$nn = count($nnd);
		}


		$jisuanqian = (float)$shezhi['tonge'] - (float)$qian;	/*这里计算出随机钱*/



		if ($qian==0) {	/*如果得出的钱等于0的话*/

			$jisuanqian = 0;
			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );


		}else{

		}

		if ($nn>=$suijishu) {

			$qian = 0;
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );


		}
		
		/*计算随机红包*/
		if ($jisuanqian==0) {
			
			$money=$shezhi['tonge'];

		}else{

			$money=$jisuanqian;    #总共要发的红包数;

		}

		if ($jisuanqian==0) {

			$people=7;        #总共要发的人数

		}else{

			$people=6;        #总共要发的人数

		}
		
		$scatter=100;    #分散度
		$reward=new reward();
		$rewardArr=$reward->splitReward($money,$people,$scatter);

		if ($jisuanqian==0) {

		}else{
			$rewardArr[] = 0;
		}

		$rewardStr = implode(',', $rewardArr);
		$sql = '';


		/*将中奖结果插入到数据*/
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			'jine' => $qian,
			'atime' => time(),
			'jiangchi' => $_SESSION['qishu1'],
			'lx' => $n
			);


		if ($jixu==0) {
			
			$tiaojian['beizhu'] = '1';
			
		}
		if ($jisuanqian==0) {

			$tiaojian['isover'] = 1;


		}else{

			$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 5 , $JINE = $qian,$JIFEN = 0 , $HUOBI = 0  , $DATA = '铜铲获取金额' , $ip = $ip);

			if ($qian11) {	/*计算佣金*/

				/*获取佣金比例*/
				$aji = isset($shezhi['yiji']) ? $shezhi['yiji'] :'0';
				$bji = isset($shezhi['erji']) ? $shezhi['erji'] :'0';
				$cji = isset($shezhi['sanji']) ? $shezhi['sanji'] :'0';


				/*这里考虑到三级分销*/
				/*获取一级分销会员*/
				$tuid = $user['tuid'];
				if ( $tuid>0 ) {	/*说明存在一级会员*/
					/*查询一级会员是否存在*/
					$tui0 = $D ->setbiao('user')-> where( array( "uid" => $tuid ) ) -> find();

					if ($tui0) {	/*如果存在的话*/

						$yonghuo = ( (float)$aji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;
						
						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui0['uid'],
							'guanxi' => 1,
							'lx' => 1,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui0['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

				$tuid1 = $user['tuid1'];
				if ($tuid1>0) {	/*二级*/

					/*查询一级会员是否存在*/
					$tui1 = $D ->setbiao('user')-> where( array( "uid" => $tuid1 ) ) -> find();
					
					if ($tui1) {	/*如果存在的话*/

						$yonghuo = ( (float)$bji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);

						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui1['uid'],
							'guanxi' => 2,
							'lx' =>1,
							'deqian' => $yonghuo, 
							);

						$shuzustr = serialize($shuzu);

						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr, $ip = ip() );

					}

				}

				$tuid2 = $user['tuid2'];
				if ($tuid2>0) {

					/*查询一级会员是否存在*/
					$tui2 = $D ->setbiao('user')-> where( array( "uid" => $tuid2 ) ) -> find();
					
					if ($tui2) {	/*如果存在的话*/

						$yonghuo = ( (float)$cji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui2['uid'],
							'guanxi' => 3,
							'lx' =>1,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

			}
		}

		$sql.= $D->setshiwu(1)-> setbiao('jiangchix')-> insert( $tiaojian );
		/*更新铲子*/
		

		if ($jixu==0) {

			if ( (float)$huiyuan['tongchan'] >=1 ) {

			}else{
				exit('fuck');
			}
			

			$newtiechan = (float)$huiyuan['tongchan']-1;


			$sql.= $D -> setshiwu(1)-> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
				'tongchan' => $newtiechan,
				'iszuobi' => 1,
				));

			// 当没有的时候，插入数据到表里
			$sql.= $D->setshiwu(1)->setbiao('chanlog')-> insert(array(
				'uid' => $_SESSION['uid'],
				'type' => 1,
				'data' => '消耗铜铲',
				'ip' => ip(),
				'atime' => time(),
				'num' => 1
				));
		}


		// 执行事务
		$fanhui = $D ->qurey( $sql , 'shiwu');


	}elseif ($n==2) {

		/*银铲*/
		$max = $shezhi['yinmax'];
		$qian = tongjiqian( $bili  ,$max,$shezhi['fenbao'],$shezhi['zuida']);

		$order = ' id desc ';
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			);

		
		/*查询奖池中的随机数*/
		$tiaojian = array( 
					'jiangchi' => (int)$_SESSION['qishu2'],
					'num !='=>'0',
					'uid' => $_SESSION['uid'],
					'lx' => 2,
				) ;
		$order = '  ';
		$jiangchix = $D -> setbiao('jiangchix') -> where( $tiaojian )->order(  ) -> find();
		if (!$jiangchix) {
			exit('fuck2');
		}
		$suijishu =  $jiangchix['num'];

		/*统计本奖池里本期抢了多少个了*/
		$order = '  ';
		$tiaojian = array(
			'jiangchi' => $_SESSION['qishu'],
			'num' => 0,
			'uid' => $_SESSION['uid'],
			'lx' => 2,
			);
		$nnd = $D -> setbiao('jiangchix') -> order( 'id asc' )->where( $tiaojian )-> select();
		if ($jixu==1) {
			
			if (!$nnd[0]['beizhu']=='1') {
				exit('fuck作弊');
			}

		}

		if (is_array($nnd)) {
			$nn = count($nnd);
		}


		$jisuanqian = (float)$shezhi['yine'] - (float)$qian;	/*这里计算出随机钱*/

		if ($qian==0) {	/*如果得出的钱等于0的话*/

			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}else{

		}

		if ($nn>=$suijishu) {

			$qian = 0;
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}
		
		/*计算随机红包*/
		if ($jisuanqian==0) {
			
			$money=$shezhi['yine'];

		}else{

			$money=$jisuanqian;    #总共要发的红包数;

		}

		if ($jisuanqian==0) {

			$people=7;        #总共要发的人数

		}else{

			$people=6;        #总共要发的人数

		}
		
		$scatter=100;    #分散度
		$reward=new reward();
		$rewardArr=$reward->splitReward($money,$people,$scatter);

		if ($jisuanqian==0) {

		}else{
			$rewardArr[] = 0;
		}

		$rewardStr = implode(',', $rewardArr);
		$sql = '';

		/*将中奖结果插入到数据*/
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			'jine' => $qian,
			'atime' => time(),
			'jiangchi' => $_SESSION['qishu2'],
			'lx' => $n
			);

		if ($jixu==0) {
			
			$tiaojian['beizhu'] = '1';
			
		}
		if ($jisuanqian==0) {

			$tiaojian['isover'] = 1;

		}else{

			$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 6 , $JINE = $qian,$JIFEN = 0 , $HUOBI = 0  , $DATA = '银铲获取金额' , $ip = $ip);

			if ($qian11) {	/*计算佣金*/

				/*获取佣金比例*/
				$aji = isset($shezhi['yiji']) ? $shezhi['yiji'] :'0';
				$bji = isset($shezhi['erji']) ? $shezhi['erji'] :'0';
				$cji = isset($shezhi['sanji']) ? $shezhi['sanji'] :'0';


				/*这里考虑到三级分销*/
				/*获取一级分销会员*/
				$tuid = $user['tuid'];
				if ( $tuid>0 ) {	/*说明存在一级会员*/
					/*查询一级会员是否存在*/
					$tui0 = $D ->setbiao('user')-> where( array( "uid" => $tuid ) ) -> find();

					if ($tui0) {	/*如果存在的话*/

						$yonghuo = ( (float)$aji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;
						
						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui0['uid'],
							'guanxi' => 1,
							'lx' => 2,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui0['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

				$tuid1 = $user['tuid1'];
				if ($tuid1>0) {	/*二级*/

					/*查询一级会员是否存在*/
					$tui1 = $D ->setbiao('user')-> where( array( "uid" => $tuid1 ) ) -> find();
					
					if ($tui1) {	/*如果存在的话*/

						$yonghuo = ( (float)$bji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);

						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui1['uid'],
							'guanxi' => 2,
							'lx' =>2,
							'deqian' => $yonghuo, 
							);

						$shuzustr = serialize($shuzu);

						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr, $ip = ip() );

					}

				}

				$tuid2 = $user['tuid2'];
				if ($tuid2>0) {

					/*查询一级会员是否存在*/
					$tui2 = $D ->setbiao('user')-> where( array( "uid" => $tuid2 ) ) -> find();
					
					if ($tui2) {	/*如果存在的话*/

						$yonghuo = ( (float)$cji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui2['uid'],
							'guanxi' => 3,
							'lx' =>2,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

			}
		}

		$sql.= $D->setshiwu(1)-> setbiao('jiangchix')-> insert( $tiaojian );
		/*更新铲子*/
		if ($jixu==0) {

			if ( (float)$huiyuan['yinchan'] >=1 ) {

			}else{
				exit('fuck');
			}

			$newtiechan = (float)$huiyuan['yinchan']-1;
			$sql.= $D -> setshiwu(1)-> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
				'yinchan' => $newtiechan,
				'iszuobi' =>1
				));

			// 当没有的时候，插入数据到表里
			$sql.= $D->setshiwu(1)->setbiao('chanlog')-> insert(array(
				'uid' => $_SESSION['uid'],
				'type' => 2,
				'data' => '消耗银铲',
				'ip' => ip(),
				'atime' => time(),
				'num' => 1
				));
		}


		// 执行事务
		$fanhui = $D ->qurey( $sql , 'shiwu');

	}elseif ($n==3) {

		/*金铲*/
		$max = $shezhi['jinmax'];
		$qian = tongjiqian( $bili  ,$max,$shezhi['fenbao'],$shezhi['zuida']);

		$order = ' id desc ';
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			);

			/*查询奖池中的随机数*/
		$tiaojian = array( 
					'jiangchi' => (int)$_SESSION['qishu3'],
					'num !='=>'0',
					'uid' => $_SESSION['uid'],
					'lx' =>3
				) ;
		$order = '  ';
		$jiangchix = $D -> setbiao('jiangchix') -> where( $tiaojian )->order(  ) -> find();
		if (!$jiangchix) {
			exit('fuck2');
		}
		$suijishu =  $jiangchix['num'];

		/*统计本奖池里本期抢了多少个了*/
		

		$order = '  ';
		$tiaojian = array(
			'jiangchi' => $_SESSION['qishu'],
			'num' => 0,
			'uid' => $_SESSION['uid'],
			'lx' => 3,
			);
		$nnd = $D -> setbiao('jiangchix') -> order( 'id asc' )->where( $tiaojian )-> select();
		if ($jixu==1) {
			
			if (!$nnd[0]['beizhu']=='1') {
				exit('fuck作弊');
			}

		}

		if (is_array($nnd)) {
			$nn = count($nnd);
		}

		$jisuanqian = (float)$shezhi['jine'] - (float)$qian;	/*这里计算出随机钱*/

		if ($qian==0) {	/*如果得出的钱等于0的话*/

			$jisuanqian = 0;
			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}else{

		}

		if ($nn>=$suijishu) {

			$qian = 0;
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}
		
		/*计算随机红包*/
		if ($jisuanqian==0) {
			
			$money=$shezhi['jine'];

		}else{

			$money=$jisuanqian;    #总共要发的红包数;

		}

		if ($jisuanqian==0) {

			$people=7;        #总共要发的人数

		}else{

			$people=6;        #总共要发的人数

		}
		
		$scatter=100;    #分散度
		$reward=new reward();
		$rewardArr=$reward->splitReward($money,$people,$scatter);

		if ($jisuanqian==0) {

		}else{
			$rewardArr[] = 0;
		}

		$rewardStr = implode(',', $rewardArr);
		$sql = '';

		/*将中奖结果插入到数据*/
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			'jine' => $qian,
			'atime' => time(),
			'jiangchi' => $_SESSION['qishu3'],
			'lx' => $n
			);

		if ($jixu==0) {
			
			$tiaojian['beizhu'] = '1';
			
		}
		if ($jisuanqian==0) {

			$tiaojian['isover'] = 1;

		}else{

			$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 7 , $JINE = $qian,$JIFEN = 0 , $HUOBI = 0  , $DATA = '金铲获取金额' , $ip = $ip);

			if ($qian11) {	/*计算佣金*/

				/*获取佣金比例*/
				$aji = isset($shezhi['yiji']) ? $shezhi['yiji'] :'0';
				$bji = isset($shezhi['erji']) ? $shezhi['erji'] :'0';
				$cji = isset($shezhi['sanji']) ? $shezhi['sanji'] :'0';

				/*这里考虑到三级分销*/
				/*获取一级分销会员*/
				$tuid = $user['tuid'];
				if ( $tuid>0 ) {	/*说明存在一级会员*/
					/*查询一级会员是否存在*/
					$tui0 = $D ->setbiao('user')-> where( array( "uid" => $tuid ) ) -> find();

					if ($tui0) {	/*如果存在的话*/

						$yonghuo = ( (float)$aji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui0['uid'],
							'guanxi' => 1,
							'lx' => 3,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui0['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

				$tuid1 = $user['tuid1'];
				if ($tuid1>0) {	/*二级*/

					/*查询一级会员是否存在*/
					$tui1 = $D ->setbiao('user')-> where( array( "uid" => $tuid1 ) ) -> find();
					
					if ($tui1) {	/*如果存在的话*/

						$yonghuo = ( (float)$bji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);

						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui1['uid'],
							'guanxi' => 2,
							'lx' =>3,
							'deqian' => $yonghuo, 
							);

						$shuzustr = serialize($shuzu);

						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr, $ip = ip() );

					}

				}

				$tuid2 = $user['tuid2'];
				if ($tuid2>0) {

					/*查询一级会员是否存在*/
					$tui2 = $D ->setbiao('user')-> where( array( "uid" => $tuid2 ) ) -> find();
					
					if ($tui2) {	/*如果存在的话*/

						$yonghuo = ( (float)$cji/100 ) * (float)$qian;
						$yonghuo = sprintf("%0.2f",$yonghuo);
						// $yong = $yonghuo/$bili;

						$shuzu = array(
							'xiaofeiid' => $_SESSION['uid'],
							'dedaouid' => $tui2['uid'],
							'guanxi' => 3,
							'lx' =>3,
							'deqian' => $yonghuo,
							);
						$shuzustr = serialize($shuzu);
						$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
					}
				}

			}
		}

		$sql.= $D->setshiwu(1)-> setbiao('jiangchix')-> insert( $tiaojian );
		/*更新铲子*/
		if ($jixu==0) {

			if ( (float)$huiyuan['jinchan'] >=1 ) {

			}else{
				exit('fuck');
			}

			$newtiechan = (float)$huiyuan['jinchan']-1;
			$sql.= $D -> setshiwu(1)-> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
				'jinchan' => $newtiechan,
				'iszuobi' => 1
				));

			// 当没有的时候，插入数据到表里
			$sql.= $D->setshiwu(1)->setbiao('chanlog')-> insert(array(
				'uid' => $_SESSION['uid'],
				'type' => 3,
				'data' => '消耗金铲',
				'ip' => ip(),
				'atime' => time(),
				'num' => 1
				));
		}

		// 执行事务
		$fanhui = $D ->qurey( $sql , 'shiwu');

	}elseif ($n==5) {	/*试玩*/

		/*铁铲*/
		$max = $shezhi['mianfei'];
		$qian = tongjiqian( $bili  ,$max ,$shezhi['fenbao'],$shezhi['zuida']);



		$fen = mt_rand(1,(float)$shezhi['mianzu']);
		#分散度
		$reward=new reward();
		$rewardArr=$reward->splitReward((float)$shezhi['mianfei'],$fen,100);

		/*过滤掉值为0的项*/
		$guo = array_filter($rewardArr);
		$num = count($guo);
		$suiji = mt_rand(0,$num-1);
		$qian = $suijideqian = $guo[$suiji];


	

		$order = ' id desc ';
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			);

		$shu = $Mem1-> g('wuwei5/'.$_SESSION['uid']);
		if ($shu) {
			
			$newshu = $shu+1;
			$Mem1-> s('wuwei5/'.$_SESSION['uid'],$newshu);
			$nn = $shu;
		}else{
			$nn = 0;
			$Mem1-> s('wuwei5/'.$_SESSION['uid'],1);

			$suiji = mt_rand($shezhi['mkaishi'],$shezhi['mjieshu']);
			$Mem1-> s('wuwei51/'.$_SESSION['uid'],$suiji);

		}

		$suijishu = $Mem1 -> g('wuwei51/'.$_SESSION['uid']);
		// $suijishu = (float)$suijishu-1;

		// var_dump($suijishu);


		$jisuanqian = (float)$shezhi['tiee'] - (float)$qian;	/*这里计算出随机钱*/




		if ($qian==0) {	/*如果得出的钱等于0的话*/
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}else{

		}

		if ($nn>=$suijishu) {

			$qian = 0;
			$jisuanqian = 0;

			$tiaojian = array(
					'iszuobi' =>0
					);
			$fan = $D ->setbiao('user')->setshiwu(0)->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );

		}

		/*计算随机红包*/
		if ($jisuanqian==0) {
			
			$money=$shezhi['tiee'];

		}else{

			$money=$jisuanqian;    #总共要发的红包数;

		}

		if ($jisuanqian==0) {

			$people=7;        #总共要发的人数

		}else{

			$people=6;        #总共要发的人数

		}

		$scatter=100;    #分散度
		$reward=new reward();
		$rewardArr=$reward->splitReward($money,$people,$scatter);

		if ($jisuanqian==0) {

		}else{
			$rewardArr[] = 0;
		}

		$rewardStr = implode(',', $rewardArr);
		$sql = '';

		/*将中奖结果插入到数据*/
		$tiaojian = array(
			'uid' => $_SESSION['uid'],
			'jine' => $qian,
			'atime' => time(),
			);

		if ($jisuanqian==0) {

			$tiaojian['isover'] = 1;

			$Mem1-> s('wuwei5/'.$_SESSION['uid'],0);

			$suiji = mt_rand((float)$shezhi['mkaishi'],(float)$shezhi['mjieshu']);
			$Mem1-> s('wuwei51/'.$_SESSION['uid'],$suiji);


		}else{

			$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 10 , $JINE = $qian,$JIFEN = 0 , $HUOBI = 0  , $DATA = '铁铲获取金额' , $ip = $ip);

			if ($shezhi['mianyong']=='1') {	/*判断是够免费佣金*/


				if ($qian11) {	/*计算佣金*/

					/*获取佣金比例*/
					$aji = isset($shezhi['yiji']) ? $shezhi['yiji'] :'0';
					$bji = isset($shezhi['erji']) ? $shezhi['erji'] :'0';
					$cji = isset($shezhi['sanji']) ? $shezhi['sanji'] :'0';

					/*这里考虑到三级分销*/
					/*获取一级分销会员*/
					$tuid = $user['tuid'];
					if ( $tuid>0 ) {	/*说明存在一级会员*/
						/*查询一级会员是否存在*/
						$tui0 = $D ->setbiao('user')-> where( array( "uid" => $tuid ) ) -> find();

						if ($tui0) {	/*如果存在的话*/

							$yonghuo = ( (float)$aji/100 ) * (float)$qian;
							$yonghuo = sprintf("%0.2f",$yonghuo);
							// $yong = $yonghuo/$bili;
							
							$shuzu = array(
								'xiaofeiid' => $_SESSION['uid'],
								'dedaouid' => $tui0['uid'],
								'guanxi' => 1,
								'lx' => 0,
								'deqian' => $yonghuo,
								);
							$shuzustr = serialize($shuzu);
							$jianjian1 = jiaqian( $tui0['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
						}

					}

					$tuid1 = $user['tuid1'];
					if ($tuid1>0) {	/*二级*/

						/*查询一级会员是否存在*/
						$tui1 = $D ->setbiao('user')-> where( array( "uid" => $tuid1 ) ) -> find();
						
						if ($tui1) {	/*如果存在的话*/

							$yonghuo = ( (float)$bji/100 ) * (float)$qian;
							$yonghuo = sprintf("%0.2f",$yonghuo);

							// $yong = $yonghuo/$bili;

							$shuzu = array(
								'xiaofeiid' => $_SESSION['uid'],
								'dedaouid' => $tui1['uid'],
								'guanxi' => 2,
								'lx' =>0 ,
								'deqian' => $yonghuo, 
								);

							$shuzustr = serialize($shuzu);

							$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr, $ip = ip() );

						}

					}

					$tuid2 = $user['tuid2'];
					if ($tuid2>0) {

						/*查询一级会员是否存在*/
						$tui2 = $D ->setbiao('user')-> where( array( "uid" => $tuid2 ) ) -> find();
						
						if ($tui2) {	/*如果存在的话*/

							$yonghuo = ( (float)$cji/100 ) * (float)$qian;
							$yonghuo = sprintf("%0.2f",$yonghuo);
							// $yong = $yonghuo/$bili;

							$shuzu = array(
								'xiaofeiid' => $_SESSION['uid'],
								'dedaouid' => $tui2['uid'],
								'guanxi' => 3,
								'deqian' => $yonghuo,
								);
							$shuzustr = serialize($shuzu);
							$jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 8 , $JINE = $yonghuo , $JIFEN = 0 , $HUOBI = 0  , $DATA = $shuzustr , $ip = ip() );
						}
					}

				}


			}


			

		}

		// $sql.= $D->setshiwu(1)-> setbiao('jiangchix')-> insert( $tiaojian );
		/*更新铲子*/
		if ($jixu==0) {
			$fan = $D ->setshiwu(0)->setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(

				'ishiwan' =>1
				));

			if ( (float)$huiyuan['tiechan'] >=1 ) {

			}else{
				
				exit('fuck');

			}

			$newtiechan = (float)$huiyuan['tiechan']-1;
			$sql.= $D -> setshiwu(1)-> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
				'tiechan' => $newtiechan,
				'iszuobi' =>1
				));

			// 当没有的时候，插入数据到表里
			$sql.= $D->setshiwu(1)->setbiao('chanlog')-> insert(array(
				'uid' => $_SESSION['uid'],
				'type' => 0,
				'data' => '消耗铁铲',
				'ip' => ip(),
				'atime' => time(),
				'num' => 1
				));
		}
		
		// 执行事务
		$fanhui = $D ->qurey( $sql , 'shiwu');

		$hh = 5;
	}

?>

{"money":<?php echo $qian ?>,"id":"58ee95520b1609063d4202b1","bianhao":"<?php echo $fanhui1 ?>","key":"ef4eaa86c97da10b257f94fb6e4d76af","status":"ok","show":"no", "n":"<?php echo $hh ?>", "list":[<?php echo $rewardStr ?>]}
<?php

}elseif ($action=='getinfo') {	/*挖宝*/

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

	$jiangchi = $D -> setbiao('jiangchi') -> where( 
		array( 
			"id" => $id, 
		) 
	) -> find();

	$xiangxiarr = unserialize($jiangchi['xiangxi']);
	$shijians = unserialize($jiangchi['shijians']);

	$yiqiangarr = unserialize($jiangchi['yiqiang']);

	$num = count($yiqiangarr);



	?>
	{"status":"ok","data":{"y":"<?php echo $num ?>\/8","g":"1.4\/1.4","l":"<ul><?php 

		if (is_array($xiangxiarr)) {
			foreach($xiangxiarr as  $k => $v){
				$user = $D -> setbiao('user') -> where( 
					array( 
						"uid" => $k, 
					) 
				) -> find();

				$yong = $shijians[$k];

				if (is_array($v)) {
					$rr = 0;
					foreach($v as  $k1 => $v1){

	?><li><div class=\"l\"><img src=\"<?php if ($user['touxiang']) {
	 ?><?php echo $user['touxiang'] ?><?php }else{ ?>http:\/\/wx.qlogo.cn\/mmopen\/lKYqejEKQMZw9ibw6TaPF49Ign5AojoxJwOZSicmvu64YF9fehqqmEWwnXmDDtcFzibpicdDiaeXElAgLvULPVmaPGRzYMmdVjbxE\/0\<?php } ?>"><\/div><div class=\"c\"><p class=\"name\"><?php echo $user['name'] ?><\/p><p><?php echo date("Y-m-d H:i:s",$yong[$rr])?><\/p><\/div><div class=\"r\"><em><?php echo $v1 ?><\/em>\u5143<\/div><\/li><?php 
				$rr = $rr+1;
				}
			}
		}}
	?><\/ul>"}}

	<?php

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




	class WxPay
	{
		function __construct()
		{

		}
		
		function pay($url, $obj) 
		{
			$obj['nonce_str'] = $this->create_noncestr();
			$stringA = $this->formatQueryParaMap($obj, false);
			$stringSignTemp = $stringA . "&key=" . PARTNERKEY;
			$sign = strtoupper(md5($stringSignTemp));
			$obj['sign'] = $sign;
			
			$postXml = $this->arrayToXml($obj);
			$responseXml = $this->curl_post_ssl($url, $postXml);
			return $responseXml;
		}

		function create_noncestr($length = 32) 
		{
			$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
			$str = "";
			for ( $i = 0; $i < $length; $i++ )  {
				$str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
			}
			return $str;
		}

		function formatQueryParaMap($paraMap, $urlencode)
		{
			$buff = "";
			ksort($paraMap);
			foreach ($paraMap as $k => $v){
				if (null != $v && "null" != $v && "sign" != $k) {
				    if($urlencode){
					   $v = urlencode($v);
					}
					$buff .= $k . "=" . $v . "&";
				}
			}
			$reqPar;
			if (strlen($buff) > 0) {
				$reqPar = substr($buff, 0, strlen($buff)-1);
			}
			return $reqPar;
		}

		//数组转XML
		function arrayToXml($arr)
	    {
	        $xml = "<xml>";
	        foreach ($arr as $key=>$val)
	        {
				if (is_numeric($val)){
					$xml.="<".$key.">".$val."</".$key.">";
	        	}else{
	        	 	$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
				}
			}
	        $xml.="</xml>";
	        return $xml;
	    }

		function curl_post_ssl($url, $vars, $second=30)
		{
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_TIMEOUT, $second);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);

			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {	
			//Windows

				curl_setopt($ch, CURLOPT_SSLCERT, $shezhi['lujing'].'apiclient_cert.pem');
				curl_setopt($ch, CURLOPT_SSLKEY, $shezhi['lujing'].'apiclient_key.pem');
				curl_setopt($ch, CURLOPT_CAINFO, $shezhi['lujing'].'rootca.pem');
				

	        }else{                      

	          //LINUX
	            curl_setopt($ch, CURLOPT_SSLCERT, 'cert'.DIRECTORY_SEPARATOR.'apiclient_cert.pem');
				curl_setopt($ch, CURLOPT_SSLKEY, 'cert'.DIRECTORY_SEPARATOR.'apiclient_key.pem');
				curl_setopt($ch, CURLOPT_CAINFO, 'cert'.DIRECTORY_SEPARATOR.'rootca.pem');
	        }

			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
			$data = curl_exec($ch);
			if($data){
				curl_close($ch);
				return $data;
			}else {
				$error = curl_errno($ch);
				echo "call faild, errorCode:$error\n";
				curl_close($ch);
				return false;
			}
		}
	}

	$zuidi = $shezhi['zuidi'];

	/*首先查询用户金额*/
	$huiyuan = $D -> setbiao('user') -> where( 
		array( 
			"uid" => $_SESSION['uid'], 
		) 
	) -> find();

	$jine = $huiyuan['jine'];

	if ( (float)$jine> (float)$zuidi  ) {
		/*查看是否自动提现*/
		if ($shezhi['zidongtixian']=='1') {	/*自动提现*/

			if ($shezhi['hongbao']=='1') {
				
			/*获取设置*/
			$shezhi = $Mem1 -> g('shezhi')  ;
			$appid = $shezhi['appid'];
			$mchid = $shezhi['mchid'];
			$partnerkey = $shezhi['partnerkey'];

			$id =isset($_GET['id']) ? $_GET['id'] :'';

			$isxianjin = $shezhi['isxianjin'];

			$jine = (float)$huiyuan['jine'] *100 ;
			$uid = $tixian['uid'];
			if ($uid !='' ) {
				$user = $D -> setbiao('user') -> where( 
					array( 
						"uid" => $uid, 
					) 
				) -> find();

				if ($user['openid']!='') {

					header("Content-type: text/html; charset=utf-8");

					//APPID
					define('APPID', $appid);
					//商户id，10025915
					define('MCHID', $mchid);
					//微信支付密钥，商户平台中，账户设置->安全设置->API安全->API密钥：api设置
					define('PARTNERKEY',$partnerkey);
					//用户OpenID
					$openid = $user['openid'];
					//以下接口均已调试成功，需要你自行对接到自己的系统中。

					//现金红包
					$money = $jine;
					$sender = "现金红包";
					$obj2 = array();
					$obj2['wxappid']         	= APPID;
					$obj2['mch_id']         	= MCHID;
					$obj2['mch_billno']			= MCHID.date('YmdHis').rand(1000, 9999);
					$obj2['client_ip']    		= $_SERVER['REMOTE_ADDR'];
					$obj2['re_openid']         	= $user['openid'];
					$obj2['total_amount']       = $money;
					$obj2['min_value']         	= $money;
					$obj2['max_value']         	= $money;
					$obj2['total_num']         	= 1;
					$obj2['nick_name']      	= $sender;
					$obj2['send_name']      	= $sender;
					$obj2['wishing']        	= "现金红包";
					$obj2['act_name']      		= $sender."红包";
					$obj2['remark']      		= $sender."红包";

					$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
					$wxHongBaoHelper2 = new WxPay();
					$result = $wxHongBaoHelper2->pay($url, $obj2);
						

					  $woqu = str_replace(array('<','>'),'',$result);

					     $p = xml_parser_create();
					     xml_parse_into_struct($p, $result, $vals, $index);
					     xml_parser_free($p);


					$shuju = array();
					foreach( $vals as $zhis)  $shuju[ strtolower( $zhis['tag'] ) ] = isset( $zhis['value']) ? $zhis['value'] :'';

					$return_code = $shuju['return_code'];
					if ($return_code=='SUCCESS') {

						// $fan = $D ->setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
						// 			'jine' =>'0.00'
						// 			));

						$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 11 , $JINE = -(float)$money,$JIFEN = 0 , $HUOBI = 0  , $DATA = '会员提现' , $ip = $ip);
								if ($qian11) {
									$arr['status'] = 'ok';
									$arr['msg'] = '提现成功';

									$tiaojian = array(
										'uid' => $huiyuan['uid'],
										'off'=>1,
										'jine' => $money
										);
									$fanhui = $D-> setbiao('tixian')-> insert( $tiaojian );

								}

					}

				}else{
					msgbox('此用户没有关注该公众号');
				}
			}

// //裂变红包
// $money = 501;
// $sender = "娃娃";
// $obj3 = array();
// $obj3['wxappid']         	= APPID;
// $obj3['mch_id']         	= MCHID;
// $obj3['mch_billno']			= MCHID.date('YmdHis').rand(1000, 9999);
// // $obj3['client_ip']    		= $_SERVER['REMOTE_ADDR'];
// $obj3['re_openid']         	= "orgvAt8BtFG33GCbrLgKZR8eNTKg";
// $obj3['total_amount']       = $money;
// $obj3['amt_type']         	= "ALL_RAND";
// // $obj3['max_value']         	= $money;
// $obj3['total_num']         	= 3;
// // $obj3['nick_name']      	= $sender;
// $obj3['send_name']      	= $sender;
// $obj3['wishing']        	= "恭喜发财";
// $obj3['act_name']      		= $sender."红包";
// $obj3['remark']      		= $sender."红包";


// var_dump($obj3);

// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack';
// $wxHongBaoHelper3 = new WxPay();
// $result = $wxHongBaoHelper3->pay($url, $obj3);
// var_dump($result);




// //企业付款
// $obj1 = array();
// $obj1['openid']         	= "ozh-4jg4F8zkHlz-xmUavAJzrXEo";
// $obj1['amount']         	= "101";
// $obj1['desc']        		= "毛小二付款";
// $obj1['mch_appid']         	= APPID;
// $obj1['mchid']         		= MCHID;
// $obj1['partner_trade_no']	= MCHID.date('YmdHis').rand(1000, 9999);
// $obj1['spbill_create_ip']   = $_SERVER['REMOTE_ADDR'];
// $obj1['check_name']      	= "FORCE_CHECK";
// $obj1['re_user_name']    	= "娃娃";

// var_dump($obj1);
// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
// $wxHongBaoHelper = new WxPay();
// $result = $wxHongBaoHelper->pay($url, $obj1);
// var_dump($result);




// // //红包查询(含现金红包和裂变红包)
// // $obj4 = array();
// // $obj4['appid']         		= APPID;
// // $obj4['mch_id']         	= MCHID;
// // $obj4['mch_billno']			= "1253901501201508011624442581";
// // $obj4['bill_type']         	= "MCHT";
// // var_dump($obj4);

// // $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo';
// // $wxHongBaoHelper4 = new WxPay();
// // $result = $wxHongBaoHelper4->pay($url, $obj4);

//企业付款查询
// $obj5 = array();
// $obj5['appid']         		= APPID;
// $obj5['mch_id']         	= MCHID;
// $obj5['partner_trade_no']	= "1253901501201508011624425667";

// var_dump($obj5);

// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo';
// $wxHongBaoHelper5 = new WxPay();
// $result = $wxHongBaoHelper5->pay($url, $obj5);


			}elseif ($shezhi['hongbao']=='2') {	/*零钱到张*/


				/*获取设置*/
				$shezhi = $Mem1 -> g('shezhi')  ;
				$appid = $shezhi['appid'];
				$mchid = $shezhi['mchid'];
				$partnerkey = $shezhi['partnerkey'];


				$id =isset($_GET['id']) ? $_GET['id'] :'';

				$isxianjin = $shezhi['zidongtixian'];


				if ($isxianjin=='1') {
					$jine = (float)$huiyuan['jine'] *100 ;
						

						$user = $D -> setbiao('user') -> where( 
							array( 
								"uid" => $_SESSION['uid'], 
							) 
						) -> find();



						if ($user['openid']!='') {

							header("Content-type: text/html; charset=utf-8");

							//APPID
							define('APPID', $appid);
							//商户id，10025915
							define('MCHID', $mchid);
							//微信支付密钥，商户平台中，账户设置->安全设置->API安全->API密钥：api设置
							define('PARTNERKEY',$partnerkey);
							//用户OpenID
							$openid = $user['openid'];
							//以下接口均已调试成功，需要你自行对接到自己的系统中。

							//现金红包
							// $money = $jine;
							// $sender = "夹娃娃";
							// $obj2 = array();
							// $obj2['wxappid']         	= APPID;
							// $obj2['mch_id']         	= MCHID;
							// $obj2['mch_billno']			= MCHID.date('YmdHis').rand(1000, 9999);
							// $obj2['client_ip']    		= $_SERVER['REMOTE_ADDR'];
							// $obj2['re_openid']         	= $user['openid'];
							// $obj2['total_amount']       = $money;
							// $obj2['min_value']         	= $money;
							// $obj2['max_value']         	= $money;
							// $obj2['total_num']         	= 1;
							// $obj2['nick_name']      	= $sender;
							// $obj2['send_name']      	= $sender;
							// $obj2['wishing']        	= "恭喜发财";
							// $obj2['act_name']      		= $sender."红包";
							// $obj2['remark']      		= $sender."红包";

							// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
							// $wxHongBaoHelper2 = new WxPay();
							// $result = $wxHongBaoHelper2->pay($url, $obj2);

							//企业付款
							$money = $jine;
							$obj1 = array();
							$obj1['openid']         	=  $user['openid'];
							$obj1['amount']         	= $money;
							$obj1['desc']        		= "零钱到账";
							$obj1['mch_appid']         	= APPID;
							$obj1['mchid']         		= MCHID;
							$obj1['partner_trade_no']	= MCHID.date('YmdHis').rand(1000, 9999);
							$obj1['spbill_create_ip']   = $_SERVER['REMOTE_ADDR'];
							$obj1['check_name']      	= "NO_CHECK";
							$obj1['re_user_name']    	= "零钱到账";


							$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
							$wxHongBaoHelper = new WxPay();
							$result = $wxHongBaoHelper->pay($url, $obj1);


							  $woqu = str_replace(array('<','>'),'',$result);

							     $p = xml_parser_create();
							     xml_parse_into_struct($p, $result, $vals, $index);
							     xml_parser_free($p);


							$shuju = array();
							foreach( $vals as $zhis)  $shuju[ strtolower( $zhis['tag'] ) ] = isset( $zhis['value']) ? $zhis['value'] :'';

							$return_code = $shuju['result_code'];

							if ($return_code=='SUCCESS') {

								// $fan = $D ->setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update(array(
								// 	'jine' =>'0.00'
								// 	));

								$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 11 , $JINE = -(float)$money,$JIFEN = 0 , $HUOBI = 0  , $DATA = '会员提现' , $ip = $ip);

								if ($qian11) {
									$arr['status'] = 'ok';
									$arr['msg'] = '提现成功';

									$tiaojian = array(
										'uid' => $huiyuan['uid'],
										'off'=>1,
										'jine' => $money
										);
									$fanhui = $D-> setbiao('tixian')-> insert( $tiaojian );

								}

							}else{

								$arr['status'] = '';
								$arr['msg'] = '提现失败';

							}

						}else{
							msgbox('此用户没有关注该公众号');
						}
				

				}else{




				}



// //裂变红包
// $money = 501;
// $sender = "方倍";
// $obj3 = array();
// $obj3['wxappid']         	= APPID;
// $obj3['mch_id']         	= MCHID;
// $obj3['mch_billno']			= MCHID.date('YmdHis').rand(1000, 9999);
// // $obj3['client_ip']    		= $_SERVER['REMOTE_ADDR'];
// $obj3['re_openid']         	= "orgvAt8BtFG33GCbrLgKZR8eNTKg";
// $obj3['total_amount']       = $money;
// $obj3['amt_type']         	= "ALL_RAND";
// // $obj3['max_value']         	= $money;
// $obj3['total_num']         	= 3;
// // $obj3['nick_name']      	= $sender;
// $obj3['send_name']      	= $sender;
// $obj3['wishing']        	= "恭喜发财";
// $obj3['act_name']      		= $sender."红包";
// $obj3['remark']      		= $sender."红包";


// var_dump($obj3);

// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack';
// $wxHongBaoHelper3 = new WxPay();
// $result = $wxHongBaoHelper3->pay($url, $obj3);
// var_dump($result);




// //企业付款
// $obj1 = array();
// $obj1['openid']         	= "ozh-4jg4F8zkHlz-xmUavAJzrXEo";
// $obj1['amount']         	= "101";
// $obj1['desc']        		= "毛小二付款";
// $obj1['mch_appid']         	= APPID;
// $obj1['mchid']         		= MCHID;
// $obj1['partner_trade_no']	= MCHID.date('YmdHis').rand(1000, 9999);
// $obj1['spbill_create_ip']   = $_SERVER['REMOTE_ADDR'];
// $obj1['check_name']      	= "FORCE_CHECK";
// $obj1['re_user_name']    	= "方倍";

// var_dump($obj1);
// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
// $wxHongBaoHelper = new WxPay();
// $result = $wxHongBaoHelper->pay($url, $obj1);
// var_dump($result);




// // //红包查询(含现金红包和裂变红包)
// // $obj4 = array();
// // $obj4['appid']         		= APPID;
// // $obj4['mch_id']         	= MCHID;
// // $obj4['mch_billno']			= "1253901501201508011624442581";
// // $obj4['bill_type']         	= "MCHT";
// // var_dump($obj4);

// // $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo';
// // $wxHongBaoHelper4 = new WxPay();
// // $result = $wxHongBaoHelper4->pay($url, $obj4);

//企业付款查询
// $obj5 = array();
// $obj5['appid']         		= APPID;
// $obj5['mch_id']         	= MCHID;
// $obj5['partner_trade_no']	= "1253901501201508011624425667";

// var_dump($obj5);

// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo';
// $wxHongBaoHelper5 = new WxPay();
// $result = $wxHongBaoHelper5->pay($url, $obj5);





			}

		}else{	/*不自动提现*/
			// 当没有的时候，插入数据到表里



		}



	}else{
		$arr['o'] = 'zuidi';
		$arr['msg'] = '最低提现金额为'.$zuidi;
	}

	echo json_encode($arr);

}elseif ($action=='tixian1') {
	
	$zhanghao = isset($_POST['zhanghao']) ? $_POST['zhanghao'] :'';
	$xingming = isset($_POST['xingming']) ? $_POST['xingming'] :'';
	$amount = isset($_POST['amount']) ? $_POST['amount'] :'';

	/*计算余钱*/
	$user = uid( $_SESSION['uid'] , 1 );
	$yue = $user['jine'];


	if ( $yue  < $shezhi['zuidi']   ) {

		exit('最低提现不达标');

	}


	$sql='';
	$tiaojian = array(
		'name' => $xingming,
		'zhanghao' => $zhanghao,
		'uid' => $_SESSION['uid'],
		'jine' => $yue,
		'atime' => time(),
		);
	$sql .= $D->setshiwu(1) -> setbiao('tixian')-> insert( $tiaojian );

	$tiaojian = array(
			'jine' => 0
			);
	// $sql .= $D -> setshiwu(1) -> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );
	// 执行事务
	$fanhui = $D ->qurey( $sql , 'shiwu');

	if ($fanhui) {

		$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 11 , $JINE = -(float)$yue,$JIFEN = 0 , $HUOBI = 0  , $DATA = '会员提现' , $ip = $ip);
		$arr['status'] = 'ok';
		$arr['msg'] = '等待管理员审核';
	}

	echo json_encode($arr);


}elseif ($action=='tixian2') {
	
	$zhanghao = isset($_POST['zhanghao']) ? $_POST['zhanghao'] :'';
	$xingming = isset($_POST['xingming']) ? $_POST['xingming'] :'';
	$amount = isset($_POST['amount']) ? $_POST['amount'] :'';

	/*计算余钱*/
	$user = uid( $_SESSION['uid'] , 1 );
	$yue = $user['jine'];


	if ( $yue  < $shezhi['zuidi']   ) {

		exit('最低提现不达标');

	}


	$sql='';
	$tiaojian = array(
		'name' => $xingming,
		'zhanghao' => $zhanghao,
		'uid' => $_SESSION['uid'],
		'jine' => $yue,
		'atime' => time(),
		);
	$sql .= $D->setshiwu(1) -> setbiao('tixian')-> insert( $tiaojian );

	$tiaojian = array(
			'jine' => 0
			);
	// $sql .= $D -> setshiwu(1) -> setbiao('user')->where( array("uid"=>$_SESSION['uid']))-> update( $tiaojian );
	// 执行事务
	$fanhui = $D ->qurey( $sql , 'shiwu');

	if ($fanhui) {

		$qian11 = jiaqian( $_SESSION['uid'] , $TYPE = 11 , $JINE = -(float)$yue,$JIFEN = 0 , $HUOBI = 0  , $DATA = '会员提现' , $ip = $ip);
		$arr['status'] = 'ok';
		$arr['msg'] = '等待管理员审核';
	}

	echo json_encode($arr);


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

	$shoujihao = isset($_POST['shoujihao']) ? $_POST['shoujihao'] :'';
	$suiji = mt_rand(1000,9999);
	$neirong = '您的验证码是'.$suiji.'请妥善保管';
	$fa = faduanxin($shoujihao,$neirong,$shezhi['duanxinid'],$shezhi['duanxinkey']);

	$fas = explode(':', $fa);
	$laizi = $fas[0];
	if ($laizi=='error') {
		$arr['o'] ='no';

	}elseif ($laizi=='success') {
		$arr['o'] ='yes';
		$_SESSION['yanzhengma'] = $suiji;
	}

	$_SESSION['yanzhengma'] = '1234';

	echo json_encode($arr);

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

	$D = db('');
	$name = isset($_POST['name']) ? $_POST['name'] :'';
	$yanzhengma = isset($_POST['yanzhengma']) ? $_POST['yanzhengma'] :'';

	if ($yanzhengma!=$_SESSION['yanzhengma']) {

		$arr['o'] = '验证码错误';

	}else{

		$user = $D -> setbiao('user') -> where( 
			array( 
				"zhanghao" => $name, 
			) 
		) -> find();


		if ($user) {
		
			// $mima = mima($mima);
			// if ($user['mima']  == $mima ) {
				
			// 	$_SESSION['uid'] = $user['uid'];
			// 	$arr['o'] ='yes';

			// }else{
			// 	$arr['o'] ='密码错误';
			// }

			$_SESSION['uid'] = $user['uid'];
			 $arr['o'] ='yes';

		}else{

			$WHERE['zhanghao'] = $name;
			$WHERE['shouji'] = $name;
			$WHERE['name'] = xinghao($name);
			$WHERE['mima'] = mima($mima);
			$WHERE['atime'] = time();
			$WHERE['off'] = 1;
			$WHERE['ip'] = ip();

			if ($_SESSION['adminid']) {
				$WHERE['adminid'] = $_SESSION['adminid']  ;
			}

			 if( isset( $_SESSION['tuid'] ) ){

			                        if( $_SESSION['tuid']  > 0){

			                            $tui = $D ->setbiao('user')-> where( array( "uid" => $_SESSION['tuid'] ) ) -> find();

			                            if( $tui ){

			                                    $WHERE['tuid'] = $_SESSION['tuid'];

			                                    for( $i = 1 ; $i < $CONN['tujishu'] ; $i++ ){

			                                         $wds = $i-1;
			                                         if($wds < 1) $wds= '' ;
			                                         $WHERE['tuid'.$i] = $tui['tuid'.$wds];

			                                    }
			                            }
			                        }

		            }

		      


			// 当没有的时候，插入数据到表里
			$fanhui = $D-> setbiao('user')-> insert($WHERE);

			if ($fanhui) {
				$arr['o'] ='yes';
				$_SESSION['uid'] = $fanhui;
				

			}else{
				$arr['o'] ='no';
			}
		}

	}

	

	echo json_encode($arr);



}
?>