game2006api/webapp/models/HashRate.php
hujiabin 5c6bf0e56f 1
2024-08-07 16:24:35 +08:00

129 lines
3.7 KiB
PHP

<?php
namespace models;
require_once('mt/AchievementsPower.php');
use mt\AchievementsPower;
use phpcommon\SqlHelper;
class HashRate extends BaseModel
{
public static function find($taskId,$period){
// return SqlHelper::ormSelectOne(
// myself()->_getSelfMysql(),
// 't_hash_rate',
// array(
// 'account_id' => myself()->_getAccountId(),
// 'task_id' => $taskId,
// 'period' => $period,
// )
// );
$row = myself()->_getSelfMysql()->execQueryOne(
'SELECT * FROM t_hash_rate WHERE account_id=:account AND period=:period AND task_id=:task_id ORDER BY idx DESC LIMIT 1',
array(
':account' => myself()->_getAccountId(),
':period' => $period,
':task_id' => $taskId,
)
);
if (!$row){
$row = array();
}
return $row;
}
public static function getCount($period){
$count = 0;
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_hash_rate',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
)
);
foreach ($rows as $row){
$hashMeta = AchievementsPower::find($row['task_id']);
if ($hashMeta['task_type'] != AchievementsPower::TYPE5){
$count += 1;
}
}
return $count;
}
public static function add($taskId,$period){
SqlHelper::insert(
myself()->_getSelfMysql(),
't_hash_rate',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
'task_id' => $taskId,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function rewardAdd($period,$reward){
SqlHelper::upsert(
myself()->_getSelfMysql(),
't_hash_rate_reward',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
),
array(
'reward' => function () use($reward) {
return "reward + ${reward}";
},
'modifytime' => myself()->_getNowTime()
),
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
'reward' => $reward,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
public static function getMyHashRate($period){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hash_rate_reward',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
)
);
$myHashRate = 0;
if ($row){
$myHashRate = $row['reward'];
}
return $myHashRate;
}
public static function getTotalByAccount($accountId,$period){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hash_rate_reward',
array(
'account_id' => $accountId,
'period' => $period,
)
);
$totalHashRate = 0;
if ($row){
$totalHashRate = $row['reward'];
}
return $totalHashRate;
}
}