ApplyAuditRequest.php 6.93 KB
<?php

namespace App\Http\Container\AdminSection\Requests\Audition;

use App\Http\Service\ActivityService;
use Hikoon\LaravelApi\Support\ApiRequest;
use Illuminate\Support\Str;

class ApplyAuditRequest extends ApiRequest
{

    protected function prepareForValidation(): void
    {
        $this->merge(['is_lyric' => (int)ActivityService::isLyric($this->input('lyric'))]);
    }

    /**
     * @return array<string,mixed>
     */
    public function rules(): array
    {
        return match ($this->input('audit_status')) {
            1 => [
                'audit_status'                 => 'required|in:1',
                'cover'                        => 'required|url',
                'song_name'                    => 'required|string|between:0,200',
                'expand.tag_ids'               => 'required|array|between:1,3',
                'expand.tag_ids.*'             => 'numeric',
                'lang'                         => 'required|array',
                'speed'                        => 'required|string',
                'weight'                       => 'required|in:0,30,60,90',
                'sub_title'                    => 'required|string|between:0,400',
                'project_id'                   => 'required|numeric',
                'expand.lyricist.ids'          => 'array|max:2',
                'expand.lyricist.ids.*'        => 'numeric',
                'expand.lyricist.supplement'   => 'array|max:2',
                'expand.lyricist.supplement.*' => 'string',
                'expand.composer.ids'          => 'array|max:2',
                'expand.composer.ids.*'        => 'numeric',
                'expand.composer.supplement'   => 'array|max:2',
                'expand.composer.supplement.*' => 'string',
                'expand.arranger.ids'          => 'array|max:2',
                'expand.arranger.ids.*'        => 'numeric',
                'expand.arranger.supplement'   => 'array|max:2',
                'expand.arranger.supplement.*' => 'string',
                'expand.guide_source.name'     => 'string',
                'expand.guide_source.url'      => 'required|url',
                'expand.guide_source.size'     => 'integer',
                'expand.karaoke_source.name'   => 'string',
                'expand.karaoke_source.url'    => 'required|url',
                'expand.karaoke_source.size'   => 'integer',
                'expand.track_source.name'     => 'sometimes|string',
                'expand.track_source.url'      => 'sometimes|url',
                'expand.track_source.size'     => 'sometimes|numeric',
                'sex'                          => 'required|string',
                'is_push'                      => "required|in:0,1",
                'is_official'                  => "required|in:0,1",
                'mark'                         => 'sometimes|string',
                'expand.push_type'             => 'required_if:is_push,1|array',
                'expand.push_user'             => 'array',
                'estimate_release_at'          => 'required|date|date_format:Y-m-d',
                'is_lyric'                     => 'required|in:1',
                'lyric'                        => 'required',
                'clip_lyric'                   => ['required', function ($attribute, $value, $fail) {
                    if (!ActivityService::isLyric($value)) {
                        $fail('推荐片段歌词文件类型错误');
                    }
                    if (!Str::contains($this->input('lyric', ''), $value)) {
                        $fail('推荐片段不在歌词中');
                    }
                }]
            ],
            2 => [
                'audit_status' => 'required|in:2',
                'msg'          => 'required|max:100',
            ],
            default => [
                'audit_status' => 'required|in:1,2',
            ]
        };
    }

    /**
     * @return array<string,string>
     */
    public function messages(): array
    {
        return [
            'audit_status.required'              => '请选择审核结果',
            'audit_status.in'                    => '审核结果不在指定范围那',
            'msg.required'                       => '请输入审核不通过理由',
            'msg.max'                            => '理由长度不能超过:max字节',
            'cover.required'                     => '请上传封面',
            'cover.url'                          => '无效的封面地址',
            'song_name.required'                 => '请输入歌曲名称',
            'song_name.between'                  => '歌曲名称长度应在:min~:max字节内',
            'expand.tag_ids.required'            => '请选择关联标签',
            'expand.tag_ids.digits_between'      => '关联标签数量限制:min~:max个',
            'tag_ids.*.numeric'                  => '关联标签类型错误',
            'lang.required'                      => '请选择语种',
            'speed.required'                     => '请选择语速',
            'sub_title.required'                 => '请输入歌曲简介',
            'sub_title.between'                  => '歌曲简介长度应在:min~:max字节内',
            'project_id.required'                => '请选择厂牌',
            'sex.required'                       => '请选择性别要求',
            'estimate_release_at.required'       => '请选择预计发行时间',
            'expand.guide_source.url.required'   => '请上传导唱文件',
            'expand.guide_source.url.url'        => '无效的导唱文件链接',
            'expand.karaoke_source.url.required' => '请上传伴奏文件',
            'expand.karaoke_source.url.url'      => '无效的伴奏文件链接',
            'expand.track_source.url.url'        => '无效的分轨文件链接',
            'is_lyric.in'                        => '歌词文件类型错误',
            'lyric.required'                     => '请上传歌词文件',
            'clip_lyric.required'                => '请上传推荐片段歌词文件',
            'expand.composer.supplement'         => '曲作者(未注册)最多:max人',
            'expand.composer.ids'                => '曲作者(用户)最多:max人',
            'expand.lyricist.supplement'         => '词作者(未注册)最多:max人',
            'expand.lyricist.ids'                => '词作者(用户)最多:max人',
            'expand.arranger.supplement'         => '编曲(未注册)最多:max人',
            'expand.arranger.ids'                => '编曲(用户)最多:max人',
            'is_push.required'                   => '请选择是否开启推送',
            'push_type.required_if'              => '请选择推送方式',
            'is_official.required'               => '请选择奖励标识',
            'weight.required_if'                 => '请选择推荐权重',
            'weight.in'                          => '推荐权重不在指定范围内'
        ];
    }
}