TeamController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 App\Models\UserShare;
  12. use Carbon\Carbon;
  13. use Dingo\Api\Http\Request;
  14. use Illuminate\Http\JsonResponse;
  15. class TeamController extends Controller
  16. {
  17. public function lists(Request $request): JsonResponse
  18. {
  19. $limit = $request->input('limit', 10);
  20. $page = $request->input('page', 1);
  21. $offset = ($page - 1) * 10;
  22. $user = \user();
  23. $lists = User::withCount('child')
  24. ->withCount('childOrder')
  25. ->withSum('childOrder','income')
  26. ->where('parent_id', $user->id)
  27. ->limit($limit)
  28. ->offset($offset)
  29. ->get();
  30. /* @var User $list*/
  31. foreach ($lists as $list){
  32. $list->become_child_at = Carbon::parse($list->become_child_at)->toDateString();
  33. $list->child_order_sum_income = $list->child_order_sum_income ? : 0;
  34. $list->child_order_count = $list->child_order_count ? : 0;
  35. }
  36. return $this->success($lists);
  37. }
  38. }