joway пре 2 година
родитељ
комит
ec80f2a715
2 измењених фајлова са 38 додато и 3 уклоњено
  1. 10 3
      backendApi/modules/v1/controllers/AtlasController.php
  2. 28 0
      common/models/UserRelation.php

+ 10 - 3
backendApi/modules/v1/controllers/AtlasController.php

@@ -72,7 +72,7 @@ class AtlasController extends BaseController {
         if ($userName !== '') {
             //$oneUser = Info::getUserByUserNameFromUserInfoTable($userName);
             if (!$userId = Info::getUserIdByUserName($userName)) {
-                
+
                 return static::notice(Yii::t('ctx', 'memberDoesNotExist'), 400); // 会员不存在
             }
         } else {
@@ -162,11 +162,18 @@ class AtlasController extends BaseController {
         $userId = Yii::$app->request->get('id', Yii::$app->params['mainUserId']);
         $periodNum = Yii::$app->request->get('periodNum', null);
         $deep = Yii::$app->request->get('deep', 2);
+        $isData = Yii::$app->request->get('isData', null);
         if ($deep > 20) {
             return static::notice(Yii::t('ctx', 'atlasNetworkViewLimitNotice'), 400);//最多查看会员的前20层子会员
         }
         $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
-        return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
+        if(!$isData){
+            return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
+        } else {
+            $createPngData = UserRelation::getDataCreatePng($allData,$userId,$deep);
+            return static::notice(['allData' => $createPngData]);
+        }
+
     }
 
     /**
@@ -231,4 +238,4 @@ class AtlasController extends BaseController {
         ]);
     }
 
-}
+}

+ 28 - 0
common/models/UserRelation.php

@@ -363,4 +363,32 @@ class UserRelation extends \common\components\ActiveRecord
         }
         return $data ? Json::decode($data) : [];
     }
+
+    public static function getDataCreatePng($allData,$userId,$deep){
+        $oneUserInfo = UserInfo::findOneAsArray(['USER_ID'=>$userId]);
+        $text = "flowchart TD".PHP_EOL;
+        //print_r($allData);die;
+        foreach($allData as $k=>$v){
+            $text .= $userId."[".$oneUserInfo['USER_NAME']."] -->".$v['USER_ID']."(".$v['USER_NAME'].")".PHP_EOL;
+            if(!empty($v['children'])){
+                $text .=  self::getChildrenData($v['USER_ID'],$v['children'],$deep);
+            }
+        }
+       print_r($text);die;
+        return $text;
+    }
+
+    public static function getChildrenData($parentId,$children,$deep,$text=''){
+        foreach($children as $vv){
+            if($deep >= 0 && !empty($vv['children'])){
+                $deep--;
+                $text .= $parentId." --> ".$vv['USER_ID']."[".$vv['USER_NAME']."]".PHP_EOL;
+                $text = self::getChildrenData($vv['USER_ID'],$vv['children'],$deep,$text);
+            } else {
+                $text .= $parentId." --> ".$vv['USER_ID']."[".$vv['USER_NAME']."]".PHP_EOL;
+            }
+        }
+        return $text;
+    }
+
 }