83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class Battle extends BaseModel {
|
|
|
|
const VALID_GAME_TIMES = 5;
|
|
const VALID_BATTLE_COUNT = 100;
|
|
|
|
public static function find($accountId){
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_battle',
|
|
array(
|
|
'account_id' => $accountId,
|
|
)
|
|
);
|
|
return $row ? $row : null;
|
|
}
|
|
|
|
public static function getMyBattleData()
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_battle',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
)
|
|
);
|
|
return $row ? json_decode($row['battle_data'], true) : array();
|
|
}
|
|
|
|
public static function add($battleData)
|
|
{
|
|
SqlHelper::upsert
|
|
(myself()->_getSelfMysql(),
|
|
't_battle',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
),
|
|
array(
|
|
'battle_data' => $battleData,
|
|
'modifytime' => myself()->_getNowTime(),
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'battle_data' => $battleData,
|
|
'kills_modifytime' => myself()->_getNowTime(),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function update($fieldsKv)
|
|
{
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_battle',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
),
|
|
$fieldsKv
|
|
);
|
|
}
|
|
|
|
public static function getBattleCount(){
|
|
|
|
$row = myself()->_getSelfMysql()->execQueryOne("SELECT COUNT(idx) AS battle_num FROM t_battle ");
|
|
return $row && $row['battle_num'] ? $row['battle_num'] : 0;
|
|
}
|
|
|
|
public static function getBattleDataLimit(){
|
|
$limit = self::VALID_BATTLE_COUNT;
|
|
return myself()->_getSelfMysql()->execQuery("SELECT idx,account_id,battle_data FROM t_battle ORDER BY idx DESC LIMIT {$limit}");
|
|
|
|
}
|
|
|
|
}
|