TeamController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * DateTime: 2022/11/5 0:31.
  5. *
  6. * @description
  7. */
  8. namespace App\Http\Controllers\V1\Share;
  9. use App\Http\Controllers\V1\Controller;
  10. use App\Models\User;
  11. use Carbon\Carbon;
  12. use Dingo\Api\Http\Request;
  13. use Illuminate\Http\JsonResponse;
  14. class TeamController extends Controller
  15. {
  16. public function lists(Request $request): JsonResponse
  17. {
  18. $limit = $request->input('limit', 10);
  19. $page = $request->input('page', 1);
  20. $offset = ($page - 1) * 10;
  21. $user = \user();
  22. $lists = User::withCount('child')
  23. ->withCount('childOrder')
  24. ->withSum('childOrder', 'income')
  25. ->where('parent_id', $user->id)
  26. ->limit($limit)
  27. ->offset($offset)
  28. ->get();
  29. /* @var User $list */
  30. foreach ($lists as $list) {
  31. $list->become_child_at = Carbon::parse($list->become_child_at)->toDateString();
  32. $list->child_order_sum_income = $list->child_order_sum_income ?: 0;
  33. $list->child_order_count = $list->child_order_count ?: 0;
  34. }
  35. return $this->success($lists);
  36. }
  37. }