<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

function game_sw( )
{
		global $db;
		global $web_dbtop;
		global $reg_points;
		$query = $db->query( "Select id,vipdate from {$web_dbtop}users where vip=1 and vipdate<'".date( "Y-m-d" )."' Order by id desc" );
		while ( $rs = $db->fetch_array( $query ) )
		{
				$db->query( "INSERT INTO {$web_dbtop}msg (usersid,title,mag,mid,time) VALUES (0,'VIP到期通知','您的VIP会员已于".date( "Y-m-d" )."到期,请您续费。',".$rs['id'].",'".date( "Y-m-d H:i:s" )."')" );
				$db->query( "update {$web_dbtop}users set vip=0 where id=".$rs['id'] );
		}
		$db->query( "insert into {$web_dbtop}webtj (time) values ('".date( "Y-m-d" )."')" );
		$reg_num = 0;
		$reg_num = $db->result_first( "select count(id) from ".$web_dbtop."users where STR_TO_DATE(time,'%Y-%m-%d')='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
		$adw_num = 0;
		$adw_num = $db->result_first( "select points from ".$web_dbtop."adtj where type=3 and STR_TO_DATE(time,'%Y-%m-%d')='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
		$ads_num = 0;
		$ads_num = $db->result_first( "select points from ".$web_dbtop."adtj where type=2 and STR_TO_DATE(time,'%Y-%m-%d')='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
		$ada_num = 0;
		$ada_num = $db->result_first( "select points from ".$web_dbtop."adtj where type=1 and STR_TO_DATE(time,'%Y-%m-%d')='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
		$users_num = 0;
		$users_num = $db->result_first( "Select (sum(points)+sum(back)) as points from {$web_dbtop}users" );
		$db->query( "update {$web_dbtop}webtj set regnum={$reg_num},regpoints=".$reg_num * $reg_points.",adquestionspoints=".intval( $adw_num ).",adcpapoints=".intval( $ads_num ).",adcpspoints=".intval( $ada_num ).",userspoints=".intval( $users_num )." where time='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
		$db->query( "update {$web_dbtop}users set dailygame16experience=0,dailygame28experience=0,dailydodgeexperience=0,dailygame11experience=0 where dailygame16experience!=0 or dailydodgeexperience!=0 or dailygame28experience!=0 or dailygame11experience!=0" );
		$tjarray = array(
				array( 60, 120, 350, 560, 2800 ),
				array( 200, 1000, 2400, 3500, 10000 ),
				array( 1, 2, 3, 4, 5 )
		);
		$query = $db->query( "Select id,tjid,time,authentication,tgreglq,maxexperience from {$web_dbtop}users where tjid!=0 and tgreglq<5 and maxexperience>=60 Order by id desc" );
		while ( $rs = $db->fetch_array( $query ) )
		{
				$z = 0;
				for ( ;	$z < count( $tjarray[0] );	++$z	)
				{
						if ( $tjarray[0][$z] <= $rs['maxexperience'] && $rs['tgreglq'] < intval( $tjarray[2][$z] ) )
						{
								if ( 0 < $z )
								{
										if ( $rs['authentication'] == 1 )
										{
												$db->query( "update {$web_dbtop}users set tgreglq=".$tjarray[2][$z]." where id =".$rs['id'] );
												$db->query( "update {$web_dbtop}users set points=points+".intval( $tjarray[1][$z] )." where id =".$rs['tjid'] );
												$db->query( "update {$web_dbtop}game_log set xx_hd=xx_hd+".intval( $tjarray[1][$z] )." where uid=".$rs['tjid'] );
												$db->query( "insert into {$web_dbtop}tjlog (uid,xid,type,regtime,points,time) values (".$rs['tjid'].",".$rs['id'].",'注册推荐','".date( "Y-m-d", strtotime( $rs['time'] ) )."',".$tjarray[1][$z].",'".date( "Y-m-d" )."')" );
												$db->query( "update {$web_dbtop}webtj set tgpoints=tgpoints+".intval( $tjarray[1][$z] )." where time='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
										}
								}
								else
								{
										$db->query( "update {$web_dbtop}users set tgreglq=".$tjarray[2][$z]." where id =".$rs['id'] );
										$db->query( "update {$web_dbtop}users set points=points+".intval( $tjarray[1][$z] )." where id =".$rs['tjid'] );
										$db->query( "update {$web_dbtop}game_log set xx_hd=xx_hd+".intval( $tjarray[1][$z] )." where uid=".$rs['tjid'] );
										$db->query( "insert into {$web_dbtop}tjlog (uid,xid,type,regtime,points,time) values (".$rs['tjid'].",".$rs['id'].",'注册推荐','".date( "Y-m-d", strtotime( $rs['time'] ) )."',".$tjarray[1][$z].",'".date( "Y-m-d" )."')" );
										$db->query( "update {$web_dbtop}webtj set tgpoints=tgpoints+".intval( $tjarray[1][$z] )." where time='".date( "Y-m-" ).( date( "d" ) - 1 )."'" );
								}
						}
				}
		}
		unset( $tjarray );
}

error_reporting( 0 );
set_time_limit( 0 );
include_once( "../inc/conn.php" );
include_once( "../inc/function.php" );
if ( $_GET['key'] == "KG_sw" )
{
		game_sw( );
		echo "000\r\n"; 
		echo date( "Y-m-d H:i:00", time( ) + 60 );
		
}
?>
