Example #1
0
 /**
  * 同步当前股票信息
  */
 public function actionSyncStock()
 {
     $sleep = 5;
     while (true) {
         try {
             $hourm = intval(date('Hm'));
             if ($hourm > 900 && $hourm < 1135 || $hourm > 1300 && $hourm < 1510) {
                 $pici = time();
                 $url_arr = ['http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=10000&sort=changepercent&asc=0&node=sz_a&symbol=&_s_r_a=page&time=' . time(), 'http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=10000&sort=changepercent&asc=0&node=sh_a&symbol=&_s_r_a=page'];
                 foreach ($url_arr as $url) {
                     $return_arr = Common::reqUrl($url, [], true, 30, true);
                     if ($return_arr['content']) {
                         $arr = Common::ext_json_decode(mb_convert_encoding($return_arr['content'], "utf-8", "gbk"), true);
                         if ($arr) {
                             foreach ($arr as $row) {
                                 $Stock = Stock::find()->where(['symbol' => $row['symbol']])->one();
                                 if ($Stock) {
                                     $Stock->scenario = 'update';
                                 } else {
                                     $Stock = new Stock(['scenario' => 'create']);
                                     $Stock->updated_at = time();
                                 }
                                 $save_arr = [];
                                 $save_arr['Stock'] = $row;
                                 if ($Stock->id && $row['trade'] != $Stock->trade) {
                                     $StockLog = new StockLog(['scenario' => 'create']);
                                     $StockLog->stock_id = $Stock->id;
                                     $StockLog->pici = $pici;
                                     $StockLog->setAttributes($Stock->attributes);
                                     $StockLog->id = '';
                                     $StockLog->save();
                                 }
                                 if ($Stock->load($save_arr) && $Stock->save()) {
                                 }
                             }
                         }
                     }
                 }
             }
             sleep($sleep);
         } catch (Exception $e) {
         }
     }
 }
Example #2
0
?>
          </ul>
        </section>
        <!-- /.sidebar -->
      </aside>
  <?php 
echo Alert::widget();
?>
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1><?php 
echo Html::encode($this->title);
?>
 <small><?php 
echo date('Y年m月d日 H:i:s') . '  星期' . Common::getWeek();
?>
</small></h1>
      <?php 
echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
?>
    <!--
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Forms</a></li>
        <li class="active">General Elements</li>
      </ol> -->
    </section>

    <section class="content" id="layouts-content-div">
      <div class="row">