<?php

namespace App\Http\Controllers\User;

use App\Console\Commands\User\TestCommand;
use App\Exceptions\AlertException;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Core\Auth;
use App\Services\Notice\UserNoticeService;
use App\Services\User\NoticeService;
use App\Services\User\ProfileService;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Request;

class VipController extends Controller
{


    /**
     * 会员通知
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function notice(Request $request)
    {
        $uid = Auth::auth();
        $NoticeService = new NoticeService();
        $NoticeService->vip($uid);
        return response()->json([
            'code' => 200,
            'message' => 'OK'
        ]);
    }

    /**
     * 获取内测资格
     */
    public function getTestQual()
    {
        $uid = Auth::auth();
        if (Redis::sismember("fpdx_supervip_test", $uid)) {
            throw new AlertException("你已经获取内测资格", 200);
        } else {
            $tc = new UserNoticeService();
            $tc->test($uid);
            return array(
                'code' => 200,
                'message' => 'success'
            );
        }
    }

    public function beVip()
    {
        $uid = Auth::auth();
        $pfs = new ProfileService();
        $pfs->beVip($uid, true);
        return response()->json([
            'code' => 200,
            'message' => 'OK'
        ]);
    }
}
