game2006api/webapp/models/HashRate.php
hujiabin 330e1fc9da 1
2024-08-06 11:35:52 +08:00

119 lines
3.4 KiB
PHP

<?php
namespace models;
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){
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_hash_rate',
array(
'account_id' => myself()->_getAccountId(),
'period' => $period,
)
);
return count($rows);
}
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::ormSelect(
myself()->_getSelfMysql(),
't_hash_rate_reward',
array(
'account_id' => $accountId,
'period' => $period,
)
);
$totalHashRate = 0;
if ($row){
$totalHashRate = $row['reward'];
}
return $totalHashRate;
}
}