12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- *
- *
- * @category xxx
- * @package PSR
- * @subpackage Documentation\API
- * @author xxx <xxx@xxx.com>
- * @license GPL https://xxx.com
- * @link https://xxx.com
- * @ctime: 2020/3/28 10:29
- */
- namespace App\Jobs;
- use App\Models\Bike;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Log;
- class BikeTemporaryWaitOverThirtyAutoCloseOrderJob extends Job
- {
- protected $mobile = '';
- protected $bike_no = '';
- protected $start_use_time = '';
- protected $redisKey = '';
- public $tries = 1;
- private $url = '';
- /**
- * 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);
- $this->url = config("app.url") . "/api/relay/order/auto-close?key=" . config('auth.api_token');
- }
- /**
- * 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 >= 0) {
- $bike_no = $this->bike_no;
- $box_no = Bike::where('bike_no', $bike_no)->value('box_no');
- // 关闭订单
- $status = json_decode(file_get_contents($this->url . "&box_no={$box_no}&bike_no={$bike_no}&type=临时停车超时"), true);
- return;
- }
- }
- }
- }
|