318 lines
11 KiB
PHP
318 lines
11 KiB
PHP
<?php
|
|
|
|
namespace services;
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/HeroSkin.php');
|
|
|
|
require_once('mt/CircuitTime.php');
|
|
require_once('mt/CircuitTime.php');
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use models\Hero;
|
|
use models\HeroSkin;
|
|
|
|
class CircuitRankingService extends BaseService {
|
|
|
|
public static function fillPhaseRanking($currentCircuitMeta, $currentStageMeta)
|
|
{
|
|
$rows = myself()->_callModelStatic('Circuit', 'getCircuitPhaseList',
|
|
$currentStageMeta['circuit_season'],
|
|
$currentStageMeta['circuit_phase']);
|
|
if (count($rows) < 100) {
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
public static function fillRanking($currentCircuitMeta)
|
|
{
|
|
$rows = myself()->_callModelStatic('Circuit', 'getCircuitList',
|
|
$currentCircuitMeta['circuit_season']);
|
|
if (count($rows) < 100) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public static function repairPhaseRanking($currentCircuitMeta)
|
|
{
|
|
$rows = myself()->_callModelStatic('Circuit', 'getCircuitPhaseList',
|
|
$currentStageMeta['circuit_season'],
|
|
$currentStageMeta['circuit_phase']);
|
|
$androidHash = array();
|
|
foreach ($rows as $row) {
|
|
$androidHash[$row['account_id']] = $row;
|
|
}
|
|
$androidHashDb = self::getAndroidHashDb($androidHash);
|
|
if (count($androidHash) < 100) {
|
|
for ($i = count($androidHash); $i < 100; $i++) {
|
|
if (!empty($androidHashDb)) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function getAndroidHashDb($alreadyAndroidHash)
|
|
{
|
|
$androidHash = array();
|
|
$rows = SqlHelper::ormSelectOne
|
|
($this->_getMysql(''),
|
|
't_android',
|
|
array(
|
|
'used' => 0
|
|
)
|
|
);
|
|
foreach ($rows as $row) {
|
|
if (!array_key_exists($row['robot_id'], $alreadyAndroidHash)) {
|
|
$androidHash[$row['robot_id']] = $row;
|
|
}
|
|
}
|
|
return $androidHash;
|
|
}
|
|
|
|
public static function repairRanking($currentCircuitMeta)
|
|
{
|
|
$rows = myself()->_callModelStatic('Circuit', 'getCircuitList',
|
|
$currentCircuitMeta['circuit_season']);
|
|
if (count($rows) < 100) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public static function genAndroidData()
|
|
{
|
|
$currentStageMeta = mt\CircuitTime::getCurrentStage();
|
|
if (empty($currentStageMeta)) {
|
|
myself()->_rspErr(1, 'currentStageMeta Is empty');
|
|
return;
|
|
}
|
|
$rows = SqlHelper::ormSelect
|
|
(myself()->_getMysql(''),
|
|
't_android',
|
|
array(
|
|
'used' => 0
|
|
)
|
|
);
|
|
$num = 0;
|
|
foreach ($rows as $row) {
|
|
++$num;
|
|
if ($num > 75) {
|
|
break;
|
|
}
|
|
SqlHelper::upsert
|
|
(myself()->_getMysql(''),
|
|
't_circuit_battle_phase',
|
|
array(
|
|
'account_id' => $row['robot_id'],
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'phase' => $currentStageMeta['circuit_phase'],
|
|
),
|
|
array(),
|
|
array(
|
|
'account_id' => $row['robot_id'],
|
|
'is_android' => 1,
|
|
'cumulative_score' => 10,
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'phase' => $currentStageMeta['circuit_phase'],
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
public static function extractRankingInfo($data){
|
|
$rankingList = array();
|
|
$ranking = 0;
|
|
foreach ($data as $k=>$row){
|
|
++$ranking;
|
|
$userDb = null;
|
|
$heroDb = null;
|
|
$heroId = 0;
|
|
$skinId = 0;
|
|
if ($row['is_android']) {
|
|
$robotMeta = myself()->_callMtStatic('Robot', 'get', $row['account_id']);
|
|
$userDb = array(
|
|
'account_id' => $row['account_id'],
|
|
'name' => $robotMeta['name'],
|
|
'head_id' => 50001,
|
|
'head_frame' => 60000,
|
|
);
|
|
$heroDb = array(
|
|
'hero_id' => $robotMeta['hero_id'],
|
|
'skin_id' => 0,
|
|
);
|
|
$heroId = $heroDb ? $heroDb['hero_id']:0;
|
|
$skinId = $skinDb ? $skinDb['skin_id']:0;
|
|
} else {
|
|
$userDb = User::find($row['account_id']);
|
|
$heroDb = Hero::findByAccountId($userDb['account_id'],$userDb['hero_id']);
|
|
$skinDb = HeroSkin::findByAccountId($heroDb['skin_id'], $userDb['account_id']);
|
|
$heroId = $heroDb ? $heroDb['hero_id']:0;
|
|
$skinId = $skinDb ? $skinDb['skin_id']:0;
|
|
}
|
|
error_log(json_encode($row));
|
|
$rewardWeight = \mt\CircuitReward::getRewardWeight($ranking);
|
|
if ($userDb){
|
|
$info = array(
|
|
'account_id' => $userDb['account_id'],
|
|
'name' => utf8_encode($userDb['name']),
|
|
'head_id' => $userDb['head_id'],
|
|
'head_frame' => $userDb['head_frame'],
|
|
'hero_id' => $heroId,
|
|
'skin_id' => $skinId,
|
|
'ranking' => $ranking,
|
|
'weight' => $rewardWeight,
|
|
#'score' => $row['cumulative_score'],
|
|
'score' => number_format($row['cumulative_score'], 2, '.', ''),
|
|
'score_boost' => number_format($row['score_boost'], 2, '.', ''),
|
|
);
|
|
array_push($rankingList,$info);
|
|
}
|
|
}
|
|
return $rankingList;
|
|
}
|
|
|
|
public static function recalcRanking()
|
|
{
|
|
$currentStageMeta = mt\CircuitTime::getCurrentStage();
|
|
if (empty($currentStageMeta)) {
|
|
myself()->_rspErr(1, 'currentStageMeta Is empty');
|
|
return;
|
|
}
|
|
$androids = SqlHelper::ormSelect
|
|
(myself()->_getMysql(''),
|
|
't_circuit_battle_phase',
|
|
array(
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'phase' => $currentStageMeta['circuit_phase'],
|
|
'is_android' => 1,
|
|
)
|
|
);
|
|
$rows = SqlHelper::ormSelect
|
|
(myself()->_getMysql(''),
|
|
't_circuit_battle_phase',
|
|
array(
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'phase' => $currentStageMeta['circuit_phase'],
|
|
'is_android' => 0,
|
|
)
|
|
);
|
|
$data = array();
|
|
foreach ($rows as $row) {
|
|
if ($row['cumulative_score'] > 0) {
|
|
array_push($data, $row);
|
|
}
|
|
}
|
|
$sortRows = myself()->arraySort($data, 'cumulative_score', 'desc');
|
|
{
|
|
for ($i = 0; $i < 200; ++$i) {
|
|
array_push($sortRows, array(
|
|
'account_id' => $i,
|
|
'cumulative_score' => 1000 - $i
|
|
));
|
|
}
|
|
}
|
|
if (count($sortRows) <= 20) {
|
|
myself()->_rspErr(1, '人数不足20');
|
|
return;
|
|
}
|
|
$maxScore = $sortRows[19]['cumulative_score'] - 1;
|
|
if ($maxScore <= 0) {
|
|
myself()->_rspErr(1, '分数不足');
|
|
return;
|
|
}
|
|
//21-100之间的名次 塞入35名
|
|
//101-200之间的名次 塞入40名
|
|
$sortAndroids = myself()->arraySort($androids, 'cumulative_score', 'desc');
|
|
$lastScore = $maxScore;
|
|
for ($i = 0; $i < 75; ++$i) {
|
|
if (20 + $i > count($sortRows)) {
|
|
break;
|
|
}
|
|
if ($i > count($sortAndroids)) {
|
|
break;
|
|
}
|
|
$currUser = $sortRows[20 + $i];
|
|
$currScore = $currUser['cumulative_score'];
|
|
if ($currScore >= $lastScore) {
|
|
continue;
|
|
}
|
|
$rangeScore = $lastScore - $currScore;
|
|
$allocScore = $currScore + rand(0, $rangeScore - 1);
|
|
$curAndroid = $sortAndroids[$i];
|
|
self::updateAndroidScore($curAndroid, $allocScore, $currentStageMeta);
|
|
$lastScore = $currScore;
|
|
}
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
private static function updateAndroidScore($android, $newScore, $currentStageMeta)
|
|
{
|
|
if ($newScore <= $android['cumulative_score']) {
|
|
return;
|
|
}
|
|
if ($android['cumulative_score'] <= 0) {
|
|
SqlHelper::upsert
|
|
(myself()->_getMysql(''),
|
|
't_circuit_battle',
|
|
array(
|
|
'account_id' => $android['account_id'],
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
),
|
|
array(
|
|
'cumulative_score' => $newScore,
|
|
),
|
|
array(
|
|
'account_id' => $android['account_id'],
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'is_android' => 1,
|
|
'cumulative_score' => $newScore,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
} else {
|
|
SqlHelper::upsert
|
|
(myself()->_getMysql(''),
|
|
't_circuit_battle',
|
|
array(
|
|
'account_id' => $android['account_id'],
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
),
|
|
array(
|
|
'cumulative_score' => function() use($android, $newScore) {
|
|
$addScore = $android['cumulative_score'] - $newScore;
|
|
return 'cumulative_score +' . $addScore;
|
|
},
|
|
),
|
|
array(
|
|
'account_id' => $android['account_id'],
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'is_android' => 1,
|
|
'cumulative_score' => $newScore,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
SqlHelper::update
|
|
(myself()->_getMysql(''),
|
|
't_circuit_battle_phase',
|
|
array(
|
|
'account_id' => $android['account_id'],
|
|
'season' => $currentStageMeta['circuit_season'],
|
|
'phase' => $currentStageMeta['circuit_phase'],
|
|
),
|
|
array(
|
|
'cumulative_score' => $newScore
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|