132 lines
3.7 KiB
PHP
132 lines
3.7 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,
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function all($period)
|
|
{
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_hash_rate',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'period' => $period,
|
|
)
|
|
);
|
|
return array_map(function($row) {
|
|
$nowDaySeconds = myself()->_getNowDaySeconds();
|
|
$mondaySeconds = myself()->_getMondaySeconds();
|
|
return $row;
|
|
}, $rows);
|
|
}
|
|
|
|
public static function allToHash($period)
|
|
{
|
|
$rows = self::all($period);
|
|
$taskHash = array();
|
|
array_walk($rows, function ($row) use(&$taskHash) {
|
|
$taskHash[$row['task_id']] = $row;
|
|
});
|
|
return $taskHash;
|
|
}
|
|
|
|
|
|
public static function add($taskId,$period){
|
|
SqlHelper::upsert(
|
|
myself()->_getSelfMysql(),
|
|
't_hash_rate',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'period' => $period,
|
|
'task_id' => $taskId
|
|
),
|
|
array(
|
|
'modifytime' => myself()->_getNowTime()
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'period' => $period,
|
|
'task_id' => $taskId,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function getMyHashRate($period){
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_hash_rate',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'period' => $period,
|
|
)
|
|
);
|
|
$myHashRate = 0;
|
|
if ($rows){
|
|
foreach ($rows as $row){
|
|
$myHashRate += $row['reward'];
|
|
}
|
|
}
|
|
return $myHashRate;
|
|
}
|
|
|
|
public static function getTotalByAccount($accountId,$period){
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_hash_rate',
|
|
array(
|
|
'account_id' => $accountId,
|
|
'period' => $period,
|
|
)
|
|
);
|
|
$totalHashRate = 0;
|
|
if ($rows){
|
|
foreach ($rows as $row){
|
|
$totalHashRate += $row['reward'];
|
|
}
|
|
}
|
|
return $totalHashRate;
|
|
}
|
|
|
|
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()
|
|
)
|
|
);
|
|
}
|
|
|
|
} |