This commit is contained in:
aozhiwei 2024-11-09 14:23:22 +08:00
parent 76061af451
commit 701f9355ba

View File

@ -220,6 +220,96 @@ class CircuitRankingService extends BaseService {
}
//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::updateAndroid($curAndroid, $allocScore, $currentStageMeta);
$lastScore = $currScore;
}
}
private static function updateAndroidScore($android, $newScore, $currentStageMeta)
{
if ($newScore <= $android['cumulative_score']) {
return;
}
if ($curAndroid['cumulative_score'] <= 0) {
SqlHelper::upsert
($this->_getMysql(''),
't_circuit_battle',
array(
'account_id' => $android['robot_id'],
'season' => $currentStageMeta['circuit_season'],
'phase' => $currentStageMeta['circuit_phase'],
),
array(
'cumulative_score' => $newScore,
),
array(
'account_id' => $android['robot_id'],
'season' => $currentStageMeta['circuit_season'],
'phase' => $currentStageMeta['circuit_phase'],
'is_android' => 1,
'cumulative_score' => $newScore,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
} else {
SqlHelper::upsert
($this->_getMysql(''),
't_circuit_battle',
array(
'account_id' => $android['robot_id'],
'season' => $currentStageMeta['circuit_season'],
'phase' => $currentStageMeta['circuit_phase'],
),
array(
'cumulative_score' => function() use($android, $newScore) {
$addScore = $android['cumulative_score'] - $newScore;
return 'cumulative_score +' . $addScore;
},
),
array(
'account_id' => $android['robot_id'],
'season' => $currentStageMeta['circuit_season'],
'phase' => $currentStageMeta['circuit_phase'],
'is_android' => 1,
'cumulative_score' => $newScore,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
SqlHelper::update
($this->_getMysql(''),
't_circuit_battle',
array(
'account_id' => $android['robot_id'],
'season' => $currentStageMeta['circuit_season'],
'phase' => $currentStageMeta['circuit_phase'],
),
array(
'cumulative_score' => function() use($android, $newScore) {
$addScore = $android['cumulative_score'] - $newScore;
return 'cumulative_score +' . $addScore;
},
)
);
}
}