VerifyChargeWorkOrderJob.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Bike;
  4. use App\Models\WorkOrder;
  5. use Carbon\Carbon;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Support\Facades\Log;
  12. class VerifyChargeWorkOrderJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. public $tries = 5;
  16. private $work_no;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct($work_no)
  23. {
  24. //
  25. $this->work_no = $work_no;
  26. }
  27. /**
  28. * Execute the job.
  29. *
  30. * @return void
  31. */
  32. public function handle()
  33. {
  34. //
  35. $work_order = WorkOrder::query()->where('work_no', $this->work_no)->first();
  36. if (empty($work_order)) {
  37. Log::error('charge工单验证时,找不到工单内容,工单号为:' . $this->work_no);
  38. return;
  39. }
  40. $bike_id = $work_order->bike_id;
  41. $bike = Bike::query()->find($bike_id);
  42. if (empty($bike)) {
  43. Log::error('charge工单验证时,找不到工单车辆信息,工单号为:' . $this->work_no);
  44. return;
  45. }
  46. if ($bike->battery_power > config('bike.huan_max_battery_power')) {
  47. try {
  48. $work_order->status = WorkOrder::STATUS_OK;
  49. $work_order->planned = WorkOrder::PLANNED_STATUS_OVER;
  50. $work_order->fix_end_time = Carbon::now();
  51. $work_order->save();
  52. } catch (\Exception $e) {
  53. Log::error('更新watch工单为结束状态失败' . $e->getMessage());
  54. }
  55. } else {
  56. // 未通过验证 改为未待处理状态
  57. try {
  58. $work_order->planned = WorkOrder::PLANNED_STATUS_WORK;
  59. $work_order->save();
  60. } catch (\Exception $e) {
  61. Log::error('更新watch工单为待处理状态失败' . $e->getMessage());
  62. }
  63. }
  64. }
  65. }