game2006api/webapp/models/RankBattle.php
hujiabin b8d4ea7e1b 1
2024-02-26 16:57:01 +08:00

260 lines
8.2 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;
const DAMAGES_OUT = 6;
const ASSIST_TIMES = 7;
const RECOVER_HP = 8;
const SURVIVAL_TIME = 9;
const RESCUE_TIMES = 10;
const OVERALL_CHARTS = 1;
const DAILY_CHARTS = 2;
const WEEKLY_CHARTS = 3;
const MOBA_DATA = 1;
const PVP_DATA = 2;
public static function inspectMode($mode){
if (!in_array($mode,array(
self::MOBA_DATA,
self::PVP_DATA,
))){
return false;
}
return true;
}
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 inspectClass($class){
if (!in_array($class,array(
self::OVERALL_CHARTS,
self::DAILY_CHARTS,
self::WEEKLY_CHARTS,
))){
return false;
}
return true;
}
public static function getTopLimit($mode, $class, $type, $limit, $fieldKv=null){
if (!self::inspectType($type) || !self::inspectClass($class) || !self::inspectMode($mode) ){
return array();
}
if (!$fieldKv){
$field = "*";
}else{
$field = implode(',',$fieldKv);
}
$sql = '';
$whereKv = array();
switch ($class) {
case self::OVERALL_CHARTS : {
$sql = "select {$field} from t_rank_battle where mode=:mode and class =:class and type=:type order by value desc,modifytime asc limit {$limit} ";
$whereKv = array(
"mode" => $mode,
"class" => self::OVERALL_CHARTS,
"type" => $type,
);
}
break;
case self::DAILY_CHARTS : {
$sql = "select {$field} from t_rank_battle where mode=:mode and class =:class and type=:type and writetime=:writetime order by value desc,modifytime asc limit {$limit} ";
$whereKv = array(
"mode" => $mode,
"class" => self::DAILY_CHARTS,
"type" => $type,
"writetime" => myself()->_getNowDaySeconds(),
);
}
break;
case self::WEEKLY_CHARTS : {
$sql = "select {$field} from t_rank_battle where mode=:mode and class =:class and type=:type and writetime=:writetime order by value desc,modifytime asc limit {$limit} ";
$whereKv = array(
"mode" => $mode,
"class" => self::WEEKLY_CHARTS,
"type" => $type,
"writetime" => myself()->_getMondaySeconds(),
);
}
}
// $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($mode,$class,$type){
if (!self::inspectType($type)){
return array();
}
$row = array();
switch ($class) {
case self::OVERALL_CHARTS : {
$row = SqlHelper::ormSelectOne
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type,
'mode' => $mode,
'class' => $class,
)
);
}
break;
case self::DAILY_CHARTS :{
$row = SqlHelper::ormSelectOne
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type,
'mode' => $mode,
'class' => $class,
"writetime" => myself()->_getNowDaySeconds(),
)
);
}
break;
case self::WEEKLY_CHARTS:{
$row = SqlHelper::ormSelectOne
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type,
'mode' => $mode,
'class' => $class,
"writetime" => myself()->_getMondaySeconds(),
)
);
}
}
return $row ;
}
public static function upsert($account,$mode,$type,$val){
if (!$account){
return;
}
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => $account,
'mode' => $mode,
'type' => $type,
'class' => self::OVERALL_CHARTS,
),
array(
'value' => function () use($val) {
return "value + ${val}";
},
'modifytime' => myself()->_getNowTime(),
'writetime' => myself()->_getNowTime(),
),
array(
'account_id' => $account,
'channel' => phpcommon\extractChannel($account),
'class' => self::OVERALL_CHARTS,
'mode' => $mode,
'type' => $type,
'value' => $val,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
'writetime' => myself()->_getNowTime(),
)
);
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => $account,
'mode' => $mode,
'type' => $type,
'class' => self::DAILY_CHARTS,
'writetime' => myself()->_getNowDaySeconds(),
),
array(
'value' => function () use($val) {
return "value + ${val}";
},
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => $account,
'channel' => phpcommon\extractChannel($account),
'class' => self::DAILY_CHARTS,
'mode' => $mode,
'type' => $type,
'value' => $val,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
'writetime' => myself()->_getNowDaySeconds(),
)
);
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_rank_battle',
array(
'account_id' => $account,
'mode' => $mode,
'type' => $type,
'class' => self::WEEKLY_CHARTS,
'writetime' => myself()->_getMondaySeconds(),
),
array(
'value' => function () use($val) {
return "value + ${val}";
},
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => $account,
'channel' => phpcommon\extractChannel($account),
'class' => self::WEEKLY_CHARTS,
'mode' => $mode,
'type' => $type,
'value' => $val,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
'writetime' => myself()->_getMondaySeconds(),
)
);
}
}