114 lines
2.8 KiB
PHP
114 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: abcdefg
|
|
* Date: 2017/8/30
|
|
* Time: 11:11
|
|
*/
|
|
|
|
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/ProcessMatchResult', '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;
|
|
}
|
|
|
|
$limit = isset($_REQUEST['c']) ? $_REQUEST['c'] : 0;
|
|
if (empty($limit))
|
|
$limit = 1000;
|
|
|
|
|
|
$p = ConnectParameter::NewParameter(MASTER_HOSTNAME, MASTER_HOSTPORT, MASTER_DATABASE, MASTER_USERNAME, MASTER_PASSWORD, MASTER_PERSISTENT, MASTER_CHARSET);
|
|
/** @var IPDOHelper $reader */
|
|
$reader = new PDODelegator(DATABASE_TYPE);
|
|
/** @var IPDOHelper $writer */
|
|
$writer = new PDODelegator(DATABASE_TYPE);
|
|
$log = '';
|
|
if (!$reader->Connect($p)) {
|
|
$log = JsonObjectToJsonString($reader->GetErrors());
|
|
OutputDebugMessage($log);
|
|
exit($log);
|
|
}
|
|
|
|
if (!$writer->Connect($p)) {
|
|
$log = JsonObjectToJsonString($writer->GetErrors());
|
|
OutputDebugMessage($log);
|
|
exit($log);
|
|
}
|
|
|
|
$reader->request(
|
|
function ($row) {
|
|
/** @var IPDOHelper $db */
|
|
$db = $GLOBALS['writer'];
|
|
|
|
$player_id = $row->player_id;
|
|
$player_name = $row->player_name;
|
|
|
|
$used_card = (array)JsonStringToJsonObject($row->room_type);
|
|
$used_card = array_shift($used_card);
|
|
|
|
$game_info = JsonStringToJsonObject($row->game_info);
|
|
$player_list = isset($game_info->playerlist) ? $game_info->playerlist : null;
|
|
if (!$player_list)
|
|
return true;
|
|
|
|
$winner = null;
|
|
$integral = null;
|
|
foreach ($player_list as $key => $value) {
|
|
if (!$winner || intval($value[1]) > $integral) {
|
|
$winner = $value[0];
|
|
$integral = intval($value[1]);
|
|
}
|
|
}
|
|
|
|
if (strcasecmp($player_name, $winner) == 0) {
|
|
$command = /** @lang text */
|
|
'update ct_temp set used_card = ?, wins = 1, is_process = 1 where id = ?';
|
|
} else {
|
|
$command = /** @lang text */
|
|
'update ct_temp set used_card = ?, is_process = 1 where id = ?';
|
|
}
|
|
|
|
if ($db->execute($command, $used_card, $row->id)) {
|
|
echo 'the record id(', $row->id, ') processing success!<br>', PHP_EOL;
|
|
} else {
|
|
echo 'the record id(', $row->id, ') processing fail!<br>', PHP_EOL;
|
|
}
|
|
|
|
return true;
|
|
}, /** @lang text */
|
|
'select * from ct_temp where is_process = 0 limit ' . intval($limit)
|
|
);
|
|
|
|
if (!$reader->isdone())
|
|
echo $reader->geterrorinfo(), PHP_EOL;
|