<?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']);
		 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=='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=='genggaichanzi') {	/*更改铲子*/

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

	$user = uid($id,1);

	if ($leixing=='tiechan') {

		$tiechan = $user['tiechan'];
		$newtiechan = (float)$tiechan + (float)$wenben;

		$gengxin = array(

			'tiechan' => $newtiechan,

			);

		$type = 8;
		
	}elseif ($leixing=='tongchan') {

		$tiechan = $user['tongchan'];
		$newtiechan = (float)$tiechan + (float)$wenben;

		$gengxin = array(

			'tongchan' => $newtiechan,

			);

		$type = 9;

	}elseif ($leixing=='yinchan') {

		$tiechan = $user['yinchan'];
		$newtiechan = (float)$tiechan + (float)$wenben;

		$gengxin = array(

			'yinchan' => $newtiechan,

			);
		$type = 10;

	}elseif ($leixing=='jinchan') {
		


		$tiechan = $user['jinchan'];
		$newtiechan = (float)$tiechan + (float)$wenben;

		$gengxin = array(

			'jinchan' => $newtiechan,

			);

		$type = 11;

	}elseif ($leixing=='jine') {
		
		$ip = ip();
		$qian11 = jiaqian( $id , $TYPE = 9 , $JINE = (float)$wenben,$JIFEN = 0 , $HUOBI = 0  , $DATA = '手动增加钱' , $ip = $ip);
		if ($qian11) {

			$arr['o'] ='yes';
		}


	}


	$fan = $D -> setbiao('user')->where( array("uid"=> $id ))->update( $gengxin );

	if ($fan) {
		$arr['o'] ='yes';

		if ( (float)$wenben>0  ) {

			$data = '增加';
		}else{
			$data = '消耗';
		}

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

			array( 	'uid' => '-1',
						'type' => $type ,
						'data' => $data ,
						'ip' => $ip == '' ? ip(): $ip,
						'num' => (float)$wenben,
						'atime' => time(),
                                          		)



			);

	}

	echo json_encode($arr);
}elseif ($action=='tixian') {
	
	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';
	$tiaojian = array(
			'off' => 1
			);
	$fan = $D ->setbiao('tixian')->where( array("id"=>$zhi))-> update( $tiaojian );

	if ($fan) {
		$arr['o'] = 'yes';
	}

	echo json_encode($arr);

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

	
	
	$zhifufs = isset($_POST['zhifufs']) ? $_POST['zhifufs'] :'';
	$xingming = isset($_POST['xingming']) ? $_POST['xingming'] :'';
	$zhanghao = isset($_POST['zhanghao']) ? $_POST['zhanghao'] :'';
	$adminid = isset($_POST['adminid']) ? $_POST['adminid'] :'';


	$tiaojian = array( 
				'id' => $adminid,
			) ;
	$order = '  ';
	$jiang = $D -> setbiao('admin') -> where( $tiaojian ) ->order(  ) -> find();
	$houtype = $jiang['type'];

	$D = db('');
	/*查询当前代理下的总用户*/
	$order = '  ';
	$tiaojian = array(
	  'adminid' => $adminid,
	  );
	$daili = $D -> setbiao('user') -> order(  )->where( $tiaojian )-> select();


	if ($daili) {
	  
	  $daiu  =array();
	  foreach($daili as  $k => $v){
	    $daiu[] = $v['uid'];
	  }


	      $order = '  ';
	      $tiaojian = array(
	        'type' => 1,
	        'uid IN' => $daiu, 
	        );
	      $chongz = $D -> setbiao('jinelog') -> order(  )->where( $tiaojian )-> select();




	      if ( $chongz ) {
	        $chondd = array();
	        foreach($chongz as  $k => $v){
	          $chondd[] = $v['jine'];
	        }

	        $chonddz = array_sum($chondd);
	      }

	}






 if ($shezhi['daili']!='') {

    $dailiarr = explode(',',  $shezhi['daili'] );


    if ($houtype==1) {

      $dailibi = $dailiarr[0];
    }elseif ($houtype==2) {
          $dailibi = $dailiarr[1];
    }elseif ($houtype==3) {
            $dailibi = $dailiarr[2];
    }

}

      $dailibi1 = $dailibi/100;
      // $qianbili = $shezhi['bili']/100;
      // $qianbili =1;


  $rr1 = $chonddz * $qianbili * $dailibi1;

  $order = '  ';
  $tiaojian = array(
    'adminid' => $_SESSION['houid'],
    );
  $daitixian = $D -> setbiao('dailitixian') -> order(  )->where( $tiaojian )-> select();

  if ($daitixian) {
    $daia = array();
    foreach($daitixian as  $k => $v){
      $daia[] = $v['jine'];

    }

    $daiak = array_sum($daia);


  }else{
    $daiak = 0;
  }

  $rrwww = $rr1 - $daiak;

  if ($rrwww>0) {
  	
  	  $tiaojian = array(
  	'adminid' => $adminid,
  	'jine' => $rrwww,
  	'atime' => time(),
  	'ip' => ip()
  	);
	  $fanhui = $D-> setbiao('dailitixian')-> insert( $tiaojian );

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


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

echo json_encode($arr);



	
}elseif ($action=='dailishenhe') {
	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';

	$tiaojian = array(
			'off' => 1
			);
	$fan = $D ->setbiao('dailitixian')->where( array("id"=>$zhi))-> update( $tiaojian );

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

	echo json_encode($arr);

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

	$key = $shezhi['lingkey'];
	$linguid = $shezhi['linguid'];

	if ($shezhi['linguid']!='') {
		$mid = $shezhi['linguid'];
	}else{
		exit('没有设置零钱uid');
	}
	
	$zhi = isset($_POST['zhi']) ? $_POST['zhi'] :'';
	$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 (!$huiyuan) {
		exit('没有此会员');
	}
	$openid = $huiyuan['weixin'];
	if ($openid=='') {
		exit('此人没有openid');
	}

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

		$post_data = array (
			'key' => $key,
			'mid' => $mid,
			'jine' => $jine,
			'openid'=>$openid,
			'tixianid'=>$jiang['id'],
			'lailu' =>$lailu,
		);

		$mkey = md5(serialize($post_data));
		$post_data['mkey'] = $mkey;
		$url = $shezhi['lingurl'];
		$da = post($post_data,$url);

		echo "<pre>";
		var_dump( $da );
		echo "</pre>";



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

	}


	





}


?>