BikeTemporaryWaitOverThirtyAutoCloseOrderJob.php 1.9 KB

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