View file element_payment_result.php

File size: 5.26Kb
<?php
require_once './element_options/element_options.php';

// регистрационная информация (пароль #2)
// registration info (password #2)
$mrh_pass2 = "ghj45gku4kh23iu";

//установка текущего времени
//current date
$tm=getdate(time()+9*3600);
$date="$tm[year]-$tm[mon]-$tm[mday] $tm[hours]:$tm[minutes]:$tm[seconds]";

// чтение параметров
// read parameters
$out_summ = $_REQUEST["OutSum"];
$inv_id = $_REQUEST["InvId"];
$Shpa = $_REQUEST["Shpa"];
$Shpb = $_REQUEST["Shpb"];
$crc = $_REQUEST["SignatureValue"];

$crc = strtoupper($crc);

$my_crc = strtoupper(md5("$out_summ:$inv_id:$mrh_pass2:Shpa=$Shpa:Shpb=$Shpb"));

// проверка корректности подписи
// check signature
if ($my_crc !=$crc)
{
  echo "bad sign\n";
  exit();
}


	$result_user = mysql_result(mysql_query("SELECT COUNT(lost_id) FROM `element_user` WHERE `lost_id` = '$Shpa'"), 0);
	$query_gold = mysql_fetch_assoc(mysql_query("SELECT * FROM `element_payment` WHERE `id` = '$Shpb' LIMIT 1"));

	if ($result_user == 0 OR !$query_gold) {
		echo "bad sign\n";
		exit();
	}
	
	$robo_id = mysql_result(mysql_query("SELECT COUNT(id) FROM `element_payment_shop` WHERE `robo_id` = '$inv_id'"), 0);

	if ($robo_id > 0) {
		echo "bad sign\n";
		exit();
	}
	
	# Проводим платеж
	require_once './element_function/element_function_users.php';
	require_once './element_function/element_function_mail.php';
	
	$payment_user = cache_user($Shpa);							    // кэш данных юзера
	$profile_other = explode(' ', $payment_user['lost_other']);		// Разбиваем на массив
	$profile_other[2] = $profile_other[2] + 1;						// Добавляем +1 письмо
	$payment_user['lost_other'] = implode(' ', $profile_other);		// Возвращаем массив в строку

	// Обновляем данные юзера
	update_money_exp($payment_user, 0, 0, 0, $query_gold['gold']);

	// Заносим платеж в Базу Данных
	mysql_query("INSERT INTO `element_payment_shop` SET `user` = '$Shpa',
												  `robo_id` = '$inv_id',
												  `cena` = '$out_summ',
												  `time` = '".time()."',
												  `gold` = '$query_gold[gold]',
												  `refferer` = '0'");
		
	$lost_sub_text = 'Вас счёт успешно пополнен на <img src="/images/icons/gold.png">'.$query_gold['gold'].' золота';
	$lost_text = '<span class="admin">Ваш счёт успешно пополнен на <img src="/images/icons/gold.png">'.$query_gold['gold'].' золота.<br/></span>';
	mysql_query("INSERT INTO `element_mail` SET `lost_out` = '0',
												`lost_in` = '$Shpa',
												`lost_sub_text` = '$lost_sub_text',
												`lost_text` = '$lost_text',
												`lost_user_out` = '0',
												`lost_user_in` = '$Shpa',
												`lost_time` = '".time()."',
												`lost_system` = 'Банк',
												`lost_new` = '1'");	

		$count_in = Cache_Count_Message($Shpa);
		if (!empty($count_in['all'])) $count_in['all']++;
		if (!empty($count_in['in'])) $count_in['in']++;
		if (!empty($count_in['new'])) $count_in['new']++;
		writecache('element_count_message'.$Shpa, $count_in);

			if ($payment_user['lost_refferer'] > 0) {
					
					$xsolla_user1 = cache_user($payment_user['lost_refferer']);			// кэш данных юзера
					$profile_other1 = explode(' ', $xsolla_user1['lost_other']);		// Разбиваем на массив
					$profile_other1[2] = $profile_other1[2] + 1;						// Добавляем +1 письмо
					$xsolla_user1['lost_other'] = implode(' ', $profile_other1);		// Возвращаем массив в строку
				
					$summa_ref = (int)(($query_gold['gold'] / 100) * 10);
					// Обновляем данные юзера
					update_money_exp($xsolla_user1, 0, 0, 0, $summa_ref);
				
					// Заносим платеж в Базу Данных
					mysql_query("INSERT INTO `element_payment_shop` SET `user` = '$xsolla_user1[lost_id]',
																		`robo_id` = '0',
																		`cena` = '0.00',
																		`time` = '".time()."',
																		`gold` = '$summa_ref',
																		`refferer` = '$Shpa'");
				
					$lost_sub_text = 'Партнерское вознаграждение: <img src="/images/icons/gold.png">'.$summa_ref.' золота';
					$lost_text = '<span class="admin">Партнерское вознаграждение: <img src="/images/icons/gold.png">'.$summa_ref.' золота.<br/></span>';
					mysql_query("INSERT INTO `element_mail` SET `lost_out` = '0',
														`lost_in` = '$xsolla_user1[lost_id]',
														`lost_sub_text` = '$lost_sub_text',
														`lost_text` = '$lost_text',
														`lost_user_out` = '0',
														`lost_user_in` = '$xsolla_user1[lost_id]',
														`lost_time` = '".time()."',
														`lost_system` = 'Банк',
														`lost_new` = '1'");	
					
					$count_in1 = Cache_Count_Message($xsolla_v1);
					if (!empty($count_in1['all'])) $count_in1['all']++;
					if (!empty($count_in1['in'])) $count_in1['in']++;
					if (!empty($count_in1['new'])) $count_in1['new']++;
					writecache('element_count_message'.$xsolla_user1['lost_id'], $count_in1);	
				}

// признак успешно проведенной операции
// success
echo "OK$inv_id\n";

?>