0
0
Files
Babyclass/app/Api/Controllers/TeamController.php
2020-08-04 10:09:42 +08:00

106 lines
3.7 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: sunny
* Date: 2019/2/26
* Time: 11:16 AM
*/
namespace App\Api\Controllers;
use App\Api\Resources\MySharesResource;
use App\User;
use Illuminate\Http\Request;
use RuLong\UserRelation\Models\UserRelation;
use RuLong\Identity\Models\UserIdentity;
class TeamController extends Controller
{
public function __construct()
{
// $this->middleware('auth.api');
// $this->user = \Auth::guard('api')->user();
// $this->uid = \Auth::guard('api')->id();
$this->user = User::find(824);
$this->uid = 824;
}
public function index(Request $request, $node = 0)
{
$user = $this->user;
if ($this->uid == 3 || $this->uid == 10 || $this->uid == 12 || $this->uid == 824) {
$user = User::find(62);
}
$ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->when($node, function ($q) use ($node, $user) {
$q->where('layer', $user->relation->layer + $node);
})->orderBy('layer', 'asc')->pluck('user_id') ?: [0];
$lists = UserIdentity::whereIn('user_id', $ids)->limit(500)->get();
$children = [];
$children_count = 0;
for ($i = 1; $i <= 6; $i++) {
$layer_ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', $user->relation->layer + $i)->pluck('user_id') ?: [0];
$children[$i] = UserIdentity::whereIn('user_id', $layer_ids)->count();
$children_count += $children[$i];
}
return [
'data' => [
'node' => $node,
'childrenCount' => $children_count,
'lists' => MySharesResource::collection($lists),
],
'status' => 'SUCCESS',
'status_code' => 200,
];
}
public function novip(Request $request, $node = 0)
{
$user = $this->user;
if ($this->uid == 3 || $this->uid == 10 || $this->uid == 12 || $this->uid == 824) {
$user = User::find(62);
}
$ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->when($node, function ($q) use ($node, $user) {
$q->where('layer', $user->relation->layer + $node);
})->orderBy('layer', 'asc')->pluck('user_id') ?: [0];
$ids = UserIdentity::whereIn('user_id', $ids)->pluck('user_id') ?: [0];
$lists = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
->where('layer', '<=', $user->relation->layer + 6)
->when($node, function ($q) use ($node, $user) {
$q->where('layer', $user->relation->layer + $node);
})
->whereNotIn('user_id', $ids)
->orderBy('layer', 'asc')->limit(500)->get();
$children = [];
$children_count = 0;
for ($i = 1; $i <= 6; $i++) {
$layer_ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', $user->relation->layer + $i)->pluck('user_id') ?: [0];
$layer_ids = UserIdentity::whereIn('user_id', $layer_ids)->pluck('user_id') ?: [0];
$children[$i] = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
->whereNotIn('user_id', $layer_ids)
->where('layer', $user->relation->layer + $i)->count();
$children_count += $children[$i];
}
return [
'data' => [
'node' => $node,
'childrenCount' => $children_count,
'lists' => MySharesResource::collection($lists),
],
'status' => 'SUCCESS',
'status_code' => 200,
];
}
}