game2006api/webapp/models/Circuit.php
hujiabin ae5310f154 1
2024-10-28 15:48:08 +08:00

157 lines
5.0 KiB
PHP

<?php
namespace models;
use mt;
use phpcommon\SqlHelper;
class Circuit extends BaseModel
{
public static function updateScore($season,$score){
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_circuit_battle',
array(
'account_id' => myself()->_getAccountId(),
'season' => $season
),
array(
'cumulative_score' => $score,
'modifytime' => myself()->_getNowTime()
),
array(
'account_id' => myself()->_getAccountId(),
'season' => $season,
'cumulative_score' => $score,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function updatePhaseScore($season,$phase,$score){
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_circuit_battle_phase',
array(
'account_id' => myself()->_getAccountId(),
'season' => $season,
'phase' => $phase,
),
array(
'cumulative_score' => $score,
'modifytime' => myself()->_getNowTime()
),
array(
'account_id' => myself()->_getAccountId(),
'season' => $season,
'phase' => $phase,
'cumulative_score' => $score,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function getMyScore($season){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_circuit_battle',
array(
'account_id' => myself()->_getAccountId(),
'season' => $season
)
);
return $row ? $row['cumulative_score'] : 0;
}
public static function getMyPhaseScore($season,$phase){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_circuit_battle_phase',
array(
'account_id' => myself()->_getAccountId(),
'season' => $season,
'phase' => $phase,
)
);
return $row ? $row['cumulative_score'] : 0;
}
public static function getRankingList($season){
$sql = "select * from t_circuit_battle where season=:season order by cumulative_score desc,modifytime asc";
$whereKv = array(
":season" => $season,
);
$rows = myself()->_getMysql('')->execQuery($sql,$whereKv);
if (!$rows){
$rows = array();
}
return $rows;
}
public static function getCircuitList($season){
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_circuit_battle',
array(
'season' => $season
)
);
foreach ($rows as &$row){
$codeDb = UserInvitationCode::findCodeByAccount($row['account_id']);
$count = UserInvitationCode::getMyCodeBindCount($codeDb['invitation_code']);
$boost = min($count * 3 / 100,60 / 100);
$boostScore = $row['cumulative_score'] * $boost;
$row['score_boost'] = $boostScore;
$row['cumulative_score'] += $boostScore;
}
return $rows;
}
public static function getPhaseRankingList($season,$phase){
$sql = "select * from t_circuit_battle_phase where season=:season and phase=:phase order by cumulative_score desc,modifytime asc";
$whereKv = array(
":season" => $season,
":phase" => $phase,
);
$rows = myself()->_getMysql('')->execQuery($sql,$whereKv);
if (!$rows){
$rows = array();
}
return $rows;
}
public static function getCircuitPhaseList($season,$phase){
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_circuit_battle_phase',
array(
'season' => $season,
'phase' => $phase,
)
);
foreach ($rows as &$row){
$codeDb = UserInvitationCode::findCodeByAccount($row['account_id']);
$count = UserInvitationCode::getMyCodeBindCount($codeDb['invitation_code']);
$boost = min($count * 3 / 100,60 / 100);
$boostScore = $row['cumulative_score'] * $boost;
$row['score_boost'] = $boostScore;
$row['cumulative_score'] += $boostScore;
}
return $rows;
}
public static function getCurrentMyScore(){
$circuitMeta = myself()->_callMtStatic('CircuitTime', 'getCurrentCircuit');
if (empty($circuitMeta)) {
return 0;
}
return self::getMyScore($circuitMeta['circuit_season']);
}
}