WorkOrder.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\Log;
  7. class WorkOrder extends Model
  8. {
  9. use ModelHelpers;
  10. //
  11. const NO_TAG = 'W';
  12. protected $table = "work_orders";
  13. protected $guarded = [];
  14. const TYPE_OTHER = 0; //其他
  15. const TYPE_CHARGE = 1; // 充电
  16. const TYPE_WATCH = 2; // 查看
  17. const TYPE_POWER_FAILURE = 3; // 断电
  18. // const TYPE_GPS_FAILURE = 4;// GPS故障
  19. const TYPE_ALERT = 5; // 警报
  20. const TYPE_STEAL = 6; // 偷盗
  21. const TYPE_HEADMAN = 7; // 组长工单
  22. const TYPE_TROUBLE = 8; // 故障
  23. const TYPE_HELP = 9; // 救援
  24. const TYPE_LOW_SPARE_BATTERY = 10; //备用电池电量低报警
  25. const TYPE_OFFLINE = 11; //离线
  26. const TYPE_BIKE_LOCATION_ERROR = 12;//车辆定位出现问题
  27. public static $typeMaps = [
  28. self::TYPE_CHARGE => '充电工单',
  29. self::TYPE_WATCH => '查看工单',
  30. self::TYPE_POWER_FAILURE => '断电工单',
  31. // self::TYPE_GPS_FAILURE => 'GPS故障工单',
  32. self::TYPE_ALERT => '警报工单',
  33. self::TYPE_STEAL => '偷盗工单',
  34. self::TYPE_HEADMAN => '组长工单',
  35. self::TYPE_TROUBLE => '故障工单',
  36. self::TYPE_HELP => '道路救援工单',
  37. self::TYPE_OTHER => '其他工单',
  38. self::TYPE_LOW_SPARE_BATTERY => '备用电池电量低报警',
  39. self::TYPE_OFFLINE => '离线工单',
  40. self::TYPE_BIKE_LOCATION_ERROR => '车辆定位出现问题',
  41. ];
  42. public static $typeWarningMaps = [
  43. self::TYPE_CHARGE => WarningLog::TYPE_BATTERY_LOW,
  44. self::TYPE_WATCH => 0,
  45. self::TYPE_POWER_FAILURE => WarningLog::TYPE_WARNING_CLOSE_ELECTRIC,
  46. // self::TYPE_GPS_FAILURE => 'GPS故障工单',
  47. self::TYPE_ALERT => WarningLog::TYPE_WARNING_BIKE_SHOCK,
  48. self::TYPE_STEAL => WarningLog::TYPE_WARNING_BIKE_OPEN,
  49. self::TYPE_HEADMAN => 0,
  50. self::TYPE_TROUBLE => WarningLog::TYPE_WARNING_BIKE_TROUBLE,
  51. self::TYPE_HELP => 0,
  52. self::TYPE_OTHER => 0,
  53. self::TYPE_LOW_SPARE_BATTERY => WarningLog::TYPE_WARNING_BATTERY_LOW,
  54. self::TYPE_OFFLINE => WarningLog::TYPE_BIKE_OFF_LINE,
  55. self::TYPE_BIKE_LOCATION_ERROR => WarningLog::TYPE_BIKE_LOCATION_ERROR,
  56. ];
  57. const PLANNED_STATUS_MEET = 1;
  58. const PLANNED_STATUS_WORK = 2;
  59. const PLANNED_STATUS_WORKED = 3;
  60. const PLANNED_STATUS_OVER = 4;
  61. public static $plannedMaps = [
  62. self::PLANNED_STATUS_MEET => '待接单',
  63. self::PLANNED_STATUS_WORK => '处理中',
  64. self::PLANNED_STATUS_WORKED => '已处理',
  65. self::PLANNED_STATUS_OVER => '已完成',
  66. ];
  67. const STATUS_OK = 1;
  68. const STATUS_NO = 0;
  69. public static $statusMaps = [
  70. self::STATUS_NO => '未确认',
  71. self::STATUS_OK => '已确认'
  72. ];
  73. const SOURCE_SYSTEM = 1;
  74. const SOURCE_ADMIN = 2;
  75. const SOURCE_REPAIR = 3;
  76. public static $sourceMaps = [
  77. self::SOURCE_SYSTEM => '系统生成',
  78. self::SOURCE_ADMIN => '管理员创建',
  79. self::SOURCE_REPAIR=>'地勤报修'
  80. ];
  81. public static $warningMaps = [
  82. 'battery' => '电池锁故障',
  83. 'bluetooth' => '蓝牙设备故障',
  84. 'ecu' => 'ECU通信故障',
  85. 'yixianzhi' => '一线制通信故障',
  86. 'wheel_lock' => '后轮锁故障',
  87. 'bms' => 'BMS故障',
  88. 'voice' => '语音喇叭故障',
  89. 'default' => '保留',
  90. ];
  91. public static function makeWorkNo(){
  92. // 订单流水号前缀
  93. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  94. for ($i = 0; $i < 10; $i++) {
  95. // 随机生成 6 位的数字
  96. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  97. // 判断是否已经存在
  98. if (!static::query()->where('work_no', $no)->exists()) {
  99. return $no;
  100. }
  101. }
  102. Log::warning('find order no failed');
  103. return false;
  104. }
  105. public function worker(){
  106. // 实际接单人员
  107. return $this->belongsTo(AdminUser::class,'worker_id','id');
  108. }
  109. public function workerOver(){
  110. // 实际维修人员
  111. return $this->belongsTo(AdminUser::class,'work_over_id','id');
  112. }
  113. public function bike(){
  114. return $this->belongsTo(Bike::class,'bike_id','id');
  115. }
  116. // public function user(){
  117. // return $this->belongsTo(User::class,'user_id','id');
  118. // }
  119. public function area(){
  120. return $this->belongsTo(Area::class,'area_id','id');
  121. }
  122. public function area_worker(){
  123. // 故障区域 所有维修人员
  124. return $this->hasMany(AdminUser::class,'area_id','area_id');
  125. }
  126. }