MemberController.php
1.94 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
51
52
53
54
55
<?php
namespace App\Http\Container\AppSection\Controllers\Auth\Group;
use App\Enums\ActivityWorkStatusEnum;
use App\Enums\ActivityWorkTypeEnum;
use App\Helpers\JsonResource;
use App\Models\ActivityUser;
use App\Models\User;
use Auth;
use Hikoon\LaravelApi\Support\ApiController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class MemberController extends ApiController
{
public function __construct()
{
$this->middleware('emptyToNull');
}
/**
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request): JsonResponse
{
$pageSize = $request->integer('size', 20);
$data = User::filter(['nickName' => $request->get('text')])
->with(['authTags:id,name', 'userTag:id,name,icon,frame'])
->select(['id', 'avatar', 'nick_name', 'chat_mode', 'identity', 'user_tag_id'])
->where("business_id", Auth::id())->latest()->paginate($pageSize);
return JsonResource::success(JsonResource::SUCCESS, ['data' => $data->items(), 'count' => $data->total()]);
}
/**
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function show(int $id): JsonResponse
{
$user = User::with(['authTags:id,name', 'styleTags:id,name', 'userTag:id,name,icon,frame'])
->select(['id', 'nick_name', 'real_name', 'avatar', 'last_login', 'rate', 'chat_mode', 'company', 'identity', 'user_tag_id'])
->findOrFail($id);
if ($user) {
$user->setAttribute('attend_count', ActivityUser::where('user_id', $id)->where('type', ActivityWorkTypeEnum::SUBMIT)->count());
$user->setAttribute('check_count', ActivityUser::where('user_id', $id)->where('type', ActivityWorkTypeEnum::SUBMIT)->where('status', ActivityWorkStatusEnum::SUCCESS)->count());
}
return JsonResource::success(JsonResource::SUCCESS, $user);
}
}