'0', 'daily_staking_value' => '0', 'planet' => array( 'type' => self::PLANET_TYPE, 'is_open' => 1, 'staked_quant' => 0, 'claim_rewards' => 0, 'daily_rewards' => 0, 'staking_value' => 0, 'maturity_quant' => 0, ), 'badge' => array( 'type' => self::BADGE_TYPE, 'is_open' => 1, 'staked_quant' => 0, 'claim_rewards' => 0, 'daily_rewards' => 0, 'staking_value' => 0, 'maturity_quant' => 0, ), 'cec' => array( 'type' => self::CEC_TYPE, 'is_open' => 0, 'staked_quant' => 0, 'claim_rewards' => 0, 'daily_rewards' => 0, 'staking_value' => 0, 'maturity_quant' => 0, ), ); $rows = Stacking::all(myself()->_getAddress()); $this->fillStackingInfo($info['planet'], $rows); $this->fillStackingInfo($info['badge'], $rows); $this->fillStackingInfo($info['cec'], $rows); myself()->_rspData($info); } private function fillStackingInfo($info, $rows) { foreach ($rows as $row) { switch ($info['type']) { case self::PLANET_TYPE: { if ($row['status'] == Stacking::STAKING_STATUS) { if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { $info['staked_quant'] += $row['stacked_num']; } else { $info['maturity_quant'] += $row['stacked_num']; } $info['staking_value'] += $row['ceg_value']; } } break; case self::BADGE_TYPE: { if ($row['status'] == Stacking::STAKING_STATUS) { if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { $info['staked_quant'] += $row['stacked_num']; } else { $info['maturity_quant'] += $row['stacked_num']; } $info['staking_value'] += $row['ceg_value']; } } break; case self::CEC_TYPE: { } break; } } } public function stacking() { $type = getReqVal('type', ''); $stackedQuant = 0; $items = array(); $rows = Stacking::all(myself()->_getAddress()); foreach ($rows as $row) { if ($row['status'] == Stacking::STAKING_STATUS) { $info = array(); $info['token_id'] = $row['token_id']; $info['token_type'] = $row['token_type']; $info['contract_address'] = $row['contract_address']; $info['net_id'] = $row['net_id']; $info['start_time'] = $row['start_time']; $info['stake_time'] = $row['stake_time']; $info['txhash'] = $row['txhash']; $info['item_id'] = $row['item_id']; $info['stacked_days'] = intval((myself()->_getNowDaySeconds() - myself()->_getDaySeconds($row['start_time'])) / 3600 / 24); $info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']); array_push($items, $info); } } myself()->_rspData(array( 'type' => $type, 'stacked_quant' => $stackedQuant, 'items' => $items )); } public function history() { $items = array(); $fromTime = getReqVal('from_time', ''); $toTime = getReqVal('to_time', ''); $rows = Stacking::all(myself()->_getAddress()); foreach ($rows as $row) { if ($row['status'] == Stacking::UNSTAKE_STATUS) { $info = array(); $info['token_id'] = $row['token_id']; $info['token_type'] = $row['token_type']; $info['contract_address'] = $row['contract_address']; $info['net_id'] = $row['net_id']; $info['start_time'] = $row['start_time']; $info['stake_time'] = $row['stake_time']; $info['txhash'] = $row['txhash']; $info['item_id'] = $row['item_id']; $info['stacked_days'] = intval( (myself()->_getNowDaySeconds() - myself()->_getDaySeconds($row['start_time']) + 3600 *24) / 3600 / 24); $info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']); $info['total_rewards'] = $row['stacked_days'] *$info['daily_rewards']; array_push($items, $info); } } myself()->_rspData(array( 'items' => $items )); } }