<?php

namespace App\Jobs;

use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Http\Controllers\Wechat\Template\TemplateWorksController;

class SendTemplate extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;
    private $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        //
        $data['send_time']=date("Y-m-d H:i:s");
        $this->data = $data;
    }
 
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
    	$this->data['receive_time'] = date("Y-m-d H:i:s");
        echo json_encode($this->data);
        try{
        	 $TemplateWork = new TemplateWorksController($this->data['data']);
             $TemplateWork->do_work();
        }
        // 加上\ 全局抓取
        catch(\Exception $e){
        	v('handle_ept: info:'.$e->getMessage());
        }

    }
    
    /**
     * The job failed to process.
     *
     * @param  Exception  $exception
     * @return void
     */
    public function failed(Exception $exception)
    {
    	// Send user notification of failure, etc...
    	v('sendTemplate_ept:'.$exception->getMessage().' data:'.json_encode($this->data));
    }
}
