<?php namespace app\api\controller\activity; use app\models\tree\TreeRecommend; use app\Request; class TreeController { public function myPoint(Request $request) { $user = $request->user(); $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', $father)->column('id'); if (count($father) > 0) $children = array_merge($children, $father); $layer++; } $item['children_num'] = count($children); }); return app('json')->success('ok', compact('points')); } public function pointChildren($id, Request $request) { $children = TreeRecommend::with(['user'])->where('parent_id', $id)->order('way', 'asc')->select(); return app('json')->success('ok', compact('children')); } }