ActivityController.php 1.73 KB
<?php


namespace App\Http\Container\AppSection\Controllers;


use App\Enums\ActivityAuditStatusEnum;
use App\Helpers\JsonResource;
use App\Mail\ActivityMaterialMail;
use App\Models\Activity;
use App\Models\Views\ActivitySubmitWork;
use App\Support\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class ActivityController extends Controller
{
    public function submitAudion(Request $request)
    {
        $size        = $request->get('size', 10);
        $activity_id = $request->get('activity_id');
        $data        = ActivitySubmitWork::query()
            ->select(['id', 'user_id', 'demo_url', 'durations', 'sing_type', 'mode', 'status', 'activity_id', 'submit_at'])
            ->with(['user:id,business_id,nick_name,avatar,user_tag_id', 'user.business:id,nick_name,avatar', 'user.userTag:id,name,icon,frame'])
            ->where(['activity_id' => $activity_id, 'is_hide' => 0])
            ->withExists('isLike')
            ->paginate($size);

        return JsonResource::success(JsonResource::SUCCESS, ['data' => $data->items(), 'count' => $data->total()]);

    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param int                      $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function sendMail(Request $request, int $id): JsonResponse
    {
        $activity = Activity::query()->where('audit_status', ActivityAuditStatusEnum::SUCCESS)->findOrFail($id);

        if (empty($request->user()->getAttribute('email'))) {
            return JsonResource::fail('请先设置您的邮箱');
        }

        Mail::send(new ActivityMaterialMail($activity, $request->user()));
        return JsonResource::success(JsonResource::SUCCESS);
    }
}