102 lines
2.7 KiB
PHP
102 lines
2.7 KiB
PHP
<?php
|
|
|
|
|
|
namespace models;
|
|
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
|
|
require_once('mt/Hero.php');
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
class BattleHistory extends BaseModel
|
|
{
|
|
public static function add($data)
|
|
{
|
|
return SqlHelper::insert
|
|
(myself()->_getSelfMysql(),
|
|
't_battle_history',
|
|
$data
|
|
);
|
|
}
|
|
|
|
public static function getMyBattleHistoryByMode($mode)
|
|
{
|
|
if ($mode == 1) {
|
|
$row1 = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_battle_history',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'match_mode' => 0,
|
|
)
|
|
);
|
|
$row2 = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_battle_history',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'match_mode' => 1,
|
|
)
|
|
);
|
|
$row = array_merge($row1,$row2);
|
|
return $row;
|
|
}elseif($mode == 2){
|
|
$row = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_battle_history',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'match_mode' => 2,
|
|
)
|
|
);
|
|
return $row;
|
|
}else{
|
|
return array();
|
|
}
|
|
}
|
|
|
|
public static function toDto($row){
|
|
if ($row['hero_id']){
|
|
$row['hero_id'] = Hero::find($row['hero_id'])['hero_id'];
|
|
}
|
|
if ($row['weapon1']){
|
|
$row['weapon1'] = Gun::find($row['weapon1'])['gun_id'];
|
|
}
|
|
if ($row['weapon2']){
|
|
$row['weapon2'] = Gun::find($row['weapon2'])['gun_id'];
|
|
}
|
|
return $row;
|
|
}
|
|
|
|
public static function orderBy($data,$order){
|
|
$len = count($data);
|
|
if ($len<=1){
|
|
return $data;
|
|
}
|
|
if ($order == 'desc'){
|
|
for ($i = 0; $i < $len - 1; $i++) {
|
|
for ($j = $i + 1; $j < $len; $j++) {
|
|
if ($data[$i]['idx'] < $data[$j]['idx']) {
|
|
$tmp = $data[$i];
|
|
$data[$i] = $data[$j];
|
|
$data[$j] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
for ($i = 0; $i < $len - 1; $i++) {
|
|
for ($j = $i + 1; $j < $len; $j++) {
|
|
if ($data[$i]['idx'] > $data[$j]['idx']) {
|
|
$tmp = $data[$i];
|
|
$data[$i] = $data[$j];
|
|
$data[$j] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
} |