ActivityWorkController.php
2.49 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
56
57
58
59
60
61
62
63
64
65
<?php
namespace App\Http\Container\AdminSection\Controllers\Audition;
use App\Enums\ActivityWorkStatusEnum;
use App\Excel\ActivityWorkExcel;
use App\Helpers\OperationLog;
use App\Http\Service\ActivityService;
use App\Models\Activity;
use App\Models\Views\ActivityWork;
use Auth;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
use Hikoon\LaravelApi\Support\ApiController;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ActivityWorkController extends ApiController
{
/**
* @param \Illuminate\Http\Request $request
* @param \App\Http\Service\ActivityService $service
* @return \Hikoon\LaravelApi\Facades\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function index(Request $request): Response|BinaryFileResponse
{
$pageSize = $request->get('pageSize');
$fetchType = $request->get('fetchType', 'page');
$filter = $request->except(['page', 'pageSize', 'fetchType']);
$query = ActivityWork::filter($filter);
return match ($fetchType) {
'excel' => ActivityWorkExcel::withBuilder($query)->download(),
default => $this->successWithData($query->paginate($pageSize))
};
}
/**
* @param \Illuminate\Http\Request $request
* @param \App\Models\Views\ActivityWork $work
* @param \App\Http\Service\ActivityService $service
* @return \Hikoon\LaravelApi\Facades\Response
* @throws \Hikoon\LaravelApi\Exceptions\ValidationException
*/
public function changeStatus(Request $request, ActivityWork $work, ActivityService $service): Response
{
$attribute = $request->validate(
['status' => 'bail|required|in:1,2'],
['status.required' => '请选择操作类型', 'status.in' => '操作类型不在指定范围内']
);
$service->auditWork($work, ActivityWorkStatusEnum::from($attribute['status']));
OperationLog::admin()->updateAction()->causer(Auth::user())->subject(new Activity(['id' => $work->getAttribute('activity_id')]))->content(
'歌曲《%s》,%s,作品《%s-V%s版本》',
$work->getAttribute('activity_name'),
$attribute['status'] === ActivityWorkStatusEnum::REJECT->value ? '标记不合适' : '完成匹配',
$work->getAttribute('user_nick_name'),
$work->getAttribute('version')
);
return $this->success(ApiCode::UPDATE_SUCCESS);
}
}