public function ajax_session() { $this->cache(false); $static = Configure::read('site.static'); $base = Configure::read('site.prefix'); $user = User::getInstance(); App::import('vendor', 'inc/wrapper'); $wrapper = Wrapper::getInstance(); $ret = $wrapper->user($user); $ret['is_login'] = $user->userid != 'guest'; $ret['forum_totol_count'] = Forum::getOnlineNum(); $ret['forum_user_count'] = Forum::getOnlineUserNum(); $ret['forum_guest_count'] = Forum::getOnlineGuestNum(); App::import("vendor", "model/mail"); $info = MailBox::getInfo($user); $ret['new_mail'] = $info['newmail']; $ret['full_mail'] = $info['full']; if (Configure::read('refer.enable')) { App::import('vendor', 'model/refer'); $ret['new_at'] = $ret['new_reply'] = false; try { if ($user->getCustom('userdefine1', 2)) { $refer = new Refer($user, Refer::$AT); $ret['new_at'] = $refer->getNewNum(); } if ($user->getCustom('userdefine1', 3)) { $refer = new Refer($user, Refer::$REPLY); $ret['new_reply'] = $refer->getNewNum(); } } catch (ReferNullException $e) { } } $this->set('no_html_data', $ret); }
public function beforeRender() { if ($this->ByrSession->isLogin) { $u = User::getInstance(); $login = true; $id = $u->userid; $isAdmin = $u->isAdmin(); App::import("vendor", "model/mail"); $info = MailBox::getInfo($u); $info['new_mail'] = $info['newmail']; $info['full_mail'] = $info['full']; $info['newAt'] = $info['newReply'] = false; if (Configure::read('refer.enable')) { App::import('vendor', 'model/refer'); try { if ($u->getCustom('userdefine1', 2)) { $refer = new Refer($u, Refer::$AT); $info['newAt'] = $refer->getNewNum(); } if ($u->getCustom('userdefine1', 3)) { $refer = new Refer($u, Refer::$REPLY); $info['newReply'] = $refer->getNewNum(); } } catch (ReferNullException $e) { } } $this->set($info); } else { $login = false; $id = "guest"; $isAdmin = false; } $this->_initAsset(); $site = Configure::read("site"); $this->set("domain", $site['domain']); $this->set("static", $site['static']); $this->set("siteName", $site['name'] . "手机版"); $this->set("webTitle", empty($this->title) ? $site['name'] . "手机版" : $this->title); $this->set("encoding", $this->encoding); $this->set("home", $site['home']); $this->set("base", $this->base); $this->set("mbase", $this->base . $this->_mbase); $this->set("msg", ECode::msg($this->_msg)); $this->set("pos", $this->notice); $this->set("css", $this->css); $this->set("islogin", $login); $this->set("id", $id); $this->set("isAdmin", $isAdmin); }
function __construct($code, $type = 'after') { $this->stockCode = $code; $this->rightType = Refer::isSockCode($code) ? $type : 'normal'; $this->dataVersion = Config::get('Day.Version'); $this->dataFile = DATA_PATH . 'day/' . $this->dataVersion . '/' . $this->rightType . '/' . $this->stockCode . '.txt'; }
public static function updateDoctor() { self::$log->debugLog("Begin Update Ths Doctor"); //$i = 2; $list = Refer::getStock(); foreach ($list as $item) { //if (--$i < 0 ) break; if ('sz300033' == $item['code']) { continue; } $numCode = substr($item['code'], 2); $url = "http://doctor.10jqka.com.cn/" . $numCode . '/'; self::$log->debugLog($item['name'], $item['code'], $url); $html = ThsDoctorKeeper::fetchSingleThsDoctor($url, $numCode); if ($html) { self::$log->debugLog($item['name'], $item['code'], "Fetch ThsDoctor Success"); $now = ThsDoctorKeeper::parseThsDoctorHtml($html); if ($now) { $tdd = new ThsDoctorData($item['code']); $last = $tdd->getThsDoctorData(); //print_r($last); if ($last) { $updata = ThsDoctorKeeper::mergeThsDoctorUpdate($last, $now); ThsDoctorKeeper::addThsDoctor($tdd->getDataFile(), $updata); } else { $updata = $now; ThsDoctorKeeper::putThsDoctor($tdd->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update ThsDoctor Success"); } else { self::$log->errorLog($item['name'], $item['code'], "Parse ThsDoctor Failed"); self::$tmp->putTmpContent('thsdoctor.duty.failed', join(":", $item) . "|", FILE_APPEND); } $now = ThsDoctorKeeper::parseThsDoctorMesHtml($html); if ($now) { $tdmd = new ThsDoctorMesData($item['code']); $last = $tdmd->getThsDoctorMesData(); //print_r($last); if ($last) { $updata = ThsDoctorKeeper::mergeThsDoctorMesUpdate($last, $now); ThsDoctorKeeper::addThsDoctor($tdmd->getDataFile(), $updata); } else { $updata = $now; ThsDoctorKeeper::putThsDoctor($tdmd->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update ThsDoctorMes Success"); } else { self::$log->errorLog($item['name'], $item['code'], "Parse ThsDoctorMes Failed"); } } else { self::$log->errorLog($item['name'], $item['code'], "Fetch ThsDoctor Failed"); self::$tmp->putTmpContent('thsdoctor.duty.failed', join(":", $item) . "|", FILE_APPEND); } } self::$log->debugLog("Finish Update Ths Doctor"); }
public static function getStock($from = 0) { if (!self::$_path) { self::load(); } if (!self::$_stockRefer) { self::$_stockRefer = self::_getRefer(self::$_stock); } return self::$_stockRefer; }
public static function testReferData() { $rows = Refer::getStock(); $columns = array_keys($rows[0]); for ($i = 0; $i < sizeof($columns); $i++) { $t = str_replace('_', ' ', $columns[$i]); $columns[$i] = array('title' => $t, 'data' => $columns[$i]); } echo json_encode(array('columns' => $columns, 'rows' => $rows)); }
public static function show() { parent::show(); $allRefer = Refer::getAll(); for ($i = 0; $i < sizeof($allRefer); $i++) { $allRefer[$i]['url'] = Url::getBasePhp('Stock') . '?code=' . $allRefer[$i]["code"]; } self::setTitle('Stock List -- ForeShadow (Alpha)'); self::$smarty->assign('refer', $allRefer); self::$smarty->display('Search.tpl'); }
public static function updateGbbq() { self::$log->debugLog("Begin Update Gbbq"); /* $url = "http://stockdata.stock.hexun.com/2009_fhzzgb_000001.shtml"; $json = DayKeeper::curlXueqiuJson($url, self::$tmp->getTmpFile('day.duty.cookie')); $json = DayKeeper::parseXueqiuJson($json); var_dump($json); */ $p = -1; $list = Refer::getStock(); //得到进度 $content = self::$tmp->getTmpContent('gbbq.step.process'); $content = explode('===', $content); $lastProcess = $content && $content[0] ? $content[0] : -1; foreach ($list as $item) { $p++; //if ($p >= 3 ) break; if ($p < $lastProcess) { continue; } self::$tmp->putTmpContent('gbbq.step.process', $p . '===' . $item['code'] . ' ' . $item['name']); $numCode = substr($item['code'], 2); $url = "http://stockdata.stock.hexun.com/2009_fhzzgb_" . $numCode . ".shtml"; self::$log->debugLog($item['name'], $item['code'], $url); $html = GbbqKeeper::fetchSingleGbbq($url, $numCode); if ($html) { self::$log->debugLog($item['name'], $item['code'], "Fetch Gbbq Success"); $now = GbbqKeeper::parseGbbqHtml($html); if ($now) { $gd = new GbbqData($item['code']); $last = $gd->getGbbqData(); if ($last) { $updata = GbbqKeeper::mergeUpdate($last, $now); GbbqKeeper::addGbbq($gd->getDataFile(), $updata); } else { $updata = $now; GbbqKeeper::putGbbq($gd->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update Gbbq Success"); self::$tmp->putTmpContent('gbbq.step.success', join(":", $item) . "|", FILE_APPEND); } else { self::$log->errorLog($item['name'], $item['code'], "Parse Gbbq Failed"); self::$tmp->putTmpContent('gbbq.step.failed', join(":", $item) . "|", FILE_APPEND); } } else { self::$log->errorLog($item['name'], $item['code'], "Fetch Gbbq Failed"); self::$tmp->putTmpContent('gbbq.step.failed', join(":", $item) . "|", FILE_APPEND); } } self::$log->debugLog("Finish Update Gbbq"); self::$tmp->putTmpContent('gbbq.step.process', ''); }
public static function calcRange($start, $end, $n) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_' . $n . '_Good.Table.txt'; $limiter = 2; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$limiter < 0 ) break; $stkT = array('name' => '', 'code' => '', 'MaxRange' => 0, 'DayNum' => 0); $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DayData($stkL['code'], 'before'); if (!$dd->prepareData()) { continue; } $day = $dd->getDayPeriod($start, $end, $n - 1); //var_dump($day); if (!$day) { continue; } $MaxRange = -2; for ($i = 0; $i < $n / 2; $i++) { $daySlice = array_slice($day, $i, $n); if (!$daySlice) { continue; } $dMax = LogicOperation::highValue($daySlice, 'close'); $dMin = $daySlice[0]['close']; $dR = ceil(($dMax - $dMin) / $dMin * 100) / 100; $MaxRange = $MaxRange < $dR ? $dR : $MaxRange; } $stkT['MaxRange'] = $MaxRange; $stkT['DayNum'] = sizeof($day); $tdd = new ThsDoctorData($stkL['code']); $t = $tdd->prepareData() ? $tdd->getDayPeriod($start, $end) : array(); //message_score $stkT['message_score_max'] = LogicOperation::highValue($t, 'message_score'); $stkT['message_score_min'] = LogicOperation::lowValue($t, 'message_score'); $stkT['message_score_dis'] = $stkT['message_score_max'] - $stkT['message_score_min']; //basic_score $stkT['basic_score_max'] = LogicOperation::highValue($t, 'basic_score'); $stkT['basic_score_min'] = LogicOperation::lowValue($t, 'basic_score'); //total_score $stkT['total_score_max'] = LogicOperation::highValue($t, 'total_score'); $stkT['total_score_min'] = LogicOperation::lowValue($t, 'total_score'); //var_dump($stkT); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function show() { parent::show(); $stockInfo = array(); $stockInfo["code"] = $_GET["code"]; $i = Refer::searchCode($stockInfo["code"]); if (!$i) { exit(0); } $stockInfo["name"] = $i['name']; $stockInfo["spell"] = $i['spell']; $stockInfo["period"] = null; /* * $stockInfo["period"] = array('start'=>strtotime("Thu May 28 00:00:00 +0800 2015")*1000, 'end'=>strtotime("Mon Dec 23 00:00:00 +0800 2015")*1000); */ $stockInfo["right"] = "before"; $gd = new GbbqData($stockInfo["code"]); $gbbq = $gd->getGbbqLabel(); $stockInfo['gbbq'] = $gbbq; $dd = new DdeData($stockInfo["code"]); $dde = $dd->getDdeData(); $stockInfo['dde'] = $dde; $tdd = new ThsDoctorData($stockInfo["code"]); $ths = $tdd->getThsDoctorData(); $stockInfo['ths'] = $ths; $ld = new LhbData($stockInfo["code"]); $lhb = $ld->getLhbData(); $stockInfo['lhb'] = $lhb; $rd = new RateData($stockInfo["code"]); $rate = RateData::filterBuy($rd->getRateData()); $stockInfo['rate'] = $rate; $stockInfo['day'] = array(); $typeRight = array("normal", "before", "after"); foreach ($typeRight as $aTypeRight) { $dd = new DayData($stockInfo["code"], $aTypeRight); if ($dd->prepareData()) { $stockInfo['day'][$aTypeRight] = $dd->getStockData(); } else { $stockInfo['day'][$aTypeRight] = null; } } self::setTitle($stockInfo['name'] . '(' . $stockInfo['code'] . ') - Stock -- ForeShadow (Alpha)'); self::$smarty->assign('historyUrl', Url::getBasePhp('History')); self::$smarty->assign('favoriteUrl', Url::getBasePhp('Favorite')); self::$smarty->assign('rawData', json_encode($stockInfo)); self::$smarty->display('Chart.tpl'); }
public function delete() { if (!isset($this->params['type'])) { $this->error(ECode::$REFER_NONE); } $type = $this->params['type']; try { $refer = new Refer(User::getInstance(), $type); } catch (ReferNullException $e) { $this->error(ECode::$REFER_NONE); } $index = intval($this->params['url']['index']); $refer->delete(intval($index)); $this->redirect($this->_mbase . "/refer/{$type}?m=" . ECode::$REFER_DELETEOK); }
/** * Отображает страницу Refer */ public function actionIndex() { $listBanners = Banners::getBannersOnSite('rand'); //если существует дневной бонус то пересчитываем его if (isset($_SESSION['dailyBonus'])) { Site::changeDailyBonus(); } //получаем баланс и бонус $balance = isset($_SESSION['id']) ? Site::getBalance() : 0; $bonus = isset($_SESSION['id']) ? $_SESSION['bonus'] : 0; $refNum = isset($_SESSION['id']) ? Refer::gerRefNumber() : 0; $refBonus = isset($_SESSION['id']) ? Refer::getRefBonus() : 0; require_once ROOT . '/' . Config::VIEW . 'refer/index.php'; return true; }
/** * Осуществляет перевод временного выйгрыша денег и бонусов в постоянный баланс */ public function actionClaim() { //проверка капчи if (empty(Validate::checkCaptcha($_POST['captcha']))) { $get = '?res=fail_captcha'; } //условия для перевода денег и бонуса с временного выйгрыша в баланс if ((!empty($_SESSION['claimAmount']) || !empty($_SESSION['bonusMinutes'])) && (empty($_SESSION['numChance']) || $_SESSION['numChance'] == Config::NUM_CHANCE) && !isset($get)) { //установливаем новые значени бонуса, баланса и др. у игрока $gameBalance = Site::setDataGame(); //если игрок был зарегин по реф ссылке, то процент от его выйгрыша идет рефереру if (!empty($_SESSION['parentId'])) { Refer::setRefBonus($gameBalance); } $get = ''; } header('Location: ' . Config::ADDRESS . $get); }
public static function calcDdeNum($start, $end) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_DdeNum.Table.txt'; $i = 2; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$i < 0 ) break; $stkT = array('name' => '', 'code' => '', 'DdxNum' => 0, 'DdxPer' => 0, 'DdzNum' => 0, 'DdzPer' => 0, 'TddzNum' => 0, 'TddzPer' => 0, 'TotalNum' => 0, 'TotalPer' => 0, 'DayNum' => 0); $stkT['name'] = '<a target="_blank" href="' . Url::getPhpUri('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DdeData($stkL['code']); if (!$dd->prepareData()) { continue; } $dde = $dd->getDayPeriod($start, $end, 1); //var_dump($dde); if (!$dde) { continue; } foreach ($dde as $d) { //echo $d['ddx']. '('; //echo ($d['ddx'] > 0). ')'; if ($d['ddx'] > 0) { $stkT['DdxNum']++; } if ($d['ddz'] > 0) { $stkT['DdzNum']++; } if ($d['tddz'] > 0) { $stkT['TddzNum']++; } } $stkT['DayNum'] = sizeof($dde); $stkT['DdxPer'] = ceil($stkT['DdxNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['DdzPer'] = ceil($stkT['DdzNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['TddzPer'] = ceil($stkT['TddzNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['TotalNum'] = $stkT['DdxNum'] + $stkT['TddzNum'] + $stkT['TddzNum']; $stkT['TotalPer'] = ceil($stkT['TotalNum'] / $stkT['DayNum'] / 3 * 10000) / 10000; //var_dump($stkT); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function calcMessJump() { $resultFile = self::$thisTaskDataPath . 'Pick_MessJump.Table.txt'; $limiter = 10; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$limiter < 0 ) break; $stkT = array(); $tdd = new ThsDoctorData($stkL['code']); if (!$tdd->prepareData()) { continue; } $ths_2 = $tdd->getLastPeriod(1, true, 2); if (!$ths_2) { continue; } //var_dump($ths_2); $ths_x = $tdd->getLastPeriod(40, true, 10); if (!$ths_x) { continue; } //var_dump($ths_x); if ($ths_2[1]['message_score'] - $ths_2[0]['message_score'] <= 0) { continue; } $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; //message_score in yesterday and today $stkT['mess_score_yesterday'] = $ths_2[0]['message_score']; $stkT['mess_score_today'] = $ths_2[1]['message_score']; $stkT['mess_score_change'] = $ths_2[1]['message_score'] - $ths_2[0]['message_score']; //message_score in 40 days $stkT['mess_score_max_40d'] = LogicOperation::highValue($ths_x, 'message_score'); $stkT['mess_score_min_40d'] = LogicOperation::lowValue($ths_x, 'message_score'); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function EBK2List($importFile, $exportFile) { if ($content = BaseFile::getFileContent($importFile)) { $rows = explode("\r\n", $content); $codeArr = array(); foreach ($rows as $row) { if (!$row) { continue; } $r = "/[0-9.]{7}/"; preg_match($r, $row, $k); $t = CommonInfo::EBK2Code($k[0]); if ($t) { $codeArr[] = array('code' => $t); } } } else { return false; } $refer = Refer::getAll(); $codeNameArray = CommonInfo::CodeArray2CodeNameArray($codeArr, $refer); self::putList($exportFile, $codeNameArray); }
public static function updateTmpDay() { self::$log->debugLog("Begin Update Tmp Day"); //读取Tmp文件中股票信息 $list = self::$tmp->getTmpContent('day.duty.failed'); $list = explode('|', $list); //print_r($list); //echo self::$tmp->getTmpContent('day.duty.failed'); self::$tmp->newTmpFile('day.duty.failed'); $rights = array('before', 'normal', 'after'); foreach ($list as $itemS) { //echo $item['code']; $tt = explode(':', $itemS); if (empty($tt) || empty($tt[0])) { continue; } $item = array('code' => $tt[0], 'name' => $tt[1], 'spell' => $tt[2]); if (Refer::isSockCode($item['code'])) { foreach ($rights as $type) { self::resetSingleDay($item, $type); } } else { self::resetSingleDay($item, 'normal'); } } self::$log->debugLog("Finish Update Tmp Day"); }
public function ajax_delete() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['type'])) { $this->error(ECode::$REFER_NONE); } $type = $this->params['type']; try { $refer = new Refer(User::getInstance(), $type); } catch (ReferNullException $e) { $this->error(ECode::$REFER_NONE); } if (isset($this->params['form']['all'])) { //delete all $refer->delete(); } else { //delete normal foreach ($this->params['form'] as $k => $v) { if (!preg_match("/m_/", $k)) { continue; } $num = split("_", $k); $refer->delete(intval($num[1])); } } $ret['ajax_code'] = ECode::$REFER_DELETEOK; $ret['default'] = "/refer/{$type}"; $ret['list'][] = array("text" => $refer->getDesc(), "url" => "/refer/{$type}"); $this->set('no_html_data', $ret); }
public static function calcV2P($start, $end) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_Vol2Price.Table.txt'; $limiter = 200; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$limiter < 0 ) break; $stkT = array(); $stkT['name'] = '<a target="_blank" href="' . Url::getBasePhp('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DayData($stkL['code'], 'before'); if (!$dd->prepareData()) { continue; } $day = $dd->getDayPeriod($start, $end, 3); if (!$day) { continue; } //var_dump($day); $s_day = 0; $s_V2P = 0; for ($i = 2; $i < count($day); $i++) { //处理当日涨跌停 $is_zt = ($day[$i]["high"] - $day[$i - 1]["close"]) / $day[$i - 1]["close"]; $is_dt = ($day[$i - 1]["close"] - $day[$i]["low"]) / $day[$i - 1]["close"]; $valid_vol = $day[$i]["volume"] / $day[$i - 1]["volume"]; //涨跌停 并且 量小于0.3 不参与计算 if (($is_zt > 1.09 || $is_dt < 0.9) && $valid_vol < 0.3) { continue; } //处理前日涨跌停 $is_zt = ($day[$i - 1]["high"] - $day[$i - 2]["close"]) / $day[$i - 2]["close"]; $is_dt = ($day[$i - 2]["close"] - $day[$i - 1]["low"]) / $day[$i - 2]["close"]; $valid_vol = $day[$i - 1]["volume"] / $day[$i - 2]["volume"]; //涨跌停 并且 量小于0.3 不参与计算 if (($is_zt > 1.09 || $is_dt < 0.9) && $valid_vol < 0.3) { continue; } //处理量太小不值得计算 $k1 = ($day[$i]["volume"] - $day[$i - 1]["volume"]) / $day[$i - 1]["volume"] * 100; $k2 = ($day[$i]["volume"] - $day[$i - 2]["volume"]) / $day[$i - 2]["volume"] * 100; if (abs($k1) < 20 && abs($k2) < 20) { continue; } //计算V2P公式 //计算量相关 $q2 = ($day[$i]["volume"] - $day[$i - 1]["volume"]) / $day[$i - 1]["volume"] * 100; if ($q2 < -100) { $q2 = -100; } if ($q2 > 100) { $q2 = 100; } //计算价格相关 $chg = $day[$i]["chg"] * 100; $q1 = $chg; if ($chg > 60) { $q1 = 16; } if ($chg <= 60 && $chg > 30) { $q1 = ($chg - 30) / 15 + 13; } if ($chg <= 30 && $chg > 10) { $q1 = ($chg - 10) / 7 + 10; } if ($chg < -60) { $q1 = -16; } if ($chg >= -60 && $chg < -30) { $q1 = ($chg + 30) / 15 - 13; } if ($chg >= -30 && $chg < -10) { $q1 = ($chg + 10) / 7 - 10; } $q1 = $q1 > 0 ? ceil($q1 + 100) : ceil($q1 - 100); $V2P = $q1 * $q2; if ($chg <= 10 && $chg >= -10) { $V2P = abs(110 * $q2); } // 统计 $s_day++; $s_V2P += $V2P; } $stkT['Vol2Price'] = $s_day ? ceil($s_V2P / $s_day) : 0; $stkT['ValidDayNum'] = $s_day; $stkT['TotalDayNum'] = count($day); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function testRefer() { echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body>'; $b = Refer::getStock(); var_dump($b); }
public static function CodeArray2ReferArray($codeArray, $refer = null) { if (!$refer) { $refer = Refer::getAll(); } $codeRefer = array(); foreach ($refer as $a) { $codeRefer[$a['code']] = $a; } $codeNameArray = array(); foreach ($codeArray as $a) { if (array_key_exists($a['code'], $codeRefer)) { $codeNameArray[] = $codeRefer[$a['code']]; } } return $codeNameArray; }
public static function updateLhb() { //日志文件 self::$log = new Log(LOG_PATH, __FILE__); //临时文件 self::$tmp = new Tmp(TMP_PATH); self::$tmp->addTmp('lhb.duty.time', false); self::$log->debugLog("Begin Update Lhb"); echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body>'; //得到上次更新时间 $lastTime = self::$tmp->getTmpContent('lhb.duty.time'); //校验上次更新时间 $pattern = "/[0-9]{4}-[0-9]{2}-[0-9]{2}/"; preg_match($pattern, $lastTime, $k); $lastTime = $k[0]; $thisTime = $lastTime; if ($lastTime) { //echo $lastTime . '<br />'; $szzs = Refer::getSH(); $dd = new DayData($szzs['code']); if ($dd->prepareData()) { $ks = $dd->getDayPeriod($lastTime, true); $list = array(); foreach ($ks as $k) { $cTime = $k['time']; if ($cTime > $lastTime) { //echo $cTime. '<br />'; $url = "http://data.eastmoney.com/stock/lhb/" . $cTime . ".html"; self::$log->debugLog('Get Url', $url); $html = LhbKeeper::fetchSinglePage($url); self::$log->debugLog("Fetch Url Page Success"); $updata = LhbKeeper::parseLhbHtml($html, $cTime); if ($updata) { $list = array_merge($list, $updata); } $thisTime = $cTime; } } //var_dump($list); if ($list) { foreach ($list as $new) { $ld = new LhbData($new[0]); $data = $ld->getLhbData(); if (!$data) { LhbKeeper::addLhb($ld->getDataFile(), array($new[1])); self::$log->noticeLog("Update", $new[0], $new[1]['time'], $new[1]['reason'], "Success"); continue; } $t = end($data)['time']; //echo $new[1]['time']. '>'. $t. '<br />'; if ($new[1]['time'] > $t) { LhbKeeper::addLhb($ld->getDataFile(), array($new[1])); self::$log->noticeLog("Update", $new[0], $new[1]['time'], $new[1]['reason'], "Success"); } } } else { self::$log->errorLog("Parse Lhb Failed"); } self::$tmp->newTmpFile('lhb.duty.time'); self::$tmp->putTmpContent('lhb.duty.time', $thisTime); self::$log->debugLog("Finish Update Lhb"); } else { self::$log->errorLog("Get Time List Failed"); } } else { self::$log->errorLog("Get LastTime Failed"); } }
public static function updateGpcxwDde() { //日志文件 self::$log = new Log(LOG_PATH, __FILE__); //临时文件 self::$tmp = new Tmp(TMP_PATH); self::$tmp->addTmp('dde.gpcxw.duty.cookie', false); self::$tmp->addTmp('dde.gpcxw.duty.failed', true); self::$tmp->addTmp('dde.gpcxw.duty.process', false); self::$log->debugLog("Begin Update Gpcxw Dde"); $host = 'www.gpcxw.com'; $referer = 'baidu.com'; //首先获取cookie $url = 'http://www.gpcxw.com/ddx/000703.html'; $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); $p = -1; $list = Refer::getStock(); //得到进度 $content = self::$tmp->getTmpContent('dde.gpcxw.duty.process'); $content = explode('===', $content); $lastProcess = $content && $content[0] ? $content[0] : -1; foreach ($list as $item) { $p++; //if ($p >= 3 ) break; if ($p < $lastProcess) { continue; } self::$tmp->putTmpContent('dde.gpcxw.duty.process', $p . '===' . $item['code'] . ' ' . $item['name']); $numCode = substr($item['code'], 2); $data = 0; $dde = new DdeData($item['code']); $last = $dde->getDdeData(); //抓取页面 while (!$data) { if ($data !== 0) { sleep(1); } $data = false; //抓取最新的数据 $ran = mt_rand(); $ran = '0.' . $ran . $ran; $referer = 'http://www.gpcxw.com/ddx/data2/dde.htm?code=' . $numCode; $url = 'http://www.gpcxw.com/ddx/data2/data2.htm?code=' . $numCode . '&m=' . $ran; self::$log->debugLog($item['name'], $item['code'], 'new', $url); $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); if (!$content) { continue; } $content = iconv('GB2312', 'UTF-8//IGNORE', $content); //处理停牌 if (substr($content, 0, 7) == 'tingpai') { $data = false; break; } //读取最新的数据 $cuts = explode('==', $content); if (sizeof($cuts) != 3) { continue; } $k = explode('<=>', $cuts[1]); $k = end($k); $k = explode(' ', $k); $new = $k[0]; $k = explode('<=>', $cuts[2]); $k = end($k); if (substr($k, strlen($k) - 1) != '|') { $k .= '|'; } $new = $k . $new; //新增的个股 需要抓取历史数据 if (!$last) { //抓取历史的数据 $k = explode('<=>', $cuts[0]); $lastfilemtime = end($k); $ran = mt_rand(); $ran = '0.' . $ran . $ran; $referer = $url; $url = 'http://www.gpcxw.com/ddx/data2/data2.htm?code=' . $numCode . '&m=' . $ran . '&lastfilemtime=' . $lastfilemtime . '&getlsold=1'; self::$log->debugLog($item['name'], $item['code'], 'history', $url); $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); if (!$content) { continue; } $content = iconv('GB2312', 'UTF-8//IGNORE', $content); //读取历史数据 $cuts = explode('<=>', $content); if (sizeof($cuts) != 2) { continue; } $k = end($cuts); if (substr($k, strlen($k) - 1) != '|') { $k .= '|'; } $new = $k . $new; } $data = DdeKeeper::parseGpcxwDde($new); } //print_r($data); //处理停牌 if (!$data) { self::$log->noticeLog($item['name'], $item['code'], "TingPai"); continue; } if ($last) { $updata = DdeKeeper::mergeUpdate($last, $data); DdeKeeper::addDde($dde->getDataFile(), $updata); } else { $updata = $data; DdeKeeper::putDde($dde->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update Gpcxw Dde Success"); } self::$log->debugLog("Finish Update Gpcxw Dde"); self::$tmp->putTmpContent('dde.gpcxw.duty.process', ''); }
public function info() { if (!isset($this->params['type'])) { $this->error(ECode::$REFER_NONE); } $type = $this->params['type']; $u = User::getInstance(); try { $refer = new Refer($u, $type); } catch (ReferNullException $e) { $this->error(ECode::$REFER_NONE); } $data['enable'] = $u->getCustom('userdefine1', $type == Refer::$AT ? 2 : 3) == 1; $data['new_count'] = $refer->getNewNum(); $wrapper = Wrapper::getInstance(); $this->set('data', $data); }