Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = FundData::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'fund_num', $this->fund_num])->andFilterWhere(['like', 'iopv', $this->iopv])->andFilterWhere(['like', 'accnav', $this->accnav])->andFilterWhere(['like', 'growth', $this->growth])->andFilterWhere(['like', 'rate', $this->rate]);
     return $dataProvider;
 }
Example #2
0
 /**
  * 获取每个基金每天的净值数据
  * @param $num
  * @return string
  */
 public function actionPriceDayDetailData($num)
 {
     $posts = FundData::find()->where(['fund_num' => $num])->orderBy(['date' => SORT_ASC])->all();
     $data = [];
     foreach ($posts as $v) {
         $data[] = [strtotime($v['date']) * 1000, floatval($v['accnav'])];
     }
     return json_encode($data);
 }
Example #3
0
 /**
  * 采集基金详情
  * @param $fundData
  * @param $type
  * @return bool
  */
 private function insertData($fundData, $type)
 {
     $iopv = $fundData['net'];
     $accnav = $fundData['totalnet'];
     $growth = $fundData['ranges'];
     $rate = $fundData['rate'];
     $num = $fundData['code'];
     $date = $fundData['SYENDDATE'];
     if ($num && $date && $iopv && $accnav && $growth && $rate) {
         $month = date('n', strtotime($date));
         if ($month <= 3) {
             $quarter = 1;
         } elseif ($month <= 6) {
             $quarter = 2;
         } elseif ($month <= 9) {
             $quarter = 3;
         } elseif ($month <= 12) {
             $quarter = 4;
         } else {
             $quarter = 0;
         }
         try {
             $fundData = new FundData(['date' => $date, 'week' => date('W', strtotime($date)), 'month' => $month, 'quarter' => $quarter, 'year' => date('Y', strtotime($date)), 'fund_num' => $num, 'fund_type' => $type, 'iopv' => $iopv, 'accnav' => $accnav, 'growth' => $growth, 'rate' => $rate]);
             $res = $fundData->save();
             if ($res) {
                 //基金详情采集日志
                 FundLog::insertFundLog($num, $date, FundLog::ITEM_FUND_DATA);
                 return true;
             } else {
                 return false;
             }
         } catch (\Exception $e) {
             echo $e->getMessage() . PHP_EOL;
             return false;
         }
     } else {
         return false;
     }
 }