ApplyController.php
3.52 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace App\Http\Container\ManageSection\Controllers\Audition;
use App\Enums\ActivityAuditStatusEnum;
use App\Enums\ActivitySongTypeEnum;
use App\Helpers\OperationLog;
use App\Http\Container\ManageSection\Filters\ActivityFilter;
use App\Http\Container\ManageSection\Requests\Audition\ApplyCreateRequest;
use App\Http\Container\ManageSection\Requests\Audition\ApplyUpdateRequest;
use App\Http\Service\ActivityService;
use App\Models\Activity;
use App\Support\Controller;
use App\Support\Model;
use Auth;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class ApplyController extends Controller
{
/**
* @param \Illuminate\Http\Request $request
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function index(Request $request): Response
{
$pageSize = $request->get('pageSize', 20);
$filter = $request->mergeIfMissing(['audit_status' => [0, 2]])->except(['page', 'pageSize']);
return $this->successWithData(Activity::filter($filter, ActivityFilter::class)->paginate($pageSize));
}
/**
* @param \App\Http\Container\ManageSection\Requests\Audition\ApplyCreateRequest $request
* @param \App\Http\Service\ActivityService $service
* @return \Hikoon\LaravelApi\Facades\Response
* @throws \Hikoon\LaravelApi\Exceptions\ValidationException
*/
public function store(ApplyCreateRequest $request, ActivityService $service): Response
{
$attribute = array_merge($request->safe()->toArray(), ['user_id' => (int)Auth::id(), 'created_form' => 0]);
if (Cache::lock('user-' . Auth::id() . '-apply', 5)->get()) {
$activity = match ($request->integer('song_type')) {
ActivitySongTypeEnum::SONG->value => $service->createActivityApply($attribute + ['lang' => [], 'is_push' => 0]),
ActivitySongTypeEnum::DEMO->value => $service->createDemoApply($attribute + ['is_push' => 1])
};
return $this->successWithData($activity, ApiCode::CREATE_SUCCESS);
}
return $this->fail(ApiCode::REQUEST_LIMIT_ERROR);
}
/**
* @param \App\Http\Container\ManageSection\Requests\Audition\ApplyCreateRequest $request
* @param \App\Models\Activity $apply
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function update(ApplyUpdateRequest $request, Activity $apply): Response
{
$apply->update(Model::dot($request->safe()->merge(['audit_status' => 0, 'status' => 0])));
OperationLog::manage()->subject($apply)->updateAction()
->content('《%s》,重新申请%s', $apply->getAttribute('song_name'), $apply->getChangeColumn()->except(['audit_status', 'status'])->format(',修改了:'));
return $this->successWithData($apply, ApiCode::UPDATE_SUCCESS);
}
/**
* @param \App\Models\Activity $apply
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function destroy(Activity $apply, ActivityService $service): Response
{
if ($apply->getAttribute('audit_status') !== ActivityAuditStatusEnum::FAIL->value) {
return $this->fail(ApiCode::VALIDATION_ERROR, '只允许删除审核未通过');
}
$service->delete($apply);
OperationLog::manage()->subject($apply)->deleteAction()->content('歌曲《%s》', $apply->getAttribute('song_name'));
return $this->success(ApiCode::DELETE_SUCCESS);
}
}