game2006api/webapp/models/RankBattle.php
hujiabin 78f7fad29f 1
2023-05-22 14:02:47 +08:00

95 lines
2.4 KiB
PHP

<?php
namespace models;
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class RankBattle extends BaseModel
{
const GAME_TIMES = 1;
const WIN_TIMES = 2;
const MVP_TIMES = 3;
const TOP_THREE_TIMES = 4;
const KILL_TIMES = 5;
public static function inspectType($type){
if (!in_array($type,array(
self::GAME_TIMES,
self::WIN_TIMES,
self::MVP_TIMES,
self::TOP_THREE_TIMES,
self::KILL_TIMES,
))){
return false;
}
return true;
}
public static function getTopLimit($type,$limit,$fieldKv=null){
if (!self::inspectType($type)){
return array();
}
if (!$fieldKv){
$field = "*";
}else{
$field = implode(',',$fieldKv);
}
$sql = "select {$field} from t_rank_battle where type=:type order by value desc,modifytime asc limit {$limit} ";
$whereKv = array(
"type" => $type,
);
$rows = myself()->_getSelfMysql()->execQuery($sql,$whereKv);
if (!$rows){
$rows = array();
}
return $rows;
}
public static function find($type){
if (!self::inspectType($type)){
return array();
}
$row = SqlHelper::ormSelectOne
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type,
)
);
return $row ? $row : null;
}
public static function upsert($account,$type,$val){
if (!$account){
return;
}
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => $account,
'type' => $type,
),
array(
'value' => function () use($val) {
return "value + ${val}";
},
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => $account,
'channel' => phpcommon\extractChannel($account),
'type' => $type,
'value' => $val,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}