BikeTemporaryWaitOverThirtyAutoCloseOrderJob.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 App\Models\Bike;
  15. use Carbon\Carbon;
  16. use Illuminate\Support\Facades\Log;
  17. class BikeTemporaryWaitOverThirtyAutoCloseOrderJob extends Job
  18. {
  19. protected $mobile = '';
  20. protected $bike_no = '';
  21. protected $start_use_time = '';
  22. protected $redisKey = '';
  23. public $tries = 1;
  24. private $url = '';
  25. /**
  26. * Create a new job instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct($mobile, $bike_no, $start_use_time, $redisKey, Carbon $delay)
  31. {
  32. $this->mobile = $mobile;
  33. $this->bike_no = $bike_no;
  34. $this->start_use_time = $start_use_time;
  35. $this->redisKey = $redisKey;
  36. // 设置延迟的时间,delay() 方法的参数代表多少秒之后执行
  37. $this->delay($delay);
  38. $this->url = config("app.url") . "/api/relay/order/auto-close?key=" . config('auth.api_token');
  39. }
  40. /**
  41. * Execute the job.
  42. *
  43. * @return void
  44. */
  45. public function handle()
  46. {
  47. $res = app()->redis->get($this->redisKey);
  48. if ($res) {
  49. //不为空 进来
  50. $time = Carbon::parse($res);
  51. $int = (new Carbon)->diffInMinutes($time, true); // $int 为正负数 ture 为绝对值
  52. if ($int >= 0) {
  53. $bike_no = $this->bike_no;
  54. $box_no = Bike::where('bike_no', $bike_no)->value('box_no');
  55. // 关闭订单
  56. $status = json_decode(file_get_contents($this->url . "&box_no={$box_no}&bike_no={$bike_no}&type=临时停车超时"), true);
  57. return;
  58. }
  59. }
  60. }
  61. }