<?php
error_reporting(0);
global $db, $CcTvAi_com_userid;
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
if ($userlogined==true) {
include "../plug/userSign/conf.inc.php";
	if (!IsNumID($CcTvAi_com_userid)) {exit();}
	$callback=SafeRequest("callback", "get");
	$sql="select cd_id,cd_name,cd_signd,cd_signdtime from " . tname('user') . " where cd_id='" . $CcTvAi_com_userid . "'";
	if ($row=$db->getrow($sql)) {
		if (DateDiff(date("Y-m-d", strtotime($row['cd_signdtime'])), date("Y-m-d"))==0) {
			echo $callback . '({"error":10002})';
		} else {
			if (DateDiff(date("Y-m-d", strtotime($row['cd_signdtime'])), date('Y-m-d', strtotime('-1 day')))==0) {
				$db->query("update " . tname('user') . " set cd_signd=cd_signd+'1',cd_signdcumu=cd_signdcumu+'1',cd_signdtime='" . date('Y-m-d H:i:s') . "' where cd_id='" . $CcTvAi_com_userid . "'");
				$cd_sign=($row['cd_signd']+'1');
			} else {
				$db->query("update " . tname('user') . " set cd_signd=1,cd_signdcumu=cd_signdcumu+'1',cd_signdtime='" . date('Y-m-d H:i:s') . "' where cd_id='" . $CcTvAi_com_userid . "'");
				$cd_sign='1';
			}
			if($CcTvAi_com_checkmm == "1"){
				$cd_points=rand(1,userSignpoints);
				$cd_points=$cd_points*2;
			}else{
				$cd_points=rand(1,userSignpoints);
			}
			$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' => 'sign',
				'cd_title' => '每日签到',
				'cd_points' => $cd_points,
				'cd_state' => 0,
				'cd_addtime' => date('Y-m-d H:i:s'),
				'cd_endtime' => getendtime()
			);
			inserttable('bill', $setarr, 1);
			echo $callback . '({"sign_num":' . $cd_sign . ',"score":' . $cd_points . '})';
		}
	}
} else {
	echo $callback . '({"error":20001})';
}
?>