Server : Apache
System : Linux iZ2vcgyutqttsd1p850kl8Z 3.10.0-1160.92.1.el7.x86_64 #1 SMP Tue Jun 20 11:48:01 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 5.6.40
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/saimikebio.com/wechat/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/saimikebio.com/wechat/prize_data.php
<?php
define('IN_ECS', true);
error_reporting(0);
require(dirname(__FILE__) . '/../includes/init.php');
$pid = $_GET['pid'];
$sql = "SELECT * FROM ". $GLOBALS['ecs']->table('weixin_prize_append') ." WHERE `prize_id` = '$pid'";
$prize_arr = $db->getAll($sql);
foreach ($prize_arr as $key => $val) 
{
	if(empty($val['prize_value'])) 
	{
		unset($prize_arr[$key]);
	}
}
$temp_count = count($prize_arr) -1;
foreach($prize_arr as $k => $v) 
{
	$ck_cnum = $db->getOne("SELECT `pid` FROM ". $GLOBALS['ecs']->table('weixin_prize_cnum') ." WHERE `pid` = '$v[prize_id]' ");
	if ($temp_count == $k) 
	{
		if (empty($ck_cnum)) 
		{
			$insert_sql = "INSERT INTO ". $GLOBALS['ecs']->table('weixin_prize_cnum') ." (`paid`, `pid`, `prize_name`, `prize_value` , `user_count`) VALUES ('$v[id]', '$v[prize_id]', '$v[prize_name]', '$v[prize_value]' ,'1');";
		}
		else 
		{
			$insert_sql = "UPDATE ". $GLOBALS['ecs']->table('weixin_prize_cnum') ." SET `user_count` = `user_count` +1 WHERE `paid` ='$v[id]';";
		}
		$prize_arr[$k]['state'] = 'no';
	}
	else 
	{
		$prize_arr[$k]['state'] = 'yes';
	}
	if ($insert_sql) 
	{
		$db->query($insert_sql);
	}
	$ck_prize_num = $db->getOne("SELECT `user_count` FROM ". $GLOBALS['ecs']->table('weixin_prize_cnum') ." WHERE `paid` = '$v[id]'");
	if ($ck_prize_num >= $v['prize_value']) 
	{
		if($prize_arr[$k]['state'] == 'yes') 
		{
			unset($prize_arr[$k]);
		}
	}
}
foreach ($prize_arr as $key => $val) 
{
	if(!empty($val['prize_value'])) 
	{
		$arr[$val['id']] = $val['prize_value'];
	}
}
$fun = 'egg';
$rid = getRand($arr);
$wxid = $_GET['wxid'];
$query_sql = "SELECT `count` FROM ". $GLOBALS['ecs']->table('weixin_prize_count') ." WHERE `wxid` = '$wxid' AND `pid` = '$pid'";
$res['num'] = $db->getOne("SELECT `num` FROM ". $GLOBALS['ecs']->table('weixin_prize') ." WHERE `pid` = '$pid' ");
$prize_count = $db->getOne($query_sql);
//用户剩余积分
$query_sql1 = "SELECT `pay_points` FROM ". $GLOBALS['ecs']->table('users') ." WHERE `wxid` = '$wxid' ";
$user_point = $db->getOne($query_sql1);
//每次金蛋扣除积分
$prize['point'] = $db->getOne("SELECT `point` FROM ". $GLOBALS['ecs']->table('weixin_prize') ." WHERE `pid` = '$pid' ");


if(( $prize_count >= $res['num'])) 
{
	$res['msg'] = 2;
	$res['prize'] = '您抽奖的机会用完了';
	$res['num'] = 0;
	echo json_encode($res);
	exit;
}
elseif($prize['point']>$user_point)
{
	$res['msg'] = 4;
	$res['prize'] = '您的积分用完了';
	$res['num'] = 0;
	echo json_encode($res);
	exit;

}
else 
{
	foreach($prize_arr as $k=>$v) 
	{
		$prize_rand[$v['id']] = $v;
	}
	$res['msg'] = ($rid==6)?0:1;
	$res['pid'] = $prize_rand[$rid]['prize_id'];
	if($prize_rand[$rid]['state'] == 'no') 
	{
		$res['msg'] = 0;
		$res['prize'] = '很遗憾,您没有中奖';
	}
	else 
	{
		$res['msg'] = 1;
		$res['prize'] = $prize_rand[$rid]['prize_name'];
	}
	if($res['num'] <= 0) 
	{
		$res['num'] = 0;
	}
	else 
	{
		$res['num'] = $res['num'] - $prize_count;
		
	}
	$res['point']=$user_point-$prize['point'];
	$point=$user_point-$prize['point'];
	$res['pid'] = $pid;
	$res['pzfun'] = $fun;
	$res['yn'] = $prize_rand[$rid]['state'];
	$res['paid'] = $prize_rand[$rid]['id'];
	$res['prize_name'] = $res['prize'];
	$res['prize_value'] = $prize_rand[$rid]['prize_value'];
	$lasttime = time();
	$db->query("UPDATE ". $GLOBALS['ecs']->table('weixin_prize') ." SET `count` = `count`+1 WHERE `pid` = '$pid';");
	$db->query("UPDATE ". $GLOBALS['ecs']->table('users') ." SET `pay_points` ='$point' WHERE `wxid` = '$wxid';");
	echo json_encode($res);
	exit;
}
function getRand($proArr) 
{
	$result = '';
	$proSum = array_sum($proArr);
	foreach ($proArr as $key => $proCur) 
	{
		$randNum = mt_rand(1, $proSum);
		if ($randNum <= $proCur) 
		{
			$result = $key;
			break;
		}
		else 
		{
			$proSum -= $proCur;
		}
	}
	unset ($proArr);
	return $result;
}
?>