SendSMSBikeTemporaryWaitOverThirtyJob.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. *
  4. *
  5. * @category xxx
  6. * @package PSR
  7. * @subpackage Documentation\API
  8. * @author xxx <xxx@xxx.com>
  9. * @license GPL https://xxx.com
  10. * @link https://xxx.com
  11. * @ctime: 2020/3/28 10:29
  12. */
  13. namespace App\Jobs;
  14. use Carbon\Carbon;
  15. use Illuminate\Support\Facades\Log;
  16. class SendSMSBikeTemporaryWaitOverThirtyJob extends Job
  17. {
  18. protected $mobile = '';
  19. protected $bike_no = '';
  20. protected $start_use_time = '';
  21. protected $redisKey = '';
  22. public $tries = 1;
  23. /**
  24. * Create a new job instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct($mobile, $bike_no, $start_use_time, $redisKey, Carbon $delay)
  29. {
  30. $this->mobile = $mobile;
  31. $this->bike_no = $bike_no;
  32. $this->start_use_time = $start_use_time;
  33. $this->redisKey = $redisKey;
  34. // 设置延迟的时间,delay() 方法的参数代表多少秒之后执行
  35. $this->delay($delay);
  36. }
  37. /**
  38. * Execute the job.
  39. *
  40. * @return void
  41. */
  42. public function handle()
  43. {
  44. $res = app()->redis->get($this->redisKey);
  45. if ($res) {
  46. //不为空 进来
  47. $time = Carbon::parse($res);
  48. $int = (new Carbon)->diffInMinutes($time, true); // $int 为正负数 ture 为绝对值
  49. if ($int >= 29) {
  50. // 留一分钟得偏差
  51. app('easy_sms')->send($this->mobile, [
  52. 'template' => '1251382',
  53. 'data' => [
  54. 'bike_no' => $this->bike_no,// 车牌号
  55. 'start_use_time' => Carbon::make($this->start_use_time)->format('Y-m-d H:i:s'), //开始时间
  56. 'int' => $int,//多长时间未操作车
  57. ]
  58. ]);
  59. }
  60. }
  61. }
  62. }