Kirin 3 éve
szülő
commit
813fc21912
1 módosított fájl, 12 hozzáadás és 1 törlés
  1. 12 1
      app/api/controller/activity/TreeController.php

+ 12 - 1
app/api/controller/activity/TreeController.php

@@ -12,7 +12,18 @@ class TreeController
     public function myPoint(Request $request)
     {
         $user = $request->user();
-        $points = TreeRecommend::where('uid', $user['uid'])->order('add_time', 'asc')->select();
+        $points = TreeRecommend::where('uid', $user['uid'])->order('add_time', 'asc')->select()
+            ->each(function ($item) {
+                $children = [];
+                $father = [$item['id']];
+                $layer = 1;
+                while (count($father) && $layer <= 12) {
+                    $father = TreeRecommend::where('parent_id', 'in', $children)->column('id');
+                    if (count($father) > 0) $children = array_merge($children, $father);
+                    $layer++;
+                }
+                $item['children_num'] = count($children);
+            });
         return app('json')->success('ok', $points);
     }