160 lines
4.4 KiB
PHP
160 lines
4.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: abcdefg
|
|
* Date: 2017/8/7
|
|
* Time: 16:33
|
|
*/
|
|
|
|
die;
|
|
|
|
require_once dirname(__DIR__) . '/common/config.inc.php';
|
|
require_once dirname(__DIR__) . '/common/DatabaseHelper.php';
|
|
|
|
|
|
/**
|
|
* @note
|
|
* @param mixed $message
|
|
* @return bool
|
|
*/
|
|
function OutputDebugMessage($message)
|
|
{
|
|
if (is_object($message) || is_array($message))
|
|
$message = JsonObjectToJsonString($message);
|
|
|
|
$nowdate = date('Y-m-d');
|
|
$nowtime = date('H:i:s');
|
|
$pathname = Characet(dirname($_SERVER['SCRIPT_FILENAME']) . '/debug/TransferAgent', 'gbk');
|
|
$filename = "{$pathname}/{$nowdate}.log";
|
|
$message = Characet($message, 'gbk');
|
|
|
|
if (!is_dir($pathname))
|
|
mkdir($pathname, 0777, true);
|
|
|
|
if ($file = fopen($filename, 'a+')) {
|
|
if (mb_strstr($message, PHP_EOL, false, USEDCHARSET) != PHP_EOL)
|
|
$message .= PHP_EOL;
|
|
|
|
fwrite($file, "{$nowtime} ====> {$message}");
|
|
fclose($file);
|
|
return true;
|
|
} else
|
|
return false;
|
|
}
|
|
|
|
$agent = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
|
|
$source = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
|
|
$target = isset($_REQUEST['t']) ? $_REQUEST['t'] : '';
|
|
|
|
if (empty($agent)) {
|
|
$output = 'please enter agent id!';
|
|
OutputDebugMessage($output);
|
|
die($output);
|
|
} elseif (empty($source)) {
|
|
$output = 'please enter source sales id!';
|
|
OutputDebugMessage($output);
|
|
die($output);
|
|
} elseif (empty($target)) {
|
|
$output = 'please enter target sales id!';
|
|
OutputDebugMessage($output);
|
|
die($output);
|
|
} else {
|
|
$connect_parameter = new ConnectParameter(MASTER_HOSTNAME, MASTER_HOSTPORT, MASTER_DATABASE, MASTER_USERNAME, MASTER_PASSWORD, MASTER_PERSISTENT, MASTER_CHARSET);
|
|
/** @var IPDOHelper $db */
|
|
$db = new PDODelegator(DATABASE_TYPE);
|
|
|
|
if (!$db->connect($connect_parameter)) {
|
|
$output = JsonObjectToJsonString($db->geterrors());
|
|
OutputDebugMessage($output);
|
|
die($output);
|
|
}
|
|
|
|
if (!$db->begintransaction()) {
|
|
$output = JsonObjectToJsonString($db->geterrors());
|
|
OutputDebugMessage($output);
|
|
die($output);
|
|
}
|
|
|
|
try {
|
|
/// 转移房卡
|
|
$room_card = 0;
|
|
/// 查询源代理信息
|
|
$sales_user = $db->request(/** @lang text */
|
|
'select saus_roomcard from sales_user where saus_agentid = ? and saus_salesid = ?', $agent, $source);
|
|
if (!$db->isdone()) {
|
|
throw new Exception($db->geterrorinfo(), $db->geterrorcode());
|
|
} elseif (empty($sales_user)) {
|
|
throw new Exception("unable to find sales id: {$source}!");
|
|
} else {
|
|
$room_card = intval($sales_user[0]->saus_roomcard);
|
|
}
|
|
|
|
/// 查询新代理信息
|
|
$sales_user = $db->request(/** @lang text */
|
|
'select saus_roomcard from sales_user where saus_agentid = ? and saus_salesid = ?', $agent, $target);
|
|
if (!$db->isdone()) {
|
|
throw new Exception($db->geterrorinfo(), $db->geterrorcode());
|
|
} elseif (empty($sales_user)) {
|
|
throw new Exception("unable to find sales id: {$target}!");
|
|
}
|
|
|
|
$command = <<<EOL
|
|
update
|
|
sales_user a,
|
|
(
|
|
select
|
|
saus_agentid, saus_salesid, saus_roomcard - {$room_card} saus_roomcard
|
|
from
|
|
sales_user
|
|
where
|
|
saus_agentid = ? and saus_salesid = ?
|
|
|
|
union all
|
|
|
|
select
|
|
saus_agentid, saus_salesid, saus_roomcard + {$room_card} saus_roomcard
|
|
from
|
|
sales_user
|
|
where
|
|
saus_agentid = ? and saus_salesid = ?
|
|
) b
|
|
set
|
|
a.saus_roomcard = b.saus_roomcard
|
|
where
|
|
a.saus_agentid = b.saus_agentid and a.saus_salesid = b.saus_salesid
|
|
|
|
EOL;
|
|
|
|
/// 更新新代理的房卡
|
|
$ret = $db->execute($command, $agent, $source, $agent, $target);
|
|
if (!$ret)
|
|
throw new Exception($db->geterrorinfo(), $db->geterrorcode());
|
|
|
|
/// 更新代理的邀请码
|
|
$ret = $db->execute(/** @lang text */
|
|
'update sales_user set saus_invitecode = ? where saus_agentid = ? and saus_invitecode = ?', $target, $agent, $source);
|
|
if (!$ret)
|
|
throw new Exception($db->geterrorinfo(), $db->geterrorcode());
|
|
|
|
/// 更新代理的上级代理
|
|
$ret = $db->execute(/** @lang text */
|
|
'update sales_user set saus_parentid = ? where saus_agentid = ? and saus_parentid = ?', $target, $agent, $source);
|
|
if (!$ret)
|
|
throw new Exception($db->geterrorinfo(), $db->geterrorcode());
|
|
|
|
/// 更新玩家的邀请码
|
|
$ret = $db->execute(/** @lang text */
|
|
'update player set play_invitecode = ? where play_agentid = ? and play_invitecode = ?', $target, $agent, $source);
|
|
if (!$ret)
|
|
throw new Exception($db->geterrorinfo(), $db->geterrorcode());
|
|
|
|
$db->commit();
|
|
} catch (Exception $Exception) {
|
|
$db->rollback();
|
|
$output = JsonObjectToJsonString(array('code' => $Exception->getCode(), 'info' => $Exception->getMessage(),));
|
|
OutputDebugMessage($output);
|
|
die($output);
|
|
}
|
|
}
|
|
|