Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ApiMonthSetting::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 15]]);
     $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, 'time' => $this->time, 'status' => $this->status, 'updated_count' => $this->updated_count, 'selected_count' => $this->selected_count, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function getUpdate($limit = 100)
 {
     $array = ApiVisitorDetail::find()->where(['month_cron' => $this->time])->orderBy('visitor_regtime asc')->limit($limit)->all();
     $fromTime = date('Y-m-d H:i:s', $this->time);
     $y = date('Y', $this->time);
     $m = date('m', $this->time);
     $toTimeStamp = mktime(0, 0, 0, $m + 1, 1, $y);
     $toTime = date('Y-m-d H:i:s', $toTimeStamp);
     foreach ($array as $k => $v) {
         //查找月表是否有该数据,有则不存储
         //逐条获取api 获取完后 数据更新完毕
         $model = ApiMonthDetail::find()->where(['idvisit' => $v['idvisit'], 'mtime' => $this->time])->one();
         if ($model == null) {
             $model = new ApiMonthDetail();
         }
         $model->idvisit = $v->idvisit;
         $model->mtime = $this->time;
         $model->visitor_username = $v->visitor_username;
         $model->visitor_referrer = $v->visitor_referrer;
         $model->created_at = CURRENT_TIMESTAMP;
         $params = ['userName' => $v->visitor_username, 'fromTime' => $fromTime, 'toTime' => $toTime];
         foreach ($this->config as $type => $config) {
             $fieldName = 'visitor_datatype_' . $type;
             $timeName = 'updated_datatype_' . $type;
             $fieldReturn = $this->getByType($v['visitor_referrer'], $type, $params);
             if ($fieldReturn['code'] == 200) {
                 $model->{$fieldName} = $fieldReturn['data'];
                 $model->{$timeName} = CURRENT_TIMESTAMP;
                 \yii::$app->controller->stdout(sprintf("%s - %s:%s Id:%d \n", $v->visitor_username, $config['name'], $fieldReturn['data'], $model->id), \yii\helpers\Console::BOLD);
             }
         }
         if ($model->save()) {
             $v->month_cron = 0;
             $v->save();
         } else {
             print_r($model->errors);
         }
     }
     if (!ApiVisitorDetail::getMonthCronData($this->time)) {
         $model = new ApiMonthSetting();
         $data = $model->getUpdating();
         $model->updateTheMonth($data->id, false);
     }
 }
 /**
  * Finds the ApiMonthDetail model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return ApiMonthDetail the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ApiMonthSetting::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }