<?php

namespace App\Http\Controllers\Manage\ForceSub;

use App\Http\Controllers\Controller;
use App\Modules\Sys\Services\SysConfigService;
use Illuminate\Http\Request;

use App\Jobs\ForceActiveJob;


class ForceUsersDateActiveController extends Controller
{

    function run(Request $request)
    {
        $start_date = $request->has('start_date') ? $request->input('start_date') : '';
        $end_date = $request->has('end_date') ? $request->input('end_date') : '';
        if(!$start_date || !$end_date) return response()->error('PARAM_ERROR');

        //查看开关
        $switch = SysConfigService::getForceActiveSwitch();
        if($switch)
        {
             return response()->error('TASK_IN_PROGRESS');
        }else{
            try {
                $job = (new ForceActiveJob(compact('start_date', 'end_date')))->onConnection('rabbitmq')->onQueue('force_active');
                dispatch($job);
                //开启开关
                SysConfigService::openForceActiveSwitch();
                //添加到执行命令
            }catch (\Exception $e)
            {

            }
        }
        return response()->success();
    }
}