* @license GPL https://xxx.com * @link https://xxx.com * @ctime: 2020/3/28 10:29 */ namespace App\Jobs; use Carbon\Carbon; use Illuminate\Support\Facades\Log; class SendSMSBikeTemporaryWaitOverThirtyJob extends Job { protected $mobile = ''; protected $bike_no = ''; protected $start_use_time = ''; protected $redisKey = ''; /** * Create a new job instance. * * @return void */ public function __construct($mobile, $bike_no, $start_use_time, $redisKey, Carbon $delay) { $this->mobile = $mobile; $this->bike_no = $bike_no; $this->start_use_time = $start_use_time; $this->redisKey = $redisKey; // 设置延迟的时间,delay() 方法的参数代表多少秒之后执行 $this->delay($delay); } /** * Execute the job. * * @return void */ public function handle() { $res = app()->redis->get($this->redisKey); if ($res) { //不为空 进来 $time = Carbon::parse($res); $int = (new Carbon)->diffInMinutes($time, true); // $int 为正负数 ture 为绝对值 if ($int >= 29) { // 留一分钟得偏差 app('easy_sms')->send($this->mobile, [ 'template' => '565201', 'data' => [ 'bike_no' => $this->bike_no,// 车牌号 'start_use_time' => Carbon::make($this->start_use_time)->format('Y-m-d H:i:s'), //开始时间 'int' => $int,//多长时间未操作车 ] ]); } } } }