game2006api/webapp/controller/ToolsController.class.php
aozhiwei 684e4b20b2 1
2024-11-06 17:14:17 +08:00

569 lines
20 KiB
PHP

<?php
require_once('phpcommon/bignumber.php');
require_once('phpcommon/sqlhelper.php');
require_once('services/BlockChainService.php');
require_once('services/BattleBoxService.php');
require_once('models/BuyRecord.php');
require_once('mt/Robot.php');
use models\Battle;
use phpcommon\SqlHelper;
use services\BlockChainService;
use services\BattleBoxService;
use models\BuyRecord;
class ToolsController extends BaseController {
public function _handlePre()
{
parent::_handlePre();
if (SERVER_ENV == _ONLINE) {
die("can't create ToolsController");
return;
}
}
public function test()
{
$price = getReqVal('price', '');
$priceBn = phpcommon\bnInit($price);
if ($priceBn === false) {
myself()->_rspErr(1, '解析失败');
return;
}
if (phpcommon\bnCmp($priceBn, phpcommon\bnInit('0')) <= 0) {
myself()->_rspErr(1, '不能为负数');
return;
}
if (phpcommon\bnCmp($priceBn, phpcommon\bnInit('10000000000000')) >= 0) {
myself()->_rspErr(1, '超过限制');
return;
}
myself()->_rspOk();
}
public function clearDB()
{
global $g_conf_mysql_cluster;
foreach ($g_conf_mysql_cluster as $mysql_conf) {
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
));
$tables = $conn->execQueryAsArray('show tables;');
foreach ($tables as $table) {
$tblName = $table[0];
$conn->execScript("DROP TABLE {$tblName};",
array());
}
}
}
public function checkWhiteList()
{
$resHash = array();
$whiteList = require("../res/alphatestWhiteList@alphatestWhiteList.php");
foreach ($whiteList as $item) {
$account = trim(strtolower($item['account']));
$i = crc32($account) % 100;
if (!getXVal($resHash, $i)) {
$list = require("../res/alphatestWhiteList${i}@alphatestWhiteList.php");
$resHash[$i] = $list;
}
$list = getXVal($resHash, $i);
$found = false;
foreach ($list as $item2) {
$account2 = trim(strtolower($item2['account']));
if ($account == $account2) {
$found = true;
}
}
if (!$found) {
echo $account . ' not found';
}
}
myself()->_rspOk();
}
public function inWhiteList()
{
$account = trim(strtolower(getReqVal('account', '')));
$i = crc32($account) % 100;
$list = require("../res/alphatestWhiteList${i}@alphatestWhiteList.php");
$found = false;
foreach ($list as $item2) {
$account2 = trim(strtolower($item2['account']));
if ($account == $account2) {
$found = true;
}
}
myself()->_rspData(array(
'found' => $found
));
}
public function splitWhiteList()
{
$dataHash = array();
for ($i = 0; $i < 100; ++$i){
$dataHash[$i] = '<?php' . "\n";
$dataHash[$i] .= 'return array(' . "\n";
}
{
$whiteList = require("../res/alphatestWhiteList@alphatestWhiteList.php");
foreach ($whiteList as $item) {
$account = trim(strtolower($item['account']));
if (strlen($account) != strlen('0x79b9997987800a4dD60049aa2e6bE3399be66F56')) {
var_dump($item);
}
$i = crc32($account) % 100;
$dataHash[$i] .= 'array(' . "\n";
$dataHash[$i] .= ' "account"=>"' . $account . '"' . "\n";
$dataHash[$i] .= '),' . "\n";
}
}
for ($i = 0; $i < 100; ++$i){
$dataHash[$i] .= ');' . "\n";
$this->writeToFile("../res/alphatestWhiteList${i}@alphatestWhiteList.php",
$dataHash[$i]);
}
myself()->_rspOk();
}
public function isSameSeriesAccount()
{
$accountId1 = getReqVal('account_id1', '');
$accountId2 = getReqVal('account_id2', '');
// error_log(phpcommon\extractOpenId($accountId1));
// error_log(phpcommon\extractRealOpenId(phpcommon\extractOpenId($accountId1)));
// error_log($accountId1 . ' **** ' . $accountId2 . ' ' .
// phpcommon\isSameSeriesAccount($accountId1, $accountId2));
myself()->_rspData(array(
));
}
public function outappRecharge()
{
$price = BlockChainService::formatCurrencyEx(1, 6);
echo $price;
return;
/*{
$obj = array(
'a' => 'safdf'
);
if (empty($obj['b'])) {
echo '22222';
}
//echo $obj['b'];
SqlHelper::update(
myself()->_getMysql(''),
't_user',
array(
'account_id' => getReqVal('account_id', '')
),
array(
'address' => null
)
);
error_log(json_encode($_REQUEST));
echo 1434;
}
return;*/
$orderInfo = null;
{
$params = array(
'c' => 'Shop',
'a' => 'outappPurchase',
'account_id' => getReqVal('account_id', ''),
'session_id' => getReqVal('session_id', ''),
'goods_id' => getReqVal('goods_id', ''),
'goods_num' => getReqVal('goods_num', ''),
'platform' => getReqVal('platform', ''),
'network' => getReqVal('network', ''),
'crypto' => getReqVal('crypto', ''),
'fiat' => getReqVal('fiat', ''),
'fiatAmount' => getReqVal('fiatAmount', ''),
'payWayCode' => getReqVal('payWayCode', ''),
'country' => getReqVal('country', ''),
);
$url = "https://game2006api-test.kingsome.cn/webapp/index.php?";
$response = '';
if (!phpcommon\HttpClient::get
($url,
$params,
$response)) {
// error_log($response);
myself()->_rspErr(500, 'server internal error 3, url:' . $url);
die();
return;
}
$orderInfo = json_decode($response, true);
//echo $response;
}
{
$params = array(
'c' => 'Callback',
'a' => 'dispatch',
'action' => 'outappPurchase',
//'c' => 'Shop',
//'a' => 'buyGoodsDirect',
'account_id' => getReqVal('account_id', ''),
'order_id' => $orderInfo['order_id'],
'status' => 9,
'id' => 1,
'txhash' => '',
);
{
$signArr = array(
'account_id' => $params['account_id'],
'order_id' => $params['order_id'],
'status' => $params['status'],
'id' => $params['id'],
'txhash' => $params['txhash']
);
ksort($signArr);
$arrSign = array();
foreach($signArr as $key => $val){
array_push($arrSign, $key . '=' . $val);
}
$signStr = implode('&', $arrSign);
$sign = hash_hmac('sha256', $signStr, BUY_SERVER_PKEY);
// error_log($signStr . BUY_SERVER_PKEY . '|!' . $sign);
$params['sign'] = $sign;
}
$url = "https://game2006api-test.kingsome.cn/webapp/index.php?";
$response = '';
if (!phpcommon\HttpClient::get
($url,
$params,
$response)) {
// error_log($response);
myself()->_rspErr(500, 'server internal error 3, url:' . $url);
die();
return;
}
echo $response;
}
}
private function writeToFile($fileName, $data)
{
$fp = fopen($fileName, 'w');
if (!$fp) {
return;
}
fwrite($fp, $data . "\n");
fclose($fp);
}
public function geneTestBattleData(){
// $data = json_decode($this->testBattleData,JSON_OBJECT_AS_ARRAY);
$str = '{
"abandon_battle": 0,
"account_id": "6513_2006_qWceQesI1syq80htV04BokwUS4FtN7C4",
"alive_time": 156050,
"assist": 8,
"damage_in": 236,
"damage_out": 15004,
"dead": 0,
"destory_car_times": 0,
"diving_times": 0,
"full_level_idx": 0,
"game_duration": 160,
"game_time": 1710920097,
"head": "",
"head_frame": 0,
"hero_id": 30800,
"hero_uniid": "50366",
"heros": "",
"is_mvp": 0,
"is_run_away": 0,
"kills": 4,
"max_hero_skill_lv": 0,
"move_distance": 6156.5,
"name": "alkl",
"open_airdrop_times": 0,
"pvp_assist": 8,
"pvp_damage": 15004,
"pvp_kill": 4,
"pvp_personal_rank": 1,
"pvp_recover": 151,
"pvp_rescue": 0,
"pvp_survia_time": 156050,
"ranked": 1,
"recover_hp": 151,
"rescue_teammate_times": 0,
"ride_car_kills": 0,
"ride_car_move_distance": 0,
"sex": 0,
"skin_id": 40801,
"use_camouflage_times": 0,
"use_medicine_times": 0,
"use_skill_times": 7,
"weapon_uuid1": "0",
"weapon_uuid2": "0",
"weapons_slot": "20711:77|30204:2|",
"weapons_type": "20711:4:13906:0|",
"battle_uuid": "1011223897643738990592",
"map_id": 2004,
"moba_enemy_team_kills": 2,
"moba_my_team_kills": 12,
"pvp_alive_human_num": -11,
"pvp_match_mode": 0,
"pvp_settelement_color": 1,
"pvp_settelement_type": 1,
"pvp_team_kills": 12,
"pvp_team_rank": 1,
"pvp_total_human_num": 8,
"pvp_total_team_num": 2,
"room_mode": 2,
"room_uuid": "1011223897612059412480",
"team_id": 1
}';
$data = json_decode($str,JSON_OBJECT_AS_ARRAY);
for ($i = 0 ;$i<100;$i++){
$hisBattleData = array();
if (!isset($hisBattleData['data'])) {
$hisBattleData['data'] = array(
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
);
}
$account = "6666_2006_testAccount".$i.rand(111111111,999999999);
$data['pvp_team_rank'] = rand(1,10);
$data['kills'] = rand(5,15);
$data['damage_out'] = rand(5000,30000);
$data['damage_in'] = rand(5000,30000);
$data['recover_hp'] = rand(1000,6000);
$data['alive_time'] = rand(240000,600000);
$data['pvp_assist'] = rand(0,8);
$this->apply($hisBattleData['data'],$data);
if (!isset($hisBattleData['moba_data'])) {
$hisBattleData['moba_data'] = array(
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
);
}
$data['pvp_team_rank'] = rand(1,2);
$data['kills'] = rand(1,5);
$data['damage_out'] = rand(2500,20000);
$data['damage_in'] = rand(2500,20000);
$data['recover_hp'] = rand(1250,10000);
$data['alive_time'] = rand(100000,400000);
$data['pvp_assist'] = rand(0,8);
$data['hero_lv'] = rand(1,10);
$this->apply($hisBattleData['moba_data'],$data);
SqlHelper::upsert
(myself()->_getMysql("6513_2006_qWceQesI1syq80htV04BokwUS4FtN7C4"),
't_battle',
array(
'account_id' => $account,
),
array(
'battle_data' => json_encode($hisBattleData),
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => $account,
'battle_data' => json_encode($hisBattleData),
'kills_modifytime' => myself()->_getNowTime(),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}
private function apply(&$battleData,$battleInfo)
{
//战斗次数
$this->incValue($battleData, 'total_battle_times', 1);
//排名
$ranked = getXVal($battleInfo,'pvp_team_rank', 0);
if ($ranked == 1) {
//吃鸡次数
$this->incValue($battleData, 'total_win_times', 1);
}
//击杀总次数
$kills = getXVal($battleInfo,'kills', 0);
$this->incValue($battleData, 'total_kills_times', $kills);
//输出
$damageOut = getXVal($battleInfo,'damage_out', 0);
$this->incValue($battleData, 'total_damage_out', $damageOut);
//承伤
$damageIn = getXVal($battleInfo,'damage_in', 0);
$this->incValue($battleData, 'total_damage_in', $damageIn);
//回复
$recoverHp = getXVal($battleInfo,'recover_hp', 0);
$this->incValue($battleData, 'total_recover_hp', $recoverHp);
//存活时间
$aliveTime = getXVal($battleInfo,'alive_time', 0);
$this->incValue($battleData, 'total_alive_time', $aliveTime);
//助攻次数
$assistTime = getXVal($battleInfo,'pvp_assist', 0);
$this->incValue($battleData, 'total_assist_time', $assistTime);
//等级
$level = getXVal($battleInfo,'hero_lv', 1);
$this->incValue($battleData, 'total_level', $level);
//救援次数
$this->incValue($battleData, 'rescue_teammate_times', getXVal($battleInfo,'rescue_teammate_times', 0));
//潜水次数
$this->incValue($battleData, 'diving_times', getXVal($battleInfo,'diving_times', 0));
//开启空投次数
$this->incValue($battleData, 'open_airdrop_times', getXVal($battleInfo,'open_airdrop_times', 0));
//使用药品次数
$this->incValue($battleData, 'use_medicine_times', getXVal($battleInfo,'use_medicine_times', 0));
//击毁机甲次数
$this->incValue($battleData, 'destory_car_times', getXVal($battleInfo,'destory_car_times', 0));
//使用伪装次数
$this->incValue($battleData, 'use_camouflage_times', getXVal($battleInfo,'use_camouflage_times', 0));
//使用技能次数
$this->incValue($battleData, 'use_skill_times', getXVal($battleInfo,'use_skill_times', 0));
//驾驶机甲移动距离
$this->incValue($battleData, 'ride_car_move_distance', getXVal($battleInfo,'ride_car_move_distance', 0));
//驾驶机甲击杀数
$this->incValue($battleData, 'ride_car_kills', getXVal($battleInfo,'ride_car_kills', 0));
}
private function incValue(&$battleData, $key, $val)
{
if ($val > 0) {
$battleData[$key] = getXVal($battleData, $key, 0) + $val;
}
}
public function genGoldBullionAirDrop()
{
$num = getReqVal('num', '');
$num = max($num, 0);
$num = min($num, 20);
$tokenIds = array();
$accountId = '1_2006_email|66726ee59adad935bd67520e';
$address = '0x57724eb7e63ebfd9833dcb7371ff9508ef7de48a';
$itemId = V_ITEM_GOLD_BULLION_1W;
$gold = 1000;
$netId = 13371;
$checkSql1 = 'SELECT COUNT(*) FROM t_nft WHERE token_id IN (';
$checkSql2 = 'SELECT COUNT(*) FROM t_gold_bullion WHERE token_id IN (';
for ($i = 0; $i < $num; ++$i) {
$tokenId = BuyRecord::genOrderId
(
GAME_ID,
phpcommon\BC_FUNC_CREATION,
myself()->_getNowTime(),
$address
);
array_push($tokenIds, $tokenId);
echo 'INSERT INTO t_gold_bullion(src_account_id, src_address, token_id, net_id, item_id, gold, createtime, modifytime)' .
'VALUES("' . $accountId . '",' .
'"' . $address . '",' .
'"' . $tokenId . '",' .
'' . $netId . ',' .
'' . $itemId . ',' .
'' . $gold . ',' .
'' . myself()->_getNowTime() . ',' .
'' . myself()->_getNowTime() . ");\n";
if ($i == 0) {
$checkSql1 .= '"' . $tokenId . '"';
} else {
$checkSql1 .= ',"' . $tokenId . '"';
}
if ($i == 0) {
$checkSql2 .= '"' . $tokenId . '"';
} else {
$checkSql2 .= ',"' . $tokenId . '"';
}
}
$checkSql1 .= ");\n";
$checkSql2 .= ");\n";
echo $checkSql1;
echo $checkSql2;
}
public function battleBoxAlloc()
{
$phase = getReqVal('phase', '');
$day = 0;
BattleBoxService::internalClear($phase, $day);
BattleBoxService::allocBox(myself()->_getNowTime());
BattleBoxService::dump($phase, $day);
}
public function battleBoxDump()
{
$phase = getReqVal('phase', '');
$day = getReqVal('day', '');
BattleBoxService::dump($phase, $day);
}
public function battleBoxClear()
{
$phase = getReqVal('phase', '');
$day = getReqVal('day', '');
BattleBoxService::clear($phase, $day);
}
public function battleBoxSet()
{
$phase = getReqVal('phase', '');
$day = getReqVal('day', '');
BattleBoxService::set($phase, $day);
}
public function includeAndroid()
{
mt\Robot::traverse(function ($meta) {
$row = SqlHelper::ormSelectOne
($this->_getMysql(''),
't_user',
array(
'name' => $meta['name']
)
);
if ($row) {
echo json_encode($meta);
}
return true;
});
}
public function excludeAndroid()
{
mt\Robot::traverse(function ($meta) {
$row = SqlHelper::ormSelectOne
($this->_getMysql(''),
't_user',
array(
'name' => $meta['name']
)
);
if (!$row) {
echo json_encode($meta);
}
return true;
});
}
public function genAndroid()
{
mt\Robot::traverse(function ($meta) {
echo 'INSERT INTO t_android(robot_id, name, createtime, modifytime)VALUES('
. $meta['id'] . ",'" . $meta['name'] . "'," . myself()->_getNowTime() . ',' . myself()->_getNowTime() . ");\n";
return true;
});
}
}