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