ActivityCreateRequest.php 6.63 KB
<?php

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

use App\Http\Request\ActivityExpandRequest;
use App\Http\Service\ActivityService;
use Str;

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

    public function rules(): array
    {
        return [
            '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',
            'sub_title'                     => 'required|string|between:0,400',
            'sex'                           => 'required|string',
            'project_id'                    => 'required|numeric',
            'out_side_manages'              => "sometimes|array",
            'out_side_manages.*.user_id'    => 'required|numeric',
            'out_side_manages.*.permission' => 'required|array|in:view,price,audit',
            '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',
            'expand.push_user'              => 'array',
            'estimate_release_at'           => 'required|date|date_format:Y-m-d',
            'is_official'                   => 'required|in:0,1',
            'is_push'                       => 'required|in:0,1',
            'mark'                          => 'sometimes|string',
            'expand.push_type'              => 'required_if:is_push,1|array',
            'weight'                        => 'required|in:0,30,60,90',
            '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('推荐片段不在歌词中');
                }
            }],
        ];
    }

    public function messages(): array
    {
        return [
            'song_type.*'                        => '请选择歌曲类型',
            'create_form.*'                      => '请选择申请平台',
            '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_official.required'               => '请选择奖励标识',
            'is_official.in'                     => '奖励标识不在指定范围内',
            'is_push.required'                   => '请选择是否开启推送',
            'is_push.in'                         => '推送值不在指定范围内',
            'expand.push_type.required_if'       => '请选择推送方式',
            'expand.push_type.array'             => '推送方式类型错误',
            'weight.required'                    => '请选择推荐权重',
            'weight.in'                          => '推荐权重不在指定范围内'
        ];
    }
}