/** * This command export heatmap result data. * @param string $filename the file to be imported to DB. */ public function actionHeatmap($filename = 'heatmap.csv') { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'exported_data' . DIRECTORY_SEPARATOR . $filename; $heatmap_records = \app\models\HeatMap::find()->where(['status' => \app\models\HeatMap::HEATMAP_VALID])->all(); $all_mobiles = array(); $fh = fopen($file, "w"); fprintf($fh, "用户微信昵称,用户手机号,是否员工,提交时间\n"); foreach ($heatmap_records as $heatmap) { $user = $heatmap->user; $staff = $user->staff; if (!empty($staff) && $staff->cat == \app\models\MStaff::SCENE_CAT_IN) { } else { $staff = $user->mobileStaff; } $mobiles = array(); $bind_mobiles = $user->openidBindMobiles; if (!empty($bind_mobiles)) { foreach ($bind_mobiles as $bind_mobile) { $mobiles[] = $bind_mobile->mobile; } } if (!empty(array_diff($mobiles, $all_mobiles))) { $all_mobiles = array_merge($all_mobiles, $mobiles); fprintf($fh, "%s,%s,%s,%s\n", $user->nickname, "[" . $user->getBindMobileNumbersStr() . "]", !empty($staff) ? "员工:{$staff->name}" : "否", $heatmap->create_time); } } fclose($fh); // var_dump($all_mobiles); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = HeatMap::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['heat_map_id' => $this->heat_map_id, 'lon' => $this->lon, 'lat' => $this->lat, 'speed_up' => $this->speed_up, 'speed_down' => $this->speed_down, 'speed_delay' => $this->speed_delay, 'status' => $this->status]); $query->andFilterWhere(['like', 'gh_id', $this->gh_id])->andFilterWhere(['like', 'openid', $this->openid])->andFilterWhere(['like', 'pic_url', $this->pic_url]); return $dataProvider; }
/** * Finds the HeatMap model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return HeatMap the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = HeatMap::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getMySpeedDownRank() { return HeatMap::find()->where('gh_id=:gh_id AND speed_down>=:speed_down AND status=:status', [':gh_id' => $this->gh_id, ':speed_down' => $this->speed_down, ':status' => 0])->count(); }
public function actionHandlespeed() { $this->layout = false; $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); $lon = empty($_GET['lon']) ? 0 : $_GET['lon']; $lat = empty($_GET['lat']) ? 0 : $_GET['lat']; $speed_up = empty($_GET['speed_up']) ? 0 : $_GET['speed_up']; $speed_down = empty($_GET['speed_down']) ? 0 : $_GET['speed_down']; $speed_delay = empty($_GET['speed_delay']) ? 0 : $_GET['speed_delay']; $media_id = empty($_GET['serverId']) ? 0 : $_GET['serverId']; $is_4g = empty($_GET['status']) ? 0 : $_GET['status']; //$is_4g = 1; if (empty($media_id)) { U::W([$_GET]); return json_encode(['code' => 1]); } $model = new HeatMap(); $model->gh_id = $gh_id; $model->openid = $openid; $model->lon = $lon; $model->lat = $lat; $model->speed_up = $speed_up; $model->speed_down = $speed_down; $model->speed_delay = $speed_delay; $model->media_id = $media_id; $model->pic_url = "{$gh_id}_{$media_id}.jpg"; $log_file_path = $model->getPicFile(); if (!file_exists($log_file_path) || $model->getPicFileSize() == 0 || $model->getPicFileSize() == 47) { Yii::$app->wx->setGhId($gh_id); Yii::$app->wx->WxMediaDownload($model->media_id, $log_file_path); } $model->save(false); return json_encode(['code' => 0]); }