/**
  * 处理用户的访问行为并入库
  * @param type $end_time
  * @param type $writeLine
  * @param type $end_num_cache_name
  */
 public static function toInserUserTarFro($end_time, $writeLine, $end_num_cache_name)
 {
     //获得存储的文件缓冲数据
     $inserArray = \Yii::$app->cache->get('target');
     //循环处理数据入库
     if ($inserArray) {
         $targetsourceurlarr = [];
         $i = 0;
         foreach ($inserArray as $key => $value) {
             foreach ($value as $key2 => $twovalue) {
                 $targetsourceurlarr[$i]['target_url'] = $key;
                 $targetsourceurlarr[$i]['from_url'] = $key2;
                 $targetsourceurlarr[$i]['nums'] = $twovalue;
                 $targetsourceurlarr[$i]['vist_time'] = $end_time;
             }
             $i++;
         }
         try {
             $command = \Yii::$app->db->createCommand();
             $command->batchInsert(TargetSourceUrl::tableName(), ['target_url', 'from_url', 'nums', 'vist_time'], $targetsourceurlarr);
             $abc = $command->execute();
             \Yii::$app->cache->set($end_num_cache_name, $writeLine);
             echo "当前处理到";
             echo "\n";
             echo $writeLine;
             echo "\n";
             echo $end_time;
             echo "\n";
             echo $abc;
             echo "\n";
         } catch (yii\db\Exception $e) {
             //记录读到的最后一行,没有处理的行会被后退
             print_r($e);
             exit;
         }
     }
     //重置数据为空
     \Yii::$app->cache->set('target', FALSE);
 }
 public function actionProduct()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $id = \Yii::$app->request->get('id');
     $sDate = date('Y-m-d 00:00:00');
     $eDate = date('Y-m-d 00:00:00', strtotime("+1 day", strtotime($sDate)));
     if ($id) {
         //获得指定的数据
         $oneUrl = TargetSourceUrl::find()->where('id=:id', [':id' => $id])->one();
         //上一级的访问图
         $prelistss = TargetSourceUrl::find()->select("id,from_url,sum(nums) nums")->where('target_url=:target_url', [':target_url' => $oneUrl->target_url])->andWhere('vist_time>=:sd AND vist_time<:ed', [':sd' => $sDate, ':ed' => $eDate])->asArray()->groupBy("from_url")->all();
         //处理一个公约数实现能量平衡
         $prelistsscountnums = 0;
         if ($prelistss) {
             foreach ($prelistss as $key => $value) {
                 $prelistsscountnums = $prelistsscountnums + $value['nums'];
             }
         } else {
             $prelistsscountnums = 1;
         }
         $listsscountnums = 0;
         //下一级访问图
         $listss = TargetSourceUrl::find()->select("id,target_url,sum(nums) nums")->where('from_url=:from_url', [':from_url' => $oneUrl->target_url])->andWhere('vist_time>=:sd AND vist_time<:ed', [':sd' => $sDate, ':ed' => $eDate])->asArray()->groupBy("target_url")->all();
         if ($listss) {
             foreach ($listss as $key => $value) {
                 $listsscountnums = $listsscountnums + $value['nums'];
             }
         } else {
             $listsscountnums = 1;
         }
         $beiNums = ToolService::min_multiple($prelistsscountnums, $listsscountnums);
         //获得上一级数据的倍数
         $prbei = $beiNums / $prelistsscountnums;
         //获得下一级数据的倍数
         $bei = $beiNums / $listsscountnums;
         //处理上一级的数据
         if (!$prelistss) {
             $data['nodes'][] = ['name' => $oneUrl->target_url];
             $data['nodes'][] = ['name' => '[0][F]起点-无数据'];
             $data['links'][] = ["source" => '[0][F]起点-无数据', "target" => $oneUrl->target_url, "value" => 1 * $prbei];
         } else {
             $data['nodes'][] = ['name' => $oneUrl->target_url];
             foreach ($prelistss as $key => $value) {
                 $name = "[" . $value['id'] . "][F]" . $value['from_url'];
                 $data['nodes'][] = ['name' => $name];
                 $data['links'][] = ["source" => $name, "target" => $oneUrl->target_url, "value" => $value['nums'] * $prbei];
             }
         }
         if (!$listss) {
             $data['nodes'][] = ['name' => '终点-点击返回首页数据[T][0]'];
             $data['links'][] = ["source" => $oneUrl->target_url, "target" => '终点-点击返回首页数据[T][0]', "value" => 1 * $bei];
         } else {
             foreach ($listss as $key => $value) {
                 $name = $value['target_url'] . "[T][" . $value['id'] . "]";
                 $data['nodes'][] = ['name' => $name];
                 $data['links'][] = ["source" => $oneUrl->target_url, "target" => $name, "value" => $value['nums'] * $bei];
             }
         }
     } else {
         //获得首页开始的流动数据
         $listss = TargetSourceUrl::find()->select("id,target_url,sum(nums) nums")->where('from_url="-"')->andWhere('vist_time>=:sd AND vist_time<:ed', [':sd' => $sDate, ':ed' => $eDate])->asArray()->groupBy("target_url")->all();
         $data['nodes'][] = ['name' => '首页'];
         foreach ($listss as $key => $value) {
             if ($value['target_url'] == 'http://www.tuandai.com/view/ip.aspx' || $value['target_url'] == 'http://www.tuandai.com/MobileAPI/GetConnectionType.aspx') {
                 continue;
             }
             $name = $value['target_url'] . "[" . $value['id'] . "]";
             $data['nodes'][] = ['name' => $name];
             $data['links'][] = ["source" => "首页", "target" => $name, "value" => $value['nums']];
         }
     }
     return $data;
 }