예제 #1
0
 public function cronVisitorDataType($type)
 {
     if (!isset($this->config[$type])) {
         return;
     }
     $config = $this->config[$type];
     $fields = 'visitor_datatype_' . $type;
     $update = 'updated_datatype_' . $type;
     $where = $config['where'] ? $config['where'] : '1=1';
     $order = $config['order'] ? $config['order'] : 'created_at asc';
     $limit = $config['limit'] ? $config['limit'] : 100;
     $models = StatVisit::find()->where($where)->orderBy($order)->limit($limit)->all();
     //连续5次失败则不更新
     $i = 0;
     foreach ($models as $k => $model) {
         $userName = $model->visitor_username;
         $ref = $model->visitor_referrer;
         $params = ['userName' => $userName];
         $return = $this->getByType($ref, $type, $params);
         if ($return['code'] == 200) {
             $model->{$fields} = $return['data'];
             $model->{$update} = CURRENT_TIMESTAMP;
             if (!$model->update()) {
                 print_r($model->errors);
             } else {
                 \yii::$app->controller->stdout(sprintf("%s - %s:%s Id:%d \n", $userName, $config['name'], $return['data'], $model->id), Console::BOLD);
             }
         } else {
             $i++;
             if ($i > 5) {
                 break;
             }
         }
     }
 }
예제 #2
0
파일: Visit.php 프로젝트: oyoy8629/yii-core
 public function tracker()
 {
     $idvisitor = $this->getIdvisitor();
     if (!($model = $this->findVisitor($idvisitor))) {
         $model = new StatVisit();
     }
     $referrers = new Referrers();
     $details = $referrers->getReferrerInformationFromRequest();
     $model->load(['StatVisit' => $this->load($idvisitor, $details)]);
     $model->save();
     if ($model->id) {
         $details['vid'] = $model->id;
         $details['flag'] = \yii::$app->request->get('rf', 1);
         $this->insertVisitDetails($details);
     }
 }
 /**
  * Lists all StatVisitDetails models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new StatVisitDetailsSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $idvisitor = '';
     if ($searchModel->vid) {
         $model = StatVisit::findOne($searchModel->vid);
         if ($model) {
             $idvisitor = $model->idvisitor;
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'idvisitor' => $idvisitor]);
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = StatVisit::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 100]]);
     $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, 'status' => $this->status, 'updated_datatype_0' => $this->updated_datatype_0, 'updated_datatype_1' => $this->updated_datatype_1, 'updated_datatype_2' => $this->updated_datatype_2, 'updated_datatype_3' => $this->updated_datatype_3, 'updated_datatype_4' => $this->updated_datatype_4, 'updated_datatype_5' => $this->updated_datatype_5, 'updated_datatype_6' => $this->updated_datatype_6, 'updated_datatype_7' => $this->updated_datatype_7, 'updated_datatype_8' => $this->updated_datatype_8, 'updated_datatype_9' => $this->updated_datatype_9, 'visitor_referrer' => $this->visitor_referrer, 'iptype' => $this->iptype, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at, 'visitor_regtime' => $this->visitor_regtime, 'month_cron' => $this->month_cron]);
     $query->select([StatVisit::tableName() . '.*', 'COUNT(' . StatVisitDetails::tableName() . '.vid) as count']);
     $query->groupBy(StatVisit::tableName() . '.id');
     $query->orderBy('updated_at desc');
     $query->leftJoin(StatVisitDetails::tableName(), StatVisit::tableName() . '.id = ' . StatVisitDetails::tableName() . '.vid');
     $query->andFilterWhere(['like', 'idvisitor', $this->idvisitor])->andFilterWhere(['like', 'location_ip', $this->location_ip])->andFilterWhere(['like', 'visitor_username', $this->visitor_username])->andFilterWhere(['like', 'visitor_datatype_0', $this->visitor_datatype_0])->andFilterWhere(['like', 'visitor_datatype_1', $this->visitor_datatype_1])->andFilterWhere(['like', 'visitor_datatype_2', $this->visitor_datatype_2])->andFilterWhere(['like', 'visitor_datatype_3', $this->visitor_datatype_3])->andFilterWhere(['like', 'visitor_datatype_4', $this->visitor_datatype_4])->andFilterWhere(['like', 'visitor_datatype_5', $this->visitor_datatype_5])->andFilterWhere(['like', 'visitor_datatype_6', $this->visitor_datatype_6])->andFilterWhere(['like', 'visitor_datatype_7', $this->visitor_datatype_7])->andFilterWhere(['like', 'visitor_datatype_8', $this->visitor_datatype_8])->andFilterWhere(['like', 'visitor_datatype_9', $this->visitor_datatype_9])->andFilterWhere(['like', 'iptext', $this->iptext]);
     return $dataProvider;
 }
예제 #5
0
 /**
  * Finds the StatVisit model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return StatVisit the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = StatVisit::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #6
0
 public static function findVisitor($idSite, $configId, $idVisitor)
 {
     $row = StatVisit::find()->where(['config_id' => $configId])->andWhere(['idsite' => $idSite])->one();
     return $row;
 }