_getSelfMysql(), 't_hash_rate_reward', array( 'account_id' => myself()->_getAccountId(), ), function ($row) use($cb) { $cb($row); } ); } public static function getTotalCecNum(){ $rows = SqlHelper::ormSelect( myself()->_getSelfMysql(), 't_hash_rate_reward', array( 'account_id'=>myself()->_getAccountId(), ) ); $totalCecNum = 0; if ($rows){ foreach ($rows as $row){ $totalCecNum += $row['reward_cec']; } } return $totalCecNum; } public static function getHistoryByTime($starTime,$endTime){ if ($starTime || $endTime){ $sql = "select * from t_hash_rate_reward where account_id=:account and createtime>:starTime and createtime<:endTime"; $rows = myself()->_getSelfMysql()->execQuery( $sql, array( 'account' => myself()->_getAccountId(), 'starTime' => $starTime, 'endTime' => $endTime, ) ); }else{ $sql = "select * from t_hash_rate_reward where account_id=:account"; $rows = myself()->_getSelfMysql()->execQuery( $sql, array( 'account' => myself()->_getAccountId(), ) ); } if (!$rows){ $rows =array(); } return $rows; } public static function toDto($row){ if (!$row){ return; } $week1 = phpcommon\getMondaySeconds($row['createtime']); $week2 = $week1 + 60*60*24*7 ; $week3 = $week1 + 60*60*24*14 ; $week4 = $week1 + 60*60*24*21 ; $state = $row['reward1'] && $row['reward2'] && $row['reward3'] && $row['reward4'] ? 1 : 0; // $pendingNum = $row['reward_cec']; $pendingNum = 0; if (!$row['reward1']){ // $pendingNum -= $pendingNum*0.25; $pendingNum += 1; } if (!$row['reward2']){ // $pendingNum -= $pendingNum*0.5; $pendingNum += 1; } if (!$row['reward3']){ // $pendingNum -= $pendingNum*0.75; $pendingNum += 1; } if (!$row['reward4']){ // $pendingNum = 0; $pendingNum += 1; } return array( 'hash_rate' => $row['power'], 'cec_num' => $row['reward_cec'], 'state' => $state, 'week1' => $row['reward1'] ? $row['reward1'] : $week1, 'week2' => $row['reward2'] ? $row['reward2'] : $week2, 'week3' => $row['reward3'] ? $row['reward3'] : $week3, 'week4' => $row['reward4'] ? $row['reward4'] : $week4, 'txHash1' => $row['txHash1'] ? $row['txHash1'] : "", 'txHash2' => $row['txHash2'] ? $row['txHash2'] : "", 'txHash3' => $row['txHash3'] ? $row['txHash3'] : "", 'txHash4' => $row['txHash4'] ? $row['txHash4'] : "", 'create_time' => $row['createtime'], 'pending_num' => strval($pendingNum), ); } public static function findByAccount($account,$period){ $row = SqlHelper::ormSelectOne( myself()->_getMysql($account), 't_hash_rate_reward', array( 'account_id'=>$account, 'period' => $period ) ); if (!$row){ $row = null; } return $row; } public static function celCecReward($account,$hashMeta){ $ownerNum = ComputingPower::getOwnedBH($hashMeta['id'],$account); //13.7 $totalNum = ComputingPower::getTotalBH($hashMeta['id']); //25.9 $target = NumberService::ceilEx(min($totalNum / $hashMeta['cec_pool'] , 1),6); // 25.9/10000 if ($totalNum == 0) { $ratio = 0; }else{ $ratio = $ownerNum/$totalNum; } $cecNum = NumberService::ceilEx($hashMeta['cec_pool'] * $target * $ratio,2); //10000*(25.9/10000)*(13.7/25.9) $address = User::findUserAddress($account); SqlHelper::upsert( myself()->_getMysql($account), 't_hash_rate_reward', array( 'account_id'=>$account, 'period'=>$hashMeta['id'], ), array( ), array( 'account_id'=>$account, 'address'=>$address, 'period'=>$hashMeta['id'], 'power'=>$ownerNum, 'reward_cec' => $cecNum, // 'reward1' => 0, // 'reward2' => 0, // 'reward3' => 0, // 'reward4' => 0, 'createtime'=>myself()->_getNowTime(), 'modifytime'=>myself()->_getNowTime(), ) ); } }