示例#1
0
    $pct_votes[$row['currency_id']]['user_pct'][$row['pct']] = $row['votes'];
    $tpl['pct_votes'][$row['currency_id']]['user_pct'][round((pow(1 + $row['pct'], 3600 * 24 * 365) - 1) * 100, 2)] = $row['votes'];
}
$PctArray = ParseData::getPctArray();
$new_pct = array();
foreach ($pct_votes as $currency_id => $data) {
    // определяем % для майнеров
    $pct_arr = ParseData::makePctArray($data['miner_pct']);
    $key = get_max_vote($pct_arr, 0, 390, 100);
    $new_pct['currency'][$currency_id]['miner_pct'] = ParseData::getPctValue($key);
    $tpl['new_pct'][$currency_id]['miner_pct'] = round((pow(1 + ParseData::getPctValue($key), 3600 * 24 * 365) - 1) * 100, 2);
    // определяем % для юзеров
    $pct_arr = ParseData::makePctArray($data['user_pct']);
    $pct_y = array_search($new_pct['currency'][$currency_id]['miner_pct'], $PctArray);
    $max_user_pct_y = round($pct_y / 2, 2);
    $user_max_key = find_user_pct($max_user_pct_y);
    // отрезаем лишнее, т.к. поиск идет ровно до макимального возможного, т.е. до miner_pct/2
    $pct_arr = del_user_pct($pct_arr, $user_max_key);
    $key = get_max_vote($pct_arr, 0, $user_max_key, 100);
    $new_pct['currency'][$currency_id]['user_pct'] = ParseData::getPctValue($key);
    $tpl['new_pct'][$currency_id]['user_pct'] = round((pow(1 + ParseData::getPctValue($key), 3600 * 24 * 365) - 1) * 100, 2);
}
/*
 * %/год
 * */
$res = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT *\n\t\tFROM `" . DB_PREFIX . "currency`\n\t\t");
while ($row = $db->fetchArray($res)) {
    $pct = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT *\n\t\t\tFROM `" . DB_PREFIX . "pct`\n\t\t\tWHERE `currency_id` = {$row['id']}\n\t\t\tORDER BY `block_id` DESC\n\t\t\tLIMIT 1\n\t\t\t", 'fetch_array');
    $tpl['currency_pct'][$row['id']]['name'] = $row['name'];
    $tpl['currency_pct'][$row['id']]['miner'] = round((pow(1 + $pct['miner'], 120) - 1) * 100, 6);
    $tpl['currency_pct'][$row['id']]['user'] = round((pow(1 + $pct['user'], 120) - 1) * 100, 6);
示例#2
0
 function new_pct_front()
 {
     $error = $this->general_check();
     if ($error) {
         return $error;
     }
     // является ли данный юзер майнером
     if (!$this->check_miner($this->tx_data['user_id'])) {
         return 'error miner id';
     }
     // получим public_key
     $this->node_public_key = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `node_public_key`\n\t\t\t\tFROM `" . DB_PREFIX . "miners_data`\n\t\t\t\tWHERE `user_id` = {$this->tx_data['user_id']}\n\t\t\t\t", 'fetch_one');
     ////print $this->db->printsql();
     if (!$this->node_public_key) {
         return 'error user_id';
     }
     $new_pct_tx = json_decode($this->tx_data['new_pct'], true);
     if (!$new_pct_tx) {
         return 'error $new_pct_tx';
     }
     // раньше не было рефских
     if (isset($this->block_data['block_id']) && $this->block_data['block_id'] <= 77951) {
         $new_pct_tx['currency'] = $new_pct_tx;
     } else {
         if (!isset($new_pct_tx['currency'], $new_pct_tx['referral'])) {
             return 'error currency referral';
         }
     }
     if (!is_array($new_pct_tx['currency'])) {
         return 'error $new_pct_tx[currency])';
     }
     // проверим, верно ли указаны ID валют
     $currency_ids_sql = '';
     $count_currency = 0;
     foreach ($new_pct_tx['currency'] as $id => $_data) {
         $currency_ids_sql .= $id . ',';
         $count_currency++;
     }
     $currency_ids_sql = substr($currency_ids_sql, 0, -1);
     $count = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT count(`id`)\n\t\t\t\tFROM `" . DB_PREFIX . "currency`\n\t\t\t\tWHERE `id` IN ({$currency_ids_sql})\n\t\t\t\t", 'fetch_one');
     if ($count != $count_currency) {
         return 'error count_currency';
     }
     // проверяем подпись
     $for_sign = "{$this->tx_data['type']},{$this->tx_data['time']},{$this->tx_data['user_id']},{$this->tx_data['new_pct']}";
     $error = self::checkSign($this->node_public_key, $for_sign, $this->tx_data['sign'], true);
     if ($error) {
         return $error;
     }
     // проверим, прошло ли 2 недели с момента последнего обновления pct
     $pct_time = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT max(`time`)\n\t\t\t\tFROM `" . DB_PREFIX . "pct`", 'fetch_one');
     if ($this->tx_data['time'] - $pct_time <= $this->variables['new_pct_period']) {
         return '14 day error';
     }
     // берем все голоса miner_pct
     $res = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t\t `pct`,\n\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_miner_pct`\n\t\t\t\tGROUP BY  `currency_id`, `pct`\n\t\t\t\t");
     while ($row = $this->db->fetchArray($res)) {
         $pct_votes[$row['currency_id']]['miner_pct'][$row['pct']] = $row['votes'];
     }
     // берем все голоса user_pct
     $res = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t\t `pct`,\n\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_user_pct`\n\t\t\t\tGROUP BY  `currency_id`, `pct`\n\t\t\t\t");
     while ($row = $this->db->fetchArray($res)) {
         $pct_votes[$row['currency_id']]['user_pct'][$row['pct']] = $row['votes'];
     }
     debug_print($pct_votes, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     $PctArray = ParseData::getPctArray();
     $new_pct = array();
     foreach ($pct_votes as $currency_id => $data) {
         // определяем % для майнеров
         $pct_arr = ParseData::makePctArray($data['miner_pct']);
         $key = get_max_vote($pct_arr, 0, 390, 100);
         $new_pct['currency'][$currency_id]['miner_pct'] = ParseData::getPctValue($key);
         debug_print('$key miner_pct=' . $key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         // определяем % для юзеров
         $pct_arr = ParseData::makePctArray($data['user_pct']);
         // раньше не было завимости юзерского % от майнерского
         if (isset($this->block_data['block_id']) && $this->block_data['block_id'] <= 95263) {
             $user_max_key = 390;
         } else {
             $pct_y = array_search($new_pct['currency'][$currency_id]['miner_pct'], $PctArray);
             debug_print('miner_pct $pct_y=' . $pct_y, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
             $max_user_pct_y = round($pct_y / 2, 2);
             debug_print('$max_user_pct=' . $max_user_pct_y, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
             $user_max_key = find_user_pct($max_user_pct_y);
             debug_print('$user_max_key=' . $user_max_key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
             // отрезаем лишнее, т.к. поиск идет ровно до макимального возможного, т.е. до miner_pct/2
             $pct_arr = del_user_pct($pct_arr, $user_max_key);
             debug_print('$user_$pct_arr=' . print_r_hex($pct_arr), __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         }
         $key = get_max_vote($pct_arr, 0, $user_max_key, 100);
         debug_print('$key user_pct=' . $key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         $new_pct['currency'][$currency_id]['user_pct'] = ParseData::getPctValue($key);
         debug_print('user_pct=' . $new_pct['currency'][$currency_id]['user_pct'], __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         debug_print('user pct y=' . array_search($new_pct['currency'][$currency_id]['user_pct'], $PctArray), __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     }
     // раньше не было рефских
     if (isset($this->block_data['block_id']) && $this->block_data['block_id'] <= 77951) {
         $new_pct = $new_pct['currency'];
     } else {
         $ref_levels = array('first', 'second', 'third');
         for ($i = 0; $i < sizeof($ref_levels); $i++) {
             $level = $ref_levels[$i];
             $votes_referral = array();
             // берем все голоса
             $res = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\t\t\tSELECT `{$level}`,\n\t\t\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\t\t\tFROM `" . DB_PREFIX . "votes_referral`\n\t\t\t\t\t\tGROUP BY  `{$level}`\n\t\t\t\t\t\t");
             while ($row = $this->db->fetchArray($res)) {
                 $votes_referral[$row[$level]] = $row['votes'];
             }
             $new_pct['referral'][$level] = get_max_vote($votes_referral, 0, 30, 10);
         }
     }
     debug_print($new_pct, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     $json_data = json_encode($new_pct);
     debug_print($json_data, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     debug_print($this->tx_data['new_pct'], __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     if ($this->tx_data['new_pct'] != $json_data) {
         return 'new_pct error ' . $json_data;
     }
 }