提交代码
This commit is contained in:
73
app/Agent/Controllers/TeamController.php
Normal file
73
app/Agent/Controllers/TeamController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Agent\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\UserRelation\Models\UserRelation;
|
||||
|
||||
/**
|
||||
* 团队管理
|
||||
*/
|
||||
class TeamController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
view()->share('app_title', '推广团队');
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::guard('agent')->user();
|
||||
$identity_id = $request->identity_id;
|
||||
$nickname = $request->nickname;
|
||||
// $lists = UserRelation::query()
|
||||
// ->when(is_numeric($identity_id), function ($query) use ($identity_id) {
|
||||
// $query->whereHas('user', function ($q1) use ($identity_id) {
|
||||
// if ($identity_id) {
|
||||
// $q1->whereHas('identity', function ($q2) use ($identity_id) {
|
||||
// $q2->where('identity_id', $identity_id);
|
||||
// });
|
||||
// } else {
|
||||
// $q1->whereDoesntHave('identity');
|
||||
// }
|
||||
// });
|
||||
// })
|
||||
// ->when($nickname, function ($query) use ($nickname) {
|
||||
// $query->whereHas('userinfo', function ($q1) use ($nickname) {
|
||||
// $q1->where('nickname', 'like', "%{$nickname}%");
|
||||
// });
|
||||
// })
|
||||
// ->where('parent_id', $user->id)
|
||||
// ->paginate();
|
||||
|
||||
$lists = UserRelation::query()
|
||||
->when(is_numeric($identity_id), function ($query) use ($identity_id) {
|
||||
if ($identity_id) {
|
||||
$query->whereHas('useridentity', function ($q) use ($identity_id) {
|
||||
$q->where('identity_id', $identity_id);
|
||||
});
|
||||
} else {
|
||||
$query->whereDoesntHave('useridentity');
|
||||
}
|
||||
})
|
||||
->when($nickname, function ($query) use ($nickname) {
|
||||
$query->whereHas('userinfo', function ($q1) use ($nickname) {
|
||||
$q1->where('nickname', 'like', "%{$nickname}%");
|
||||
});
|
||||
})
|
||||
->where('parent_id', $user->id)
|
||||
->paginate();
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
if ($lists->isNotEmpty()) {
|
||||
$html = response(view('Agent::team.more', compact('lists')))->getContent();
|
||||
return $this->success($html);
|
||||
} else {
|
||||
return $this->error('没有数据了');
|
||||
}
|
||||
} else {
|
||||
return view('Agent::team.index', compact('user', 'identity_id', 'nickname', 'lists'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user