<?php if( !defined( 'ONGPHP')) exit( 'Error ONGSOFT');
plus(array('p','jiami','jianli','mima','shanchu','qcurl','qfopen','x','memcc','txtcc','db','isutf8','setsession','pagec','pinyin','ip','post','funciton','tcpcc','mongodbcc','vcode','ipdiqu','update','route','sslget','sslpost'));
$Memsession =  $Mem = new txtcc();

$Mem1 = new txtcc(ONGPHP.'/mode/');
$shezhi = $Mem1->g('shezhi');

//dump($shezhi);exit;
$D = db('');
$action = isset($_POST['action']) ? $_POST['action'] :'';



if ($action=='buyNumber') {	

//     $array['success'] = true;
//     $array['last_number'] = 2;//实际
//     $array['number'] = 2;//猜的
//     $array['left_cash_time'] = 0;
//     $array['wx_order_number'] = 100032323263263;5
//     $array['is_win'] = 0;
//     $array['tail'] = 4;
//     $array['status'] = 2;
//     $array['win_money'] = 20;
//     $array['total_hand'] = 1;
//     $array['buy_money'] = 10;
//     echo json_encode($array);exit;
    
    $total_hand = isset($_POST['total_hand']) ? $_POST['total_hand'] :'';
    $number = $_POST['number'];
    $number = (int)$number;
    $yazhu  = array(0,1,2,3);
    
    if(!in_array($number, $yazhu)){
        
        $info['success'] = false;
        $info['msg'] = "最少下注1手!";
        
        exit(json_encode($info));
        
    }
    
    $jishou = (int)$total_hand;
	$total_hand = (int)$total_hand*10;
	
    $total_jine = (float)$total_hand+ $jishou+1;
    /*查看是否是数据库的一种
     * 
     * 
     * <pre>array(5) {
  [&quot;o&quot;] =&gt; string(3) &quot;yes&quot;
  [&quot;orderid&quot;] =&gt; string(20) &quot;20170829111936763387&quot;
  [&quot;payment_no&quot;] =&gt; string(28) &quot;1000018301201708299485221757&quot;
  [&quot;partner_trade_no&quot;] =&gt; string(20) &quot;20170829111935717319&quot;
  [&quot;payment_time&quot;] =&gt; string(19) &quot;2017-08-29 11:19:36&quot;
}
</pre>{"o":"yes"
     */
    $huiyuan = $user = $D -> setbiao('user')-> where( array( "uid" => $_SESSION['uid'] ) ) -> find();
    
    if($jishou<=0){
        
        $info['success'] = false;
        $info['msg'] = "最少下注1手!";
        
        exit(json_encode($info));
        
    }
    
    if((float)$total_jine>(float)$huiyuan['jine']){
        
        $info['success'] = false;
        $info['msg'] = "余额不足";
        
        exit(json_encode($info));
        
        
    }
    
   if($shezhi['weixintixian'] == 1){
    
    $tixianid = 'whjc'.time().rand(10000, 99999);//商户订单号
	
   }else{
	   
	   $tixianid = time().rand(1,9);//商户订单号
	   
   }
    $tiaojian = array(
    
        'uid' => $_SESSION['uid'],
        'jine' => 1,
        'name'=>$huiyuan['name'],
        'tixianid'=>(string)$tixianid,
        'type'=>3,//游戏中订单1元
        'off'=>0,//
        'atime'=>time(),
        'ip'=>ip(),
    
    );
    $result = $D -> setbiao('tixian')-> insert( $tiaojian );
    //$result = $D -> setbiao('tixian')-> find();
    //dump($result);exit;
    
    if(!$result){
    
        $info['success'] = false;
        $info['msg'] = "未知错误3,请刷新重试";
    
        exit(json_encode($info));
    
    }
    //dump($tixianid);exit;
    

    //$shezhi['weixintixian'] = 1;
    //确定玩游戏 体现方式 第三方还是微信自带
    if($shezhi['weixintixian'] == 1){
    
       
        $chuanzhi['openid'] = $huiyuan['openid'];
        $chuanzhi['appid']  = $shezhi['appid'];//公众账号appid
        $chuanzhi['name']  = $huiyuan['name'];//姓名
        
        $chuanzhi['partner_trade_no']  = $tixianid;//公众账号appid
        $chuanzhi['mchid']  = $shezhi['mchid'];//公众账号appid
        $chuanzhi['partnerkey'] = $shezhi['partnerkey'];//公众账号appid
        $chuanzhi['amount'] = 100;
        
        $chuanzhi['ip'] = $shezhi['ip'];
        
        $result = weixintixian($chuanzhi);
        
    }else{
        
        $chuanzhi['txopenid'] = $huiyuan['txopenid'];
        $chuanzhi['linguid'] = $shezhi['linguid'];
        $chuanzhi['lingkey'] = $shezhi['lingkey'];
        $chuanzhi['lailu']  = WZHOST.'ajax.php';
        $chuanzhi['jine']  = 1;
        $chuanzhi['lingurl']  = $shezhi['lingurl'];
        $chuanzhi['tixianid']  = $tixianid;
        $chuanzhi['lx']  = 8;
        
        $result = zstixain($chuanzhi);
    }
    
   
    if($result['success'] != true){
        
        exit;
        
    }
    
    $JINE = (float)$total_jine;
    
    $DATA = "撸".$jishou."手,消耗".$JINE.'积*分，其中'.$jishou.'积*分是手续费';
    
    $jianjian = jiaqian($_SESSION['uid'] , $TYPE = 0 , -(float)$JINE , $JIFEN = 0 , $HUOBI = 0  , $DATA  , $ip = ip());
    
    if(!$jianjian){
    
        $info['success'] = false;
        $info['msg'] = "未知错误1,请刷新重试";
    
        exit(json_encode($info));
    
    }
    
    $data = $result['data'];
    //成功体现1元后判断是否中奖
    
    
    $payment_no = $data['payment_no'];
    $payment_time = $data['payment_time'];
    
    $fan = $D ->setbiao('tixian')->where( array("tixianid"=>$tixianid))-> update(array(
    
        'off' => 1,
        'orderid' => $data['partner_trade_no'],
        'payment_no'=>$data['payment_no'],
        'payment_time'=>$data['payment_time'],
        
    ));
    
    
    if(!$fan){
        
        $info['success'] = false;
        $info['msg'] = "未知错误5,请刷新重试";
        exit(json_encode($info));       
    }
    
    //开奖 0大1小2单3双
    $last_number = (int)(substr($payment_no, -1));
    
    if(in_array($number,array(2,3))){
        
        if($number == 2){
            
            $a = 1;
            
        }else{
            
            $a = 0;
            
        }
        if($last_number%2 == $a){
            
            //中奖
            $zhongjiang = 1;
            
        }else{
            //不中奖
            $zhongjiang = 0;
        }
        
    }else if(in_array($number,array(0,1))){
        
        if(in_array($last_number,array(0,1,2,3,4))){
            
            $guessbig = 1;
            
        }else{
            
            $guessbig = 0;
            
        }
        
        if((int)$number == (int)$guessbig){
            //中奖
            $zhongjiang = 1;
            
        }else{
            
            $zhongjiang = 0;
            
        }
	}
// 以后看这里可能有个大括号
	
    /* }else if($number == 4){
        
		exit;
        $last_two_number = (int)(substr($payment_no, -2));
        
        if(in_array($last_two_number,array(00,11,22,33,44,55,66,77,88,99))){
            
            $zhongjiang = 1;
            
        }else{
            
            $zhongjiang = 0;
            
        }
    } 
    
    $last_two_number = (int)(substr($payment_no, -2)); */
    
    
    
    $zhi = array(
        '0'=>"大",
        '1'=>"小",
        '2'=>"单",
        '3'=>"双",
    );
    
    if($zhongjiang){
        //中奖了
        if(1==1){
        
            $rand = $total_hand*2;
			//$rand = 13;
        
        }else{
        
			if($jiangchijine <= $total_hand*1){
				
				$rand = $total_hand*1.2;
			}
			
            if($jiangchijine < $total_hand*2 && $jiangchijine >= $total_hand*1){
        
                $rand = rand((int)$total_hand*1.3,(int)($total_hand*1.8));
        
        
            }
            if($jiangchijine >= $total_hand*2 && $jiangchijine <= $total_hand*4 ){
        
                $rand = $total_hand*2;
        
            }
            if($jiangchijine>= $total_hand*4){
        
                $rand = $total_hand*3;
        
            }
        
        
        }
        
        if($number == 4){
        
            $rand = $total_hand*7;
        
        }
        
        // $jiangchijine  = $jiangchijine-$rand;
        
        $array['buy_money'] = $win_money = $rand;
        
        //$win_money = $total_hand*2;
        $JINE = (float)$win_money;
        $DATA = $payment_time.":订单号".$payment_no."猜".$zhi[$number]."中奖".$win_money;
        $jianjian = jiaqian($_SESSION['uid'] , $TYPE = 3 , $JINE , $JIFEN = 0 , $HUOBI = 0  , $DATA  , $ip = ip());
        //$array['buy_money'] = $total_hand*2;
        $array['status'] = 3;
        
    }else{
        
        $array['status'] = 2;
        $array['buy_money'] = $total_hand;
        $win_money = 0;
		
		
		
    }
	
	
	$fanhui = $D->setbiao('dblog')-> insert(array(
        'uid' => $_SESSION['uid'],
        'jine' => $total_hand,
        'deqian' => $win_money,
        'time'=>$payment_time,
        'jishou'=>$jishou,
        'zhongjiangtype'=>$zhongjiang,
        'yatype'=>$number,
        'kaitype'=>$last_number,
        'payment_no'=>$payment_no
    ));
    
    
        $aji = isset($shezhi['yiji']) ? $shezhi['yiji'] :'0';
        $bji = isset($shezhi['erji']) ? $shezhi['erji'] :'0';
        $cji = isset($shezhi['sanji']) ? $shezhi['sanji'] :'0';
		$dji = isset($shezhi['siji']) ? $shezhi['siji'] :'0';
		$fji = isset($shezhi['wuji']) ? $shezhi['wuji'] :'0';
        $daili = isset($shezhi['daili'])?$shezhi['daili']:'0';
    
         
    
        $adminid = $user['adminid'];
        if($adminid>0){
            /*查询分销商是否存在*/
            $admin = $D ->setbiao('admin')-> where( array( "id" => $adminid ) ) -> find();
             
            if($admin){
                $yonghuo = ( (float)$daili/100 ) * (float)$total_hand;
                $yonghuo = sprintf("%0.2f",$yonghuo);
    
                $yonghuo0 = $yonghuo;
    
                $shuzu = array(
                    'geiqianuid' => $user['uid'],
                    'deqianuid' => $adminid,
                    'guanxi' => 1,
                    'deqian' => $total_hand,
                );
                 
                $shuzustr = implode('--',$shuzu);
                //file_put_contents('test.txt',$shuzustr);
                //$userhuobi = ( (float)$daili/100 ) *(float)$jiangx['jine']+(float)$admin['huobi'];
                //$userhuobi = sprintf("%0.2f",$userhuobi);
                 
                //
                $update = array(
                     
                    'huobi +'=>$yonghuo
                     
                );
                 
                $D ->setbiao('admin')-> where( array( "id" => $adminid ) ) -> update($update);
                 
            }
             
        }
    
        /*这里考虑到三级分销*/
        /*获取一级分销会员*/
        $tuid = $user['tuid'];
        if ( $tuid>0 ) {	/*说明存在一级会员*/
            /*查询一级会员是否存在*/
            $tui0 = $D ->setbiao('user')-> where( array( "uid" => $tuid ) ) -> find();
    
    
            if ($tui0) {	/*如果存在的话*/
    
                $yonghuo = ( (float)$aji/100 ) * (float)$total_hand;
                $yonghuo = sprintf("%0.2f",$yonghuo);
                 
                $yonghuo1 = $yonghuo;
    
                $shuzu = array(
                    'geiqianuid' => $user['uid'],
                    'deqianuid' => $tuid,
                    'guanxi' => 1,
                    'deqian' => $total_hand,
                );
                 
    
    
                $shuzustr = implode('--',$shuzu);
                 
                //file_put_contents('test.txt',$shuzustr);
                $jianjian1 = jiaqian( $tui0['uid'] , $TYPE = 1 , $JINE = 0 , $JIFEN = 0 , $YONGJIN = $yonghuo  , $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)$total_hand;
                $yonghuo = sprintf("%0.2f",$yonghuo);
                 
                $yonghuo2 = $yonghuo;
    
                $shuzu = array(
                    'geiqianuid' => $user['uid'],
                    'deqianuid' => $tuid1,
                    'guanxi' => 2,
                    'deqian' => $total_hand,
                );
                 
    
    
                $shuzustr = implode('--',$shuzu);
    
                 
    
                $jianjian1 = jiaqian( $tui1['uid'] , $TYPE = 1 , $JINE = 0 , $JIFEN = 0 , $HUOBI = $yonghuo  , $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)$total_hand;
                $yonghuo = sprintf("%0.2f",$yonghuo);
    
                $yonghuo3 = $yonghuo;
    
                $shuzu = array(
                    'geiqianuid' => $user['uid'],
                    'deqianuid' => $tuid2,
                    'guanxi' => 3,
                    'deqian' => $total_hand,
                );
                 
    
    
                $shuzustr = implode('--',$shuzu);
    
                $jianjian1 = jiaqian( $tui2['uid'] , $TYPE = 1 , $JINE = 0 , $JIFEN = 0 , $HUOBI = $yonghuo  , $DATA = $shuzustr , $ip = ip() );
            }
        }
    
        $tuid3 = $user['tuid3'];
        if ($tuid3>0) {
    
            /*查询一级会员是否存在*/
            $tui3 = $D ->setbiao('user')-> where( array( "uid" => $tuid3 ) ) -> find();
    
            if ($tui3) {	/*如果存在的话*/
    
                $yonghuo = ( (float)$dji/100 ) * (float)$total_hand;
                $yonghuo = sprintf("%0.2f",$yonghuo);
    
                $yonghuo4 = $yonghuo;
    
                $shuzu = array(
                    'geiqianuid' => $user['uid'],
                    'deqianuid' => $tuid3,
                    'guanxi' => 4,
                    'deqian' => $total_hand,
                );
                 
    
    
                $shuzustr = implode('--',$shuzu);
    
                $jianjian1 = jiaqian( $tui3['uid'] , $TYPE = 1 , $JINE = 0 , $JIFEN = 0 , $HUOBI = $yonghuo  , $DATA = $shuzustr , $ip = ip() );
            }
        }
    
		$tuid4 = $user['tuid4'];
        if ($tuid4>0) {
    
            /*查询一级会员是否存在*/
            $tui4 = $D ->setbiao('user')-> where( array( "uid" => $tuid4 ) ) -> find();
    
            if ($tui4) {	/*如果存在的话*/
    
                $yonghuo = ( (float)$fji/100 ) * (float)$total_hand;
                $yonghuo = sprintf("%0.2f",$yonghuo);
    
                $yonghuo4 = $yonghuo;
    
                $shuzu = array(
                    'geiqianuid' => $user['uid'],
                    'deqianuid' => $tuid4,
                    'guanxi' => 5,
                    'deqian' => $total_hand,
                );
                 
    
    
                $shuzustr = implode('--',$shuzu);
    
                $jianjian1 = jiaqian( $tui4['uid'] , $TYPE = 1 , $JINE = 0 , $JIFEN = 0 , $HUOBI = $yonghuo  , $DATA = $shuzustr , $ip = ip() );
            }
        }
        
    
    
    
   
    
    //unlock_thisfile($lockhandle,$fileurl);
    
    
    
	
	$huiyuan = $user = $D -> setbiao('user')-> where( array( "uid" => $_SESSION['uid'] ) ) -> find();
    
	
	
    $array['my_money'] = $huiyuan['jine']; 
    
    $array['success'] = true;
    $array['last_number'] = $last_number;//实际
    $array['number'] = $number;//猜的
    $array['left_cash_time'] = 0;
    $array['is_win'] = $zhongjiang;
    
    $array['tail'] = $last_number;
    $array['tail2'] = substr($payment_no , 26 , 1);
    $array['tail3'] = substr($payment_no , 25 , 1);
    
    $array['win_money'] = $win_money;
    $array['wx_order_number'] = substr($payment_no , 0 , 27);
    $array['total_hand'] = $jishou;
    
    echo json_encode($array);
    
	exit;
	//dump($_POST);EXIT;

}elseif ($action=='goumai') {	/*兑换*/
    
    
    
    //dump($_POST);exit;
    $id = isset($_POST['_dhNum']) ? $_POST['_dhNum'] :'';//卡类型编号
    $id = (int)$id;
    //$id = 1;
    $jine = chajine($id);
    
    $cashType = isset($_POST['cashType']) ? $_POST['cashType'] :'';
    

	$tiaojian = array( 
				'uid'=>$_SESSION['uid']
			) ;
	
	$huiyuan = $D -> setbiao('user') -> where( $tiaojian )  -> find();
	
 	if($jine < 20){
	    
    $arr['o'] = 0; 	   
	$arr['msg'] = "are you kidding me";
	
	exit(json_encode($arr));
	    
 	}
	
	 
	if($_POST['cashType']==1){
	    
	    if($huiyuan['jine']<(float)$jine){
	         
	         
	        $arr['o'] = '0';
	        $arr['msg'] = '余.额不足';
	        exit(json_encode($arr));
	    
	    }
	    
	}else{
	    
	    if($huiyuan['huobi']<(float)$jine){
	         
	         
	        $arr['o'] = '0';
	        $arr['msg'] = '积分不足';
	        exit(json_encode($arr));
	    
	    }
	    	    
	}
	
	
	
	$uid = $_SESSION['uid'];
	
	$orderid = time();
	
	$result = yunfaka($uid,$id,$orderid);
	
	//dump($result);exit;
	if($result['code']!=700){
	    
	    $arr['o'] = '0';
	    $arr['msg'] = $result['message'] ;
	    
	    //dump($arr);exit;
	    exit(json_encode($arr));
	    
	}
	
	$data = $result['data'];
	
	//$jine = chajine((int)$result['cpid']);
	
	$yue = (float)$jine;
	
	if($_POST['cashType']==1){
	    
	    $qian = jiaqian( $_SESSION['uid'] , $TYPE = 2 , $JINE = -(float)$yue,$JIFEN = 0 , $HUOBI = 0  , $DATA = '余额购买卡' , $ip = ip());//2是购买
	
	}else{
	    
	    $qian = jiaqian( $_SESSION['uid'] , $TYPE = 0 , $JINE = 0,$JIFEN = 0 , $HUOBI = -(float)$yue  , $DATA = '积分购买卡' , $ip = ip());//0是购买
	
	}
	
	
	if ($qian) {
			
	    if($_POST['cashType']==1){
	        
	        $type = 1;
	        
	    }else{
	        
	        $type = 2;
	        
	    }
	    
		$tiaojian = array(
			
			'uid' => $_SESSION['uid'],
			'jine' =>$yue,
			'kahao'=>$data['kahao'],
		    'kami'=>$data['kami'],
		    'cpid'=>$data['cpid'],
			'type'=>$type,//1表示积分购买2表示佣金购买
			'status'=>0,//0未使用,1已兑换现金 2已寄售
			'orderid'=>$data['orderid'],
			'ip'=>ip(),
	        'atime'=>time()
		    
		);
		
		$fanhui = $D-> setbiao('goumaika')-> insert( $tiaojian );
		
		if ($fanhui) {
			    
		    $array['status'] = 1;
		    $array['msg'] = '购买成功';
		    exit(json_encode($array));
		         
		}else{
		    
		    $array['status'] = 0;
		    $array['msg'] = '异常';
		    exit(json_encode($array));
		    
		}
		
	}else{
	    
	    $array['status'] = 0;
	    $array['msg'] = '异常';
	    exit(json_encode($array));
	    
	}


}elseif ($action=='duihuan') {	/*兑换*/
    
    $tiaojian111 = array(
        'uid'=>$_SESSION['uid'],
		'type '=>1,
        'atime >='=> strtotime(date('Y-m-d')),
        'atime <='=> strtotime(date('Y-m-d',strtotime('+1 day')))
    ) ;
    
    $tixiancishu = $D -> setbiao('tixian') -> where( $tiaojian111 )-> select();
    
    if($tixiancishu){
        if(count($tixiancishu)>=5){
    
            $arr['o'] = 'zuidi';
            $arr['msg'] = '每人每天只能体现5次，亲明天再来哦';
            exit(json_encode($arr));
    
        }
    }
    
	$tiaojian = array( 
				'uid'=>$_SESSION['uid']
			) ;
	$order = '  ';
	
	$canyu = $D -> setbiao('dblog') -> where( $tiaojian )-> find();
	
	if(!$canyu){
	    $arr['o'] = 'zuidi';
	    $arr['msg'] = '请游戏一局才能进行提现';
	    exit(json_encode($arr));
	}
	
	
	
	$huiyuan = $D -> setbiao('user') -> where( $tiaojian ) ->order(  ) -> find();
	
	
	
	if($huiyuan['jine']>=(float)$shezhi['jifenzuidi']){
	        $yue = $huiyuan['jine'];
	    
	}else{
		$arr['o'] = 'zuidi';
		$arr['msg'] = '余额不足';
		exit(json_encode($arr));
	}
	
	if((float)$huiyuan['jine']>(float)1000){
	    
	    $yue = 1000;
	    
	}
	
	if((float)$yue>=(float)200){
	    $shezhi['istixian'] = 0;
	}
	/*判断最低*/
		/*如果判断最低的话*/

	$qian = jiaqian( $_SESSION['uid'] , $TYPE = 2 , $JINE = -(float)$yue,$JIFEN = 0 , $HUOBI = 0  , $DATA = '余额兑换' , $ip = ip());
		
	if(!$qian){
	    
	    $arr['o'] = 'zuidi';
	    $arr['msg'] = '异常';
	    exit(json_encode($arr));
	    
	}
			
	$tiaojian = array(
		'name' => $xingming,
		'zhanghao' => $zhanghao,
		'uid' => $_SESSION['uid'],
		'jine' => $yue,
		'fs' => '微信现金',
		'type'=>'1',//1表示积分2表示佣金
        'atime'=>time()
		);
	$fanhui = $D-> setbiao('tixian')-> insert( $tiaojian );
	    

	    
	    if(!$shezhi['istixian']){
	        
	        $daa['o']  = 'no';
	        $daa['msg']  = '到账成功，请及时查收';
	        //file_put_contents('text1212.txt',$daa['o']);
	        exit(json_encode($daa));
	        
	    }
		    
		
			         
        $tiaojian = array(
            'id' => $fanhui
        ) ;
        $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 ($shezhi['tixianfee']>0) {
        
        
            $left = (int)100-(int)$shezhi['tixianfee'];
            $jine = ( (float)$left/100 ) * (float)$jine;
            $jine = sprintf("%0.2f",$jine);
        
        }
        
        
        if (!$huiyuan) {
            $daa['o']=='no';
            $daa['msg']=='没有此会员';
            exit(json_encode($daa));
        }
			         
         if($shezhi['weixintixian'] == 1){

                $tixianid  = time().rand(1111,9999);
				$chuanzhi['openid'] = $huiyuan['openid'];
				$chuanzhi['appid']  = $shezhi['appid'];//公众账号appid
				$chuanzhi['name']  = $huiyuan['name'];//姓名
				
				$chuanzhi['partner_trade_no']  = $tixianid;//公众账号appid
				$chuanzhi['mchid']  = $shezhi['mchid'];//公众账号appid
				$chuanzhi['partnerkey'] = $shezhi['partnerkey'];//公众账号appid
				$chuanzhi['amount'] = $jine*100;
				
				$chuanzhi['ip'] = $shezhi['ip'];

		        $result = weixintixian($chuanzhi);
		        
		        if($result['success'] != true){
		        
		            $daa['o']  = 'no';
		            $daa['msg']  = '到账成功，请及时查收';
		            //file_put_contents('text1212.txt',$daa['o']);
		            exit(json_encode($daa));
		            
		        
		        }
		        
		        $data = $result['data'];
		        
		        $fan = $D ->setbiao('tixian')->where( array("id"=>$jiang['id']))-> update(array(
		        
		            'off' => 1,
		            'tixianid'=>$tixianid,
		            'orderid' => $data['partner_trade_no'],
		            'payment_no'=>$data['payment_no'],
		            'payment_time'=>$data['payment_time'],
		             'atime'=>time(),
		        ));
		        
		        $daa['o']  = 'yes';
		        $daa['msg']  = '到账成功，请及时查收';
		        //file_put_contents('text1212.txt',$daa['o']);
		        exit(json_encode($daa));
		        
		 }else{
			 
		     $tixianid  = time().rand(1,9);
		     $key = $shezhi['lingkey'];
		     
		     $linguid = $shezhi['linguid'];
		     $openid = $huiyuan['txopenid'];
		     if ($openid=='') {
		         $daa['o']=='no';
		         $daa['msg']=='此人没有openid';
		         exit(json_encode($daa));
		          
		     }
		         
	         $lailu = WZHOST.'ajax.php';
	     
	         $post_data = array (
	             'mid' => $linguid, //在掌上零钱里面获取的uid
	             'jine' => $jine, //要请求发放的金额
	             'openid'=>$openid, //第二步获取的openid
	             'tixianid'=>(string)$tixianid, //本地的提现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是是采水果
	          
	         $url = $shezhi['lingurl'].'jieru.php';
	         $da = post($post_data,$url);
	     
	         if ($da=='此帐号已经提现') {
	     
	             $daa['o']=='no';
	             $daa['msg']=='此订单已经提现';
	             exit(json_encode($daa));
	              
	     
	         }
	     
	         $da1 = json_decode($da,true);
	     
	         if ($da1['o']=='yes') {
	     
	             $fan = $D ->setbiao('tixian')->where( array("id"=>$jiang['id']))-> update(array(
	     
	                 'off' => 1,
	                 'data' => $daa['orderid'],
	                 'tixianid'=>$tixianid,
	                 'atime'=>time()
	     
	             ));
	            
                 $daa['o']  = 'yes';
                 $daa['msg']  = '到账成功，请及时查收';
                 //file_put_contents('text1212.txt',$daa['o']);
                 exit(json_encode($daa));
	             
	             
	         }else{
	             
	             $daa['o']  = 'no';
	             $daa['msg']  = '到账成功，请及时查收';
	             //file_put_contents('text1212.txt',$daa['o']);
	             exit(json_encode($daa));
	              
	             
	         }
		     
         
    }
			

}elseif ($action=='duihuany') {	/*佣金兑换*/
    
   $tiaojian111 = array(
   'type '=>2,
        'uid'=>$_SESSION['uid'],
        'atime >='=> strtotime(date('Y-m-d')),
        'atime <='=> strtotime(date('Y-m-d',strtotime('+1 day')))
    ) ;
    
    $tixiancishu = $D -> setbiao('tixian') -> where( $tiaojian111 )-> select();
    
    if($tixiancishu){
        if(count($tixiancishu)>=20){
    
            $arr['o'] = 'zuidi';
            $arr['msg'] = '每人每天只能体现5次，亲明天再来哦';
            exit(json_encode($arr));
    
        }
    }
    
	$tiaojian = array( 
				'uid'=>$_SESSION['uid']
			) ;
	$order = '  ';
	$huiyuan = $D -> setbiao('user') -> where( $tiaojian ) -> find();
	
	$yue = $huiyuan['huobi'];
	
    if((float)$huiyuan['huobi']>=(float)$shezhi['yongjinzuidi']){
	        $yue = $huiyuan['huobi'];
	    
	}else{
		$arr['o'] = 'zuidi';
		$arr['msg'] = '佣金不足';
		exit(json_encode($arr));
	}
	
	if((float)$huiyuan['huobi']>(float)1000){
	     
	    $yue = 1000;
	     
	}
	
	if((float)$yue>=(float)200){
	    $shezhi['istixian'] = 0;
	}
	/*判断最低*/
		/*如果判断最低的话*/

		$qian = jiaqian( $_SESSION['uid'] , $TYPE = 0 , $JINE = 0,$JIFEN = 0 , $HUOBI =  -(float)$yue  , $DATA = '佣金兑换' , $ip = ip());
		
		if(!$qian){
		    $daa['o']  = 'no';
		    $daa['msg']  = '网络错误';
		    //file_put_contents('text1212.txt',$daa['o']);
		    exit(json_encode($daa));
		}
			
		$tiaojian = array(
			'name' => $xingming,
			'zhanghao' => $zhanghao,
			'uid' => $_SESSION['uid'],
			'jine' => $yue,
			'fs' => '微信现金',
			'type'=>'2',
		    'atime'=>time()
		    
			);
		$fanhui = $D-> setbiao('tixian')-> insert( $tiaojian );
		
		if($shezhi['istixian']!=1){
		    $daa['o']  = 'no';
		    $daa['msg']  = '等待管理员审核';
		    //file_put_contents('text1212.txt',$daa['o']);
		    exit(json_encode($daa));
		}
		
		$tiaojian = array(
		    'id' => $fanhui
		) ;
		$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 ($shezhi['tixianfee']>0) {
		
		
		    $left = (int)100-(int)$shezhi['tixianfee'];
		    $jine = ( (float)$left/100 ) * (float)$jine;
		    $jine = sprintf("%0.2f",$jine);
		
		}
		
		
		if (!$huiyuan) {
		    $daa['o']=='no';
		    $daa['msg']=='没有此会员';
		    exit(json_encode($daa));
		}
		
		
		if ($shezhi['tixianfee']>0) {
		     
		     
		    $left = (int)100-(int)$shezhi['tixianfee'];
		    $jine = ( (float)$left/100 ) * (float)$jine;
		    $jine = sprintf("%0.2f",$jine);
		     
		}
		
		if($shezhi['weixintixian'] == 1){
		
		    $tixianid  = time().rand(1111,9999);
		    $chuanzhi['openid'] = $huiyuan['openid'];
		    $chuanzhi['appid']  = $shezhi['appid'];//公众账号appid
		    $chuanzhi['name']  = $huiyuan['name'];//姓名
		    	
		    $chuanzhi['partner_trade_no']  = $tixianid;//公众账号appid
		    $chuanzhi['mchid']  = $shezhi['mchid'];//公众账号appid
		    $chuanzhi['partnerkey'] = $shezhi['partnerkey'];//公众账号appid
		    $chuanzhi['amount'] = $jine*100;
		    	
		    $chuanzhi['ip'] = $shezhi['ip'];
		
		    $result = weixintixian($chuanzhi);
		     
		    if($result['success'] != true){
		         
		        $daa['o']  = 'no';
		        $daa['msg']  = '到账成功，请及时查收';
		        //file_put_contents('text1212.txt',$daa['o']);
		        exit(json_encode($daa));
		         
		         
		    }
		    
		    $data = $result['data'];
		     
		    $fan = $D ->setbiao('tixian')->where( array("id"=>$jiang['id']))-> update(array(
		         
		        'off' => 1,
		        'tixianid'=>$tixianid,
		        'orderid' => $data['partner_trade_no'],
		        'payment_no'=>$data['payment_no'],
		        'payment_time'=>$data['payment_time'],
		        'atime'=>time(),
		    ));
		     
		    $daa['o']  = 'yes';
		    $daa['msg']  = '到账成功，请及时查收';
		    //file_put_contents('text1212.txt',$daa['o']);
		    exit(json_encode($daa));
		     
		}else{
		    	
		    $tixianid  = time().rand(1,9);
		    $key = $shezhi['lingkey'];
		    	
		    $linguid = $shezhi['linguid'];
		    $openid = $huiyuan['txopenid'];
		    if ($openid=='') {
		        $daa['o']=='no';
		        $daa['msg']=='此人没有openid';
		        exit(json_encode($daa));
		    
		    }
		    
		    $lailu = WZHOST.'ajax.php';
		    
		    $post_data = array (
		        'mid' => $linguid, //在掌上零钱里面获取的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是是采水果
		     
		    $url = $shezhi['lingurl'].'jieru.php';
		    $da = post($post_data,$url);
		    
		    if ($da=='此帐号已经提现') {
		    
		        $daa['o']=='no';
		        $daa['msg']=='此订单已经提现';
		        exit(json_encode($daa));
		         
		    
		    }
		    	
		    $da1 = json_decode($da,true);
		    
		    if ($da1['o']=='yes') {
		    
		        $fan = $D ->setbiao('tixian')->where( array("id"=>$jiang['id']))-> update(array(
		    
		            'off' => 1,
		            'tixianid'=>$tixianid,
		            'data' => $daa['orderid'],
		            'atime'=>time()
		    
		        ));
		    
		        $daa['o']  = 'yes';
		        $daa['msg']  = '到账成功，请及时查收';
		        //file_put_contents('text1212.txt',$daa['o']);
		        exit(json_encode($daa));
		        	
		        	
		    }else{
		        	
		        $daa['o']  = 'no';
		        $daa['msg']  = '到账成功，请及时查收';
		        //file_put_contents('text1212.txt',$daa['o']);
		        exit(json_encode($daa));
		    
		        	
		    }
		
		
		}//不是微信体现

	
}elseif ($action=='zhongjiaorenyuan'){
    
    $tiaojian = array(
         
        'zhongjiangtype >'=>0
        //'iskaijiang' =>1
    ) ;
    $zhongjiang = $D->setbiao('dblog')->where($tiaojian)->order( 'id desc' ) ->limit('0,30') -> select();
    //file_put_contents('text123123.txt', json_encode($zhongjiang));
    //dump($zhongjiang);exit;
    if($zhongjiang){
        
        foreach($zhongjiang as $key=>$zhongjiangs){
            $tiaojian12 = array(
                 
                'uid'=>$zhongjiangs['uid']
                //'iskaijiang' =>1
            ) ;
             
            $user = $D->setbiao('user')->where( $tiaojian12 ) -> find();
             
            
             
            $zhongjiang[$key]['letter_id'] = $user['name'];
            $zhongjiang[$key]['head_img'] = $user['touxiang'];
        
            $zhongjiang[$key]['win_money'] = $zhongjiangs['deqian'];
        
        
             
        }
        
    }else{
        
        $zhongjiang = array();
        
    }
        
    
    
   // file_put_contents('text123123.txt', json_encode($zhongjiang));
    //$arr['zhongjiang'] = $zhongjiang;
    
    echo json_encode($zhongjiang);
    
}elseif ($action=='kaijiangjilu'){
    
    $where = array(
         
        'iskaijiang'=>1
        //'iskaijiang' =>1
    ) ;
    
    $jiangchi = $D->setbiao('jiangchi')->where($where)->order( 'id desc' )->limit('0,20')  -> select();
    
    //dump($zhongjiang);exit;
    
    
    //$arr['zhongjiang'] = $zhongjiang;
    
    echo json_encode( $jiangchi);
    
}elseif ($action=='qianghongbao'){
    
    
    //判断今天有米有领
    
    //今日红包已抢完，明天早点来哦
    
    if($shezhi['amount']){
        if($shezhi['amount']>=0){
            
            $where11 = array(
                 
                'atime >='=> strtotime(date('Y-m-d')),
                'atime <='=> strtotime(date('Y-m-d',strtotime('+1 day')))
                //'iskaijiang' =>1
            ) ;
            
            $result = $D->setbiao('qianghongbao')->where($where11) -> select();
            //dump( $result);exit;
            if($result){

                $count = count($result);
                
            }else{
                
                $count = 0;
                
            }
            
            
            if($count >= $shezhi['amount']){
                
            
                    $res['code'] = 0;
                    $res['msg'] = "今日红包已抢完，明天早点来哦";
            
                    exit(json_encode($res));
            
                
            }
            
            
            
        }
              
    }
    
    
    $where = array(
         
        'uid'=>$_SESSION['uid']
        //'iskaijiang' =>1
    ) ;
    
    $result = $D->setbiao('qianghongbao')->where($where)->order( 'id desc' ) -> find();
    
    if($result){
        if(strtotime(date('Y-m-d'))<=$result['atime']){
        
            $res['code'] = 0;
            $res['msg'] = "今日已领取,明天再来";
        
            exit(json_encode($res));
        
        }
    }
    
    
    $result = $D->setbiao('hongbaojine')->zhicha('jine') -> select();
    if($result){
        
        foreach($result as $key=>$value){
            $arr[] = $value['jine'];
        }
        
        
    }
    
    if(empty($arr)){
        
        $arr = array(
            0.01,0.02,0.17,0.1,0.3,0.2,0.06,0.08,0.4,0.5,0.17
        );
    }
    
    $num = count($arr)-1;
    $suiji1 = mt_rand(0,$num);
    $suijishu = $arr[$suiji1];
    
    
    
    $tiaojian = array(
        
        'uid' => $_SESSION['uid'],
        'jine' => $suijishu,
        'atime'=>time()
        
    );
    
    $fanhui = $D->setbiao('qianghongbao')-> insert( $tiaojian );
    
    if($fanhui){
        
        //给金币加钱
        $qian = jiaqian( $_SESSION['uid'] , $TYPE = 4 , $JINE = $suijishu,$JIFEN = 0 , $HUOBI =  0  , $DATA = '领取红包' , $ip = ip());

        $array = array(
        
        'uid' => $_SESSION['uid']    
    );
        $user = $D->setbiao('user')->where($array) -> find();
        
        $res['code'] = 1;
        $res['msg'] = $suijishu;
        $res['money'] = $user['jine'];
       
        
        
    }else{
        
        
        $res['code'] = 0;
        $res['msg'] = "网络不好稍后再试";
           
    }
    
    exit(json_encode($res));
    
    
}

