MemberController.php
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Http\Container\AdminSection\Controllers\User;
use App\Helpers\OperationLog;
use App\Http\Service\UserService;
use App\Models\GroupHasMember;
use App\Models\User;
use App\Support\Controller;
use Hikoon\LaravelApi\Facades\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class MemberController extends Controller
{
/**
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function index(Request $request, int $id): Response
{
$pageSize = $request->get('pageSize', 20);
$filter = $request->except(['page', 'pageSize']);
$data = GroupHasMember::filter($filter)
->with('member:id,nick_name,real_name,avatar,email,phone,area_code,sex,official_status,status,scope,identity')
->whereRelation('group', 'groups.user_id', $id)
->where('role', '!=', 1)
->paginate($pageSize);
return $this->successWithData($data);
}
/**
* @param int $userId
* @param \App\Http\Service\UserService $userService
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function destroy(int $userId): Response
{
$user = User::query()->findOrFail($userId);
DB::transaction(static function () use ($user) {
UserService::deleteGroupMember($user);
OperationLog::admin()->subject($user)->updateAction()->content('用户《%s》解绑经纪人', $user->getFullName());
});
return $this->successWithData($user);
}
}