game2006api/webapp/models/ServerTaskBattleCount.php
hujiabin f475f86f28 1
2024-07-11 19:18:36 +08:00

73 lines
2.2 KiB
PHP

<?php
namespace models;
use mt;
use phpcommon\SqlHelper;
class ServerTaskBattleCount extends BaseModel
{
const TOTAL_COUNT = 1; //总计数
const LOOP_COUNT = 2; //循环计数
public static function getV($period,$lootIndex, $state, $defVal = 0)
{
$valData = self::internalGetV($period, $lootIndex,$state, $defVal);
return $valData['val'];
}
public static function setV($period,$lootIndex, $state, $defVal)
{
self::internalSetV($period,$lootIndex, $state, $defVal);
}
public static function incV($period,$lootIndex, $state, $val)
{
$oldVal = self::getV($period,$lootIndex, $state);
self::internalSetV($period,$lootIndex, $state, $oldVal + $val);
}
private static function internalGetV($period,$lootIndex, $state, $defVal = 0){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_server_task_battle_count',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
'loot_index' => $lootIndex,
'state' => $state,
)
);
return array(
'val' => $row ? $row['val'] : $defVal,
'modifytime' => $row ? $row['modifytime'] : myself()->_getNowTime(),
);
}
private static function internalSetV($period,$lootIndex,$state, $val)
{
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_server_task_battle_count',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
'loot_index' => $lootIndex,
'state' => $state
),
array(
'val' => $val,
'modifytime' => myself()->_getNowTime()
),
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
'loot_index' => $lootIndex,
'state' => $state,
'val' => $val,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}