Exemplo n.º 1
0
 /**
  * 获取制定基金类型名称
  * @param $num
  * @return string
  */
 public static function getTypeName($num)
 {
     $fund = FundNum::find()->where(['fund_num' => $num])->one();
     if (!$fund) {
         return '';
     }
     $type = $fund->fund_type;
     switch ($type) {
         case self::TYPE_ZQ:
             $name = '债券';
             break;
         case self::TYPE_GG:
             $name = '股票';
             break;
         case self::TYPE_ZS:
             $name = '指数';
             break;
         case self::TYPE_HH:
             $name = '混合';
             break;
         case self::TYPE_BB:
             $name = '保本';
             break;
         default:
             $name = '';
     }
     return $name;
 }
Exemplo n.º 2
0
                <th>年</th>
                <th>月</th>
                <th>幅度</th>
            </tr>
            </thead>
           <tbody>
           <?php 
foreach ($datas as $data) {
    ?>
               <tr>
                   <td><?php 
    echo $data['year'];
    ?>
</td>
                   <td><?php 
    echo $data['month'];
    ?>
</td>
                   <td><?php 
    echo \common\models\FundNum::getRate($data['sum_rate']);
    ?>
</td>
               </tr>
           <?php 
}
?>
           </tbody>
        </table>
    </div>
</div>
Exemplo n.º 3
0
                    <th>rate</th>
                </tr>
            </thead>
            <tbody class="sort-tbody">
                <?php 
if ($datas) {
    ?>
                    <?php 
    foreach ($datas as $v) {
        ?>
                        <tr>
                            <td><?php 
        echo $v['fund_num'];
        ?>
</td>
                            <td><?php 
        echo \common\models\FundNum::getRate($v['rate']);
        ?>
</td>
                        </tr>
                    <?php 
    }
    ?>
                <?php 
}
?>
            </tbody>
        </table>
    </div>
</div>
Exemplo n.º 4
0
 /**
  * 查看一段时间基金排名
  * @param string $type
  * @return array|string
  */
 public function actionSort($type = '')
 {
     if (\Yii::$app->request->isPost) {
         $start = Html::encode(Yii::$app->request->post('start'));
         $end = Html::encode(Yii::$app->request->post('end'));
         if ($start && $end) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             $connection = Yii::$app->db;
             if ($type) {
                 $nums = FundNum::find()->select('fund_num')->distinct()->where(['fund_type' => $type])->asArray()->all();
                 $nums = ArrayHelper::getColumn($nums, 'fund_num');
                 $nums = '(\'' . implode('\',\'', $nums) . '\')';
                 $sql = "SELECT `fund_num`,sum(rate+0) as rate FROM fund_history WHERE fund_num IN " . $nums . " AND  ( UNIX_TIMESTAMP(`date`) BETWEEN UNIX_TIMESTAMP('" . $start . "') AND UNIX_TIMESTAMP('" . $end . "')) GROUP BY fund_num ORDER BY rate DESC LIMIT 100";
             } else {
                 $sql = "SELECT `fund_num`,sum(rate+0) as rate FROM fund_history WHERE  ( UNIX_TIMESTAMP(`date`) BETWEEN UNIX_TIMESTAMP('" . $start . "') AND UNIX_TIMESTAMP('" . $end . "')) GROUP BY fund_num ORDER BY rate DESC LIMIT 100";
             }
             $command = $connection->createCommand($sql);
             $posts = $command->queryAll();
             return $posts;
         } else {
             return '';
         }
     } else {
         return $this->render('sort', ['datas' => [], 'type' => $type]);
     }
 }
Exemplo n.º 5
0
 /**
  * ajax处理每周重复数据
  * @return array|string
  */
 public function actionGetWeekDuplicate()
 {
     $nums = FundNum::find()->select('fund_num')->distinct()->where(['fund_type' => FundNum::TYPE_HH])->asArray()->all();
     $nums = ArrayHelper::getColumn($nums, 'fund_num');
     $nums = '(\'' . implode('\',\'', $nums) . '\')';
     if (Yii::$app->request->isPost) {
         $w = Yii::$app->request->post('w');
         if (count($w) > 0) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             $posts = [];
             foreach ($w as $k => $v) {
                 if ($k == 5) {
                     break;
                 }
                 $connection = Yii::$app->db;
                 $command = $connection->createCommand("SELECT `fund_num`,WEEK(`date`) as `week`,sum(rate+0) as rate FROM fund_history WHERE fund_num IN " . $nums . " AND YEAR(`date`) = 2016 AND WEEK(`date`)=" . $v . " GROUP BY fund_num,`week` ORDER BY rate DESC LIMIT 100");
                 $posts = array_merge($posts, ArrayHelper::getColumn($command->queryAll(), 'fund_num'));
             }
             $count = array_count_values($posts);
             foreach ($count as $key => $v) {
                 if ($v !== count($w)) {
                     unset($count[$key]);
                 }
             }
             return array_keys($count);
         }
     }
     return '';
 }
Exemplo n.º 6
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\FundNum;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '自选基金';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="fund-choose-index">

    <p>
        <?php 
echo Html::a('添加自选', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', 'fund_num', ['attribute' => 'created_at', 'value' => function ($model) {
    return date('Y-m-d', $model->created_at);
}], ['header' => '累计涨幅', 'content' => function ($model) {
    return FundNum::getRate($model->getTotalRate());
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Exemplo n.º 7
0
 public function actionNum()
 {
     @set_time_limit(0);
     @ini_set('memory_limit', '1280M');
     $client = new Client();
     foreach ($this->url as $type => $u) {
         $crawler = $client->request('GET', $u);
         $result = $crawler->text();
         $result = trim($result, 'g');
         $result = trim($result, '(');
         $result = trim($result, ')');
         $data_area = json_decode($result, true);
         foreach ($data_area['data']['data'] as $key => $v) {
             $model = FundNum::find()->where(['fund_num' => $v['code'], 'fund_type' => $type])->one();
             if (!$model) {
                 $model = new FundNum(['fund_num' => $v['code'], 'fund_type' => $type]);
                 $model->save();
             }
         }
     }
 }
Exemplo n.º 8
0
}
?>
    </ul>
</div>
<div class="row">
    <table id="month-sort-ul"  class="table table-striped table-hover">
        <?php 
foreach ($posts as $v) {
    ?>
            <tr>
                <td><?php 
    echo $v['fund_num'];
    ?>
</td>
                <td><?php 
    echo FundNum::getRate($v['rate']);
    ?>
</td>
                <td><a target="_blank" href="<?php 
    echo Url::to(['/fund/month-detail', 'num' => $v['fund_num']]);
    ?>
">月详情</a></td>
                <td><a target="_blank" href="<?php 
    echo Url::to(['/fund/week-detail', 'num' => $v['fund_num']]);
    ?>
">周详情</a></td>
                <td><a target="_blank" href="<?php 
    echo Url::to(['/fund/day-detail', 'num' => $v['fund_num']]);
    ?>
">日详情</a></td>
            </tr>
Exemplo n.º 9
0
 /**
  * 执行类型5:涨幅超过5%的天数是跌幅超过5%的天数的2倍
  */
 public static function saveType5()
 {
     $fund_nums = FundNum::find()->all();
     foreach ($fund_nums as $v) {
         $biggerCount = FundHistory::biggerCount($v->fund_num, 5);
         $smallerCount = FundHistory::smallerCount($v->fund_num, -5);
         if ($biggerCount >= $smallerCount * 2) {
             $model = new self(['type' => self::TYPE_5, 'date' => date('Y-m-d'), 'fund_num' => $v->fund_num]);
             $model->save();
         }
     }
 }
Exemplo n.º 10
0
?>
        <?php 
echo Html::a('删除', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
?>
    </p>
    <?php 
$day = FundNum::getFundDetail($model->fund_num, 'day');
if ($day) {
    $h1 = '均值:' . number_format($day['average'], 2) . ';标准差:' . number_format($day['sd'], 2) . ';比例:' . ($day['average'] ? number_format($day['sd'] / $day['average'], 2) : '');
} else {
    $h1 = '-';
}
$week = FundNum::getFundDetail($model->fund_num, 'week');
if ($week) {
    $h2 = '均值:' . number_format($week['average'], 2) . ';标准差:' . number_format($week['sd'], 2) . ';比例:' . ($week['average'] ? number_format($week['sd'] / $week['average'], 2) : '');
} else {
    $h2 = '-';
}
$month = FundNum::getFundDetail($model->fund_num, 'month');
if ($month) {
    $h3 = '均值:' . number_format($month['average'], 2) . ';标准差:' . number_format($month['sd'], 2) . ';比例:' . ($month['average'] ? number_format($month['sd'] / $month['average'], 2) : '');
} else {
    $h3 = '-';
}
?>
    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'fund_num', 'created_at:datetime', 'updated_at:datetime', ['label' => '日统计', 'format' => 'html', 'value' => $h1], ['label' => '周统计', 'format' => 'html', 'value' => $h2], ['label' => '月统计', 'format' => 'html', 'value' => $h3]]]);
?>

</div>