/** * Creates a new ApiMonthDetail model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ApiMonthDetail(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
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); } }