game2006api/webapp/controller/TempToolsController.class.php
aozhiwei ebedd528ad 1
2024-07-09 20:24:39 +08:00

876 lines
29 KiB
PHP

<?php
require_once('mt/Item.php');
require_once('mt/Parameter.php');
require_once('mt/Language.php');
require_once('models/InGameMall.php');
require_once('services/MailApiService.php');
use phpcommon\SqlHelper;
use models\InGameMall;
class TempToolsController extends BaseController {
public function _handlePre()
{
parent::_handlePre();
}
public function test()
{
}
public function getBattleData()
{
$targetId = getReqVal('target_id', '');
$time = getReqVal('time', '');
$conn = myself()->_getMysql($targetId);
$data = array();
$survivalTime = 0;
$sameTimes = 0;
$sessionChgTimes = 0;
{
$rows = SqlHelper::ormSelect(
$conn,
't_battle_record',
array(
'account_id' => $targetId
)
);
foreach ($rows as $row) {
$reqObj = json_decode($row['request'], true);
$reqObj['start_time'] = $reqObj['game_time'] -
$reqObj['alive_time']/1000;
$survivalTime += $reqObj['alive_time']/1000;
array_push($data, $reqObj);
}
}
usort($data, function ($a, $b) {
return $a['start_time'] < $b['start_time'] ? -1 : 1;
});
$lastSessionId = '';
{
for ($i = 0; $i < count($data); ++$i){
if ($i + 1 >= count($data)) {
break;
}
if ($data[$i]['start_time'] + $time > $data[$i + 1]['start_time']) {
++$i;
++$sameTimes;
}
if ($lastSessionId) {
if ($lastSessionId != $data[$i]['session_id']) {
++$sessionChgTimes;
$lastSessionId = $data[$i]['session_id'];
}
} else {
$lastSessionId = $data[$i]['session_id'];
}
}
}
myself()->_rspData(array(
'battle_times' => count($data),
'same_times' => $sameTimes,
'session_chg_times' => $sessionChgTimes,
'survival_time' => $survivalTime,
'data' => $data
));
}
public function exportRankActivity()
{
$type = getReqVal('type', '');
$count = getReqVal('count', '');
$cond = getReqVal('cond', 0);
$accounts = array();
$conn = myself()->_getMysql('');
{
$rows = $conn->execQuery(
'SELECT * FROM t_rank_activity ' .
'WHERE type=:type AND channel=:channel AND value>=:value ' .
'ORDER BY value DESC, modifytime ASC ' .
"LIMIT ${count}",
array(
':type' => $type,
':channel' => 6516,
':value' => $cond
)
);
$ranked = 1;
foreach ($rows as $row) {
array_push($accounts, array(
'account_id' => $row['account_id'],
'name' => '',
'ranked' => $ranked,
'score' => $row['value'],
'modifytime' => $row['modifytime']
));
++$ranked;
}
}
{
foreach ($accounts as &$account) {
$row = SqlHelper::ormSelectone(
$conn,
't_user',
array(
'account_id' => $account['account_id']
)
);
$account['name'] = $row['name'];
}
}
{
foreach ($accounts as &$account) {
$row = $conn->execQueryOne(
'SELECT MAX(hero_lv) AS max_hero_lv FROM t_hero WHERE account_id=:account_id',
array(
':account_id' => $account['account_id'],
)
);
$account['max_hero_lv'] = $row['max_hero_lv'];
}
}
{
foreach ($accounts as &$account) {
$row = $conn->execQueryOne(
'SELECT MAX(quality) AS max_hero_quality FROM t_hero WHERE account_id=:account_id',
array(
':account_id' => $account['account_id'],
)
);
$account['max_hero_quality'] = $row['max_hero_quality'];
}
}
echo 'account_id,name,rank,score,max_hero_lv,max_hero_quality,flag, time' . "\n";
foreach ($accounts as $account) {
$flag = 0;
if ($type == 3) {
$flag = $account['max_hero_lv'] != $account['score'] ? 1 : 0;
}
if ($type == 4) {
$flag = $account['max_hero_quality'] != $account['score'] ? 1 : 0;
}
echo
phpcommon\extractOpenId($account['account_id']) . ','
. $account['name'] . ','
. $account['ranked'] . ','
. $account['score'] . ','
. $account['max_hero_lv'] . ','
. $account['max_hero_quality'] . ','
. $flag . ','
. phpcommon\timestamp_to_datetime($account['modifytime'])
. "\n";
}
}
public function getRiskAccounts()
{
$accounts = array();
$conn = myself()->_getMysql('');
{
$count = 1000;
$rows = $conn->execQuery(
'SELECT * FROM t_rank_activity ' .
'WHERE type=:type AND channel=:channel AND value>=:value ' .
'ORDER BY value DESC, modifytime ASC ' .
"LIMIT ${count}",
array(
':type' => 1,
':channel' => 6516,
':value' => 600
)
);
$ranked = 1;
foreach ($rows as $row) {
array_push($accounts, array(
'account_id' => $row['account_id'],
'ranked' => $ranked
));
++$ranked;
}
}
$riskAccountHash = array();
foreach ($accounts as $account) {
$rows = SqlHelper::ormSelect(
$conn,
't_battle_record',
array(
'account_id' => $account['account_id']
)
);
$sessionChgTimes = 0;
$lastSessionId = '';
foreach ($rows as $row) {
$reqObj = json_decode($row['request'], true);
if ($lastSessionId) {
if ($lastSessionId != $reqObj['session_id']) {
++$sessionChgTimes;
$lastSessionId = $reqObj['session_id'];
}
} else {
$lastSessionId = $reqObj['session_id'];
}
}
$account['session_changed_times'] = $sessionChgTimes;
array_push($riskAccountHash, $account);
}
usort($riskAccountHash, function ($a, $b) {
return $a['session_changed_times'] > $b['session_changed_times'] ? -1 : 1;
});
echo 'account_id,rank,session_changed_times' . "\n";
foreach ($riskAccountHash as $account) {
echo $account['account_id'] . ',' . $account['ranked'] . ',' . $account['session_changed_times'] . "\n";
}
}
public function exportData()
{
$type = getReqVal('type', '');
if ($type == 1) {
$this->exportData1();
} else if($type == 2) {
$this->exportData2();
} else if($type == 3) {
$this->exportData3();
} else if($type == 4) {
$this->exportData4();
}
}
public function exportData1()
{
$type = getReqVal('type', '');
$accounts = array();
$conn = myself()->_getMysql('');
{
$rows = $conn->execQuery(
'SELECT * FROM t_battle',
array(
)
);
echo 'account_id,first_battle_utc_time' . "\n";
foreach ($rows as $row) {
$channel = phpcommon\extractChannel($row['account_id']);
if ($channel == 6516) {
echo phpcommon\extractOpenId($row['account_id'])
. ',' . phpcommon\timestamp_to_datetime($row['createtime']) . "\n";
}
}
}
}
public function exportData2()
{
$type = getReqVal('type', '');
$accounts = array();
$conn = myself()->_getMysql('');
{
$rows = $conn->execQuery(
'SELECT * FROM t_user',
array(
)
);
echo 'account_id' . "\n";
foreach ($rows as $row) {
$channel = phpcommon\extractChannel($row['account_id']);
if ($channel == 6516) {
echo $row['account_id'] . "\n";
}
}
}
}
public function exportData3()
{
$type = getReqVal('type', '');
$accounts = array();
$conn = myself()->_getMysql('');
{
$rows = $conn->execQuery(
'SELECT * FROM t_dyndata WHERE x=:x AND y=:y',
array(
':x' => TN_ACTIVE,
':y' => 0,
)
);
echo 'account_id' . ",name,active>=10,active>=30,active>=50,active_value\n";
foreach ($rows as $row) {
$channel = phpcommon\extractChannel($row['account_id']);
if ($channel == 6516) {
$userDb = SqlHelper::ormSelectone(
$conn,
't_user',
array(
'account_id' => $row['account_id']
)
);
echo
$row['account_id'] . ','
. ($userDb ? $userDb['name'] : '') . ','
. ($row['val'] >= 10 && $row['val'] < 30 ? 1 :0) . ','
. ($row['val'] >= 30 && $row['val'] < 50 ? 1 :0) . ','
. ($row['val'] >= 50 ? 1 :0) . ','
. $row['val'] . ','
. "\n";
}
}
}
}
public function exportData4()
{
$conn = myself()->_getMysql('');
$rows = $conn->execQuery(
'SELECT account_id, name FROM t_user',
array(
)
);
$data = array();
foreach ($rows as $row) {
$channel = phpcommon\extractChannel($row['account_id']);
if ($channel == BC_CHANNEL) {
$row2 = $conn->execQueryOne(
'SELECT count(*) AS battle_times FROM t_battle_record WHERE account_id=:account_id',
array(
':account_id' => $row['account_id']
)
);
$data[$row['account_id']] = array(
'account_id' => $row['account_id'],
'name' => $row['name'],
'battle_times' => $row2 ? $row2['battle_times'] : 0
);
}
}
echo 'account_id' . ",name,game_times\n";
foreach ($data as $item) {
echo
$item['account_id'] . ','
. $item['name'] . ','
. $item['battle_times']
. "\n";
}
}
public function exportLock()
{
$beginTime = getReqVal('begin_time', '0');
$endTime = getReqVal('end_time', '0');
$type = getReqVal('type', '0');
$bceventConn = null;
$accountConn = null;
{
$mysql_conf = getMysqlConfig(crc32(''));
if (SERVER_ENV == _ONLINE) {
$mysql_conf['database'] = 'bcevent_prod_1';
} else {
$mysql_conf['database'] = 'bcevent_dev';
}
$bceventConn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => $mysql_conf['database'],
));
}
{
$mysql_conf = getMysqlConfig(crc32(''));
if (SERVER_ENV == _ONLINE) {
$mysql_conf['database'] = 'accountdb_prod_1';
} else {
$mysql_conf['database'] = 'accountdb1';
}
$accountConn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => $mysql_conf['database'],
));
}
$heroContractAddress = '\"' . HERO_CONTRACT_ADDRESS . '\"';
if ($type == 0) {
$sql = "select lock_to, count(idx) as lock_count from t_nft_lock_event where createtime>=$beginTime and createtime<=$endTime and lower(JSON_EXTRACT(convert(return_values using utf8), '$.nft'))='$heroContractAddress' group by lock_to;";
} else {
$sql = "select lock_to, count(idx) as lock_count from t_nft_lock_event where createtime>=$beginTime and createtime<=$endTime group by lock_to;";
}
$rows = $bceventConn->execQuery($sql);
foreach ($rows as $row) {
$email = $this->getAddressEmail($accountConn, $row['lock_to']);
echo $row['lock_to'] . ',' . $email . ',' . $row['lock_count'] . "\n";
}
}
private function getAddressEmail($accountConn, $accountAddress)
{
$row = $accountConn->execQueryOne('select * from t_immutable_account where address=:address',
array(
'address' => $accountAddress
));
// error_log(json_encode($row));
if (!empty($row)) {
$dataJson = json_decode($row['data'], true);
return $dataJson['decoded']['email'];
} else {
return '';
}
}
public function repairInGameMallMail()
{
$gameDbConn = myself()->_getMysql('');
$mailDbConn = myself()->_getMailMysql();
$rows = $gameDbConn->execQuery(
'SELECT * FROM t_ingame_mall WHERE status=:status AND buy_ok_time<:buy_ok_time',
array(
'status' => InGameMall::BUY_OK_STATE,
'buy_ok_time' => myself()->_getNowDaySeconds(),
)
);
$mailApiService = new \services\MailApiService();
foreach ($rows as $row) {
$goods = $row;
$price = $row['price'];
//发邮件给卖家
$itemMeta = \mt\Item::get($goods['item_id']);
$languageMeta = \mt\Language::get($itemMeta['name']);
$itemName = $languageMeta ? $languageMeta['en'] : "The Item";
$taxRate = \mt\Parameter::getVal("market_place_tax_rate",0.05);
$taxGold = ceil($price*$taxRate);
$falGold = $price - $taxGold;
$mailContent = <<<EOD
{$itemName} has been successfully sold
Transaction price: + {$price} gold
Service fee: - {$taxGold} gold
After selling {$itemName}, you received {$falGold} gold
EOD;
$attachments = array(
array(
'itemid' => V_ITEM_GOLD,
'itemnum' => $falGold
)
);
echo $mailContent;
$mailApiService->sendSellMail(
$goods['order_id'],
$goods['seller'],
\services\MailApiService::SELL_MAIL_SUBJECT,
$mailContent,
$attachments
);
}
}
public function exportBattleLog()
{
$accountConn = null;
{
$mysql_conf = getMysqlConfig(crc32(''));
if (SERVER_ENV == _ONLINE) {
$mysql_conf['database'] = 'accountdb_prod_1';
} else {
$mysql_conf['database'] = 'accountdb1';
}
$accountConn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => $mysql_conf['database'],
));
}
$data = file_get_contents('php://input');
$array = explode("\r\n", $data);
foreach ($array as $accountId) {
$row = SqlHelper::ormSelectOne(
$accountConn,
't_immutable_account',
array(
'account_id' => $accountId
)
);
if (empty($row)) {
echo "\n";
} else {
echo $row['address'] . "\n";
}
}
}
public function importRewardPunish()
{
$rewardHash = require('../res/reward070901@reward070901.php');
$gameDbConn = myself()->_getMysql('');
{
foreach ($rewardHash as $item) {
$userExists = false;
{
$row = SqlHelper::ormSelectOne(
$gameDbConn,
't_user',
array(
'account_id' => $item['account_id']
)
);
$userExists = !empty($row);
}
SqlHelper::upsert(
$gameDbConn,
't_test_reward070901',
array(
'account_id' => $item['account_id'],
),
array(),
array(
'account_id' => $item['account_id'],
'account_address' => $item['account_address'],
'enter_times' => $item['enter_times'],
'dec_times' => $item['dec_times'],
'return_num' => $item['return_num'],
'user_exists' => $userExists ? 1 : 0,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
}
$punishHash = require('../res/punish070901@punish070901.php');
{
foreach ($punishHash as $item) {
$userExists = false;
{
$row = SqlHelper::ormSelectOne(
$gameDbConn,
't_user',
array(
'account_id' => $item['account_id']
)
);
$userExists = !empty($row);
}
SqlHelper::upsert(
$gameDbConn,
't_test_punish070901',
array(
'account_id' => $item['account_id'],
),
array(),
array(
'account_id' => $item['account_id'],
'account_address' => $item['account_address'],
'gold' => $item['gold'],
'user_exists' => $userExists ? 1 : 0,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
}
echo json_encode(array(
'reward' => $rewardHash,
'punish' => $punishHash,
));
}
public function punish()
{
return;
$gameDbConn = myself()->_getMysql('');
$rows = SqlHelper::ormSelect(
$gameDbConn,
't_test_punish070901',
array(
)
);
foreach ($rows as $row) {
if ($row['user_exists'] && $row['gold'] > 0 && $row['pre_send'] == 0) {
$itemNum = $row['gold'];
$srcGold = $this->getUserGold($gameDbConn, $row['account_id']);
echo $row['account_id'], $srcGold,1;
SqlHelper::update(
$gameDbConn,
't_test_punish070901',
array(
'account_id' => $row['account_id'],
),
array(
'pre_send' => 1,
'src_gold' => $srcGold,
)
);
SqlHelper::update(
$gameDbConn,
't_user',
array(
'account_id' => $row['account_id'],
),
array(
'gold' => function () use($itemNum) {
return "gold - ${itemNum}";
},
)
);
SqlHelper::update(
$gameDbConn,
't_test_punish070901',
array(
'account_id' => $row['account_id'],
),
array(
'post_send' => 1
)
);
}
}
echo 'ok';
}
private function getUserGold($gameDbConn, $accountId)
{
$row = SqlHelper::ormSelectOne(
$gameDbConn,
't_user',
array(
'account_id' => $accountId,
)
);
return empty($row) ? 0 : $row['gold'];
}
public function reward()
{
return;
$gameDbConn = myself()->_getMysql('');
$rows = SqlHelper::ormSelect(
$gameDbConn,
't_test_reward070901',
array(
)
);
foreach ($rows as $row) {
if ($row['pre_send'] == 0) {
SqlHelper::update(
$gameDbConn,
't_test_reward070901',
array(
'account_id' => $row['account_id'],
),
array(
'pre_send' => 1
)
);
$this->sendRewardMail($row['account_id'], $row['return_num']);
SqlHelper::update(
$gameDbConn,
't_test_reward070901',
array(
'account_id' => $row['account_id'],
),
array(
'post_send' => 1
)
);
}
}
echo 'ok';
}
private function sendRewardMail($to, $itemNum)
{
$unikey = 'reward:070901:' . $to;
SqlHelper::upsert
(myself()->_getMailMysql(),
't_sys_mail',
array(
'unikey' => $unikey
),
array(
),
array(
'unikey' => $unikey,
'subject' => 'reward',
'content' => 'reward',
'recipients' => json_encode(array(
$to
)),
'attachments' => json_encode(array(
array(
'itemid' => 900006,
'itemnum' => intval($itemNum),
)
)),
'tag1' => 1,
'tag2' => 2,
'sendtime' => myself()->_getNowTime(),
'expiretime' => myself()->_getNowTime() + 3600 * 24 * 365 * 20,
'user_reg_start_time' => 0,
'user_reg_end_time' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public function returnGoldBullion()
{
$gameDbConn = myself()->_getMysql('');
$data = file_get_contents('php://input');
$array = explode("\r\n", $data);
foreach ($array as $accountId) {
$rows = SqlHelper::ormSelect(
$gameDbConn,
't_gold_bullion',
array(
'src_account_id' => $accountId
)
);
foreach ($rows as $row) {
if (!$this->isReturnEd($row)) {
$this->doReturn($gameDbConn, $row);
}
}
}
echo 'ok';
}
private function isReturnEd($row)
{
if ($row['activated']) {
return true;
}
if ($row['status']) {
return true;
}
if ($row['returned']) {
return true;
}
if ($row['open_status']) {
return true;
}
if ($row['createtime'] > (myself()->_getNowTime() - 3600 * 25)) {
return true;
}
return false;
}
private function doReturn($gameDbConn, $row)
{
echo json_encode($row);
{
$tmpRow = SqlHelper::ormSelectOne(
$gameDbConn,
't_gold_bullion_return',
array(
'token_id' => $row['token_id'],
)
);
if (!empty($tmpRow)) {
return;
}
}
{
SqlHelper::upsert(
$gameDbConn,
't_gold_bullion_return',
array(
'token_id' => $row['token_id'],
),
array(),
array(
'account_id' => $row['src_account_id'],
'token_id' => $row['token_id'],
'net_id' => $row['net_id'],
'item_id' => $row['item_id'],
'gold' => $row['gold'],
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
{
SqlHelper::update(
$gameDbConn,
't_gold_bullion',
array(
'idx' => $row['idx'],
),
array(
'return_status' => 1,
'returned' => 1,
'return_time' => myself()->_getNowTime(),
)
);
}
{
$itemNum = $row['gold'];
if ($itemNum < 0) {
return;
}
SqlHelper::update(
$gameDbConn,
't_user',
array(
'account_id' => $row['src_account_id'],
),
array(
'gold' => function () use($itemNum) {
return "gold + ${itemNum}";
},
)
);
}
$this->sendReturnMail($row['src_account_id'], $row['token_id'], $row['gold']);
{
SqlHelper::update(
$gameDbConn,
't_gold_bullion',
array(
'idx' => $row['idx'],
),
array(
'return_status' => 2,
)
);
}
}
private function sendReturnMail($to, $tokenId, $itemNum)
{
$unikey = 'gold_return:' . $to . ":" . $tokenId;
SqlHelper::upsert
(myself()->_getMailMysql(),
't_sys_mail',
array(
'unikey' => $unikey
),
array(
),
array(
'unikey' => $unikey,
'subject' => 'reward',
'content' => 'We regret to inform you that the minting of your Gold Card has failed. The gold has been refunded to your account. Please check your balance to confirm the refund.',
'recipients' => json_encode(array(
$to
)),
'attachments' => json_encode(array(
)),
'tag1' => 1,
'tag2' => 3,
'sendtime' => myself()->_getNowTime(),
'expiretime' => myself()->_getNowTime() + 3600 * 24 * 365 * 20,
'user_reg_start_time' => 0,
'user_reg_end_time' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}