<?php
/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
global $db;
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
if ($CcTvAi_com_userid) {
	$row=$db->getrow("select cd_id,cd_uid,cd_uname,cd_addtime from " . tname('slot') . " where cd_uid='".$CcTvAi_com_userid."'");
	if(DateDiff(date("Y-m-d", strtotime($row['cd_addtime'])), date("Y-m-d"))==0) {exit('今天已经摇过了！');}
	include "../../plug/userSlot/conf.inc.php";
	if(userSlot_open=="no") {exit('已关闭摇一摇功能');}
	if (!IsNumID($CcTvAi_com_userid)) {exit('数据异常');}
	$callback=SafeRequest("callback", "get");
	//$my_array   = array('1','0','2','1','0','4','1','0','2','1','0','3','8','1','2','0','5','1','0','2','6','0','1','2','0','9','1','0','7','1','0');
	$integral_a=rand(0, userSlotpointsa); //1
	$integral_b=rand(1, userSlotpointsb); //2
	$integral_c=rand(1, userSlotpointsc); //3
	$sql="select cd_id,cd_uid,cd_uname,cd_addtime from " . tname('slot') . " where cd_uid='" . $CcTvAi_com_userid . "'";
	if ($row=$db->getrow($sql)) {
		if (DateDiff(date("Y-m-d", strtotime($row['cd_addtime'])), date("Y-m-d"))==0) {
			exit('您今天摇奖资格已经用完，请明天再来。');
		} else {
			echo'恭喜您获得了幸运摇一摇' . $integral_a . $integral_b .$integral_c . '金币奖励。';
			$db->query("update " . tname('slot') . " set cd_number=cd_number+'1',cd_points='" . $integral_a . $integral_b . $integral_c . "',cd_addtime='" . date('Y-m-d H:i:s') . "' where cd_uid='" . $CcTvAi_com_userid . "'");
		}
	} else {
		echo'恭喜您获得了幸运摇一摇' . $integral_a . $integral_b .$integral_c . '金币奖励。';
		//入库
		$setarr=array(
			'cd_uid' => $CcTvAi_com_userid,
			'cd_uname' => $CcTvAi_com_username,
			'cd_points' => $integral_a . $integral_b . $integral_c,
			'cd_number' => 1,
			'cd_addtime' => date('Y-m-d H:i:s')
		);
		inserttable('slot', $setarr, 1);
	}
	$tomorrow=mktime(date("H"), date("i"), date("s"), date("m"), date("d")+7, date("Y"));
	$cd_enddate=date("Y-m-d H:i:s", $tomorrow);
	//记录账单
	$cd_points=$integral_a . $integral_b . $integral_c;
	$db->query("update " . tname('user') . " set cd_points=cd_points+'" . $cd_points . "' where cd_id='" . $CcTvAi_com_userid . "'");
	$setarr=array(
		'cd_type' => 1, //1为加,0为减
		'cd_uid' => $CcTvAi_com_userid,
		'cd_uname' => $CcTvAi_com_username,
		'cd_icon' => 'app',
		'cd_title' => '幸运摇一摇奖励',
		'cd_points' => $integral_a . $integral_b . $integral_c,
		'cd_state' => 1,
		'cd_addtime' => date('Y-m-d H:i:s'),
		'cd_endtime' => $cd_enddate
	);
	inserttable('bill', $setarr, 1);
} else {
	exit('请先登录！');
}
?>