/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ApiMonthDetail::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, 'idvisit' => $this->idvisit, 'mtime' => $this->mtime, 'updated_datatype_13' => $this->updated_datatype_13, 'updated_datatype_10' => $this->updated_datatype_10, 'updated_datatype_11' => $this->updated_datatype_11, 'updated_datatype_12' => $this->updated_datatype_12, 'visitor_referrer' => $this->visitor_referrer, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'visitor_datatype_13', $this->visitor_datatype_13])->andFilterWhere(['like', 'visitor_datatype_10', $this->visitor_datatype_10])->andFilterWhere(['like', 'visitor_datatype_11', $this->visitor_datatype_11])->andFilterWhere(['like', 'visitor_datatype_12', $this->visitor_datatype_12])->andFilterWhere(['like', 'visitor_username', $this->visitor_username]); return $dataProvider; }
/** * 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 = ApiMonthDetail::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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); } }
public function getUpdatedCount() { return ApiMonthDetail::find()->where(['mtime' => $this->time])->count(); }