123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Jobs;
- use App\Models\Bike;
- use App\Models\WarningLog;
- use App\Models\WorkOrder;
- use Illuminate\Bus\Queueable;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Support\Facades\Log;
- // 验证是否真正长时间离线
- class VerifyRealOffLineWorkOrderJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- private $warning_id;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($warning_id)
- {
- //
- $this->warning_id = $warning_id;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- $warning = WarningLog::find($this->warning_id);
- if(empty($warning)) {
- Log::error('找不到警报相关信息,警报id为'.$this->warning_id);
- return;
- }
- $bike = Bike::where('bike_no',$warning->bike_no)->first();
- if(empty($bike)) {
- Log::error('找不到警报车辆相关信息,警报id为'.$this->warning_id.'车辆编号为'.$warning->bike_no);
- return;
- }
- if($bike->is_link == 0){
- $data = [
- 'work_no' => WorkOrder::makeWorkNo(),
- 'bike_no' => $warning->bike_no,
- 'bike_id' => $bike->id,
- 'source' => WorkOrder::SOURCE_SYSTEM,
- 'planned' => WorkOrder::PLANNED_STATUS_MEET,
- 'area_id' => $bike->put_area_id,
- 'type' => WorkOrder::TYPE_OFFLINE,
- 'reason' => WarningLog::$typeMaps[WarningLog::TYPE_BIKE_OFF_LINE],
- 'type_name' => WorkOrder::$typeMaps[WorkOrder::TYPE_OFFLINE],
- 'insert_time' => $warning->created_at,
- ];
- // 验证是否存在数据
- $verify = [
- 'type' => WorkOrder::TYPE_OFFLINE,
- 'bike_id' => $bike->id,
- 'status' => WorkOrder::STATUS_NO,
- ];
- WorkOrder::firstOrCreate($verify,$data);
- }
- }
- }
|