ActivityManagerController.php
2.65 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\AdminSection\Controllers\Audition;
use App\Helpers\OperationLog;
use App\Http\Container\AdminSection\Requests\Audition\ActivityManagerCreateRequest;
use App\Http\Container\AdminSection\Requests\Audition\ActivityManagerUpdateRequest;
use App\Models\Activity;
use App\Models\Pivots\ActivityLinkPivot;
use App\Support\Controller;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
class ActivityManagerController extends Controller
{
/**
* @param \App\Http\Container\AdminSection\Requests\Audition\ActivityManagerCreateRequest $request
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function store(ActivityManagerCreateRequest $request): Response
{
$data = $request->safe()->toArray();
$activity = Activity::query()->find($data['activity_id']);
$activity->links()->wherePivot('type', 'manager')->syncWithPivotValues($data['user_ids'], ['type' => 'manager', 'expand->permission' => $data['expand->permission']], false);
OperationLog::admin()->createAction()->subject($activity)->content('《%s》新增外部管理员', $activity->getAttribute('song_name'));
return $this->success(ApiCode::CREATE_SUCCESS);
}
/**
* @param \App\Http\Container\AdminSection\Requests\Audition\ActivityManagerUpdateRequest $request
* @param \App\Models\Pivots\ActivityLinkPivot $activityManager
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function update(ActivityManagerUpdateRequest $request, ActivityLinkPivot $activityManager): Response
{
$activityManager->update($request->safe()->toArray());
$nickName = $activityManager->link()->value('nick_name');
$activityName = $activityManager->activity()->value('song_name');
OperationLog::admin()->subject($activityManager)->updateAction()->content('《%s》调整外部管理员:%s 的权限', $activityName, $nickName);
return $this->successWithData($activityManager, ApiCode::UPDATE_SUCCESS);
}
/**
* @param \App\Models\Pivots\ActivityLinkPivot $activityManager
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function destroy(ActivityLinkPivot $activityManager): Response
{
$nickName = $activityManager->link()->value('nick_name');
$activityName = $activityManager->activity()->value('song_name');
$activityManager->delete();
OperationLog::admin()->subject($activityManager)->deleteAction()->content('《%s》移除外部管理员:%s', $activityName, $nickName);
return $this->success(ApiCode::DELETE_SUCCESS);
}
}