123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- class WorkOrder extends Model
- {
- use ModelHelpers;
- //
- const NO_TAG = 'W';
- protected $table = "work_orders";
- protected $guarded = [];
- const TYPE_OTHER = 0; //其他
- const TYPE_CHARGE = 1; // 充电
- const TYPE_WATCH = 2; // 查看
- const TYPE_POWER_FAILURE = 3; // 断电
- // const TYPE_GPS_FAILURE = 4;// GPS故障
- const TYPE_ALERT = 5; // 警报
- const TYPE_STEAL = 6; // 偷盗
- const TYPE_HEADMAN = 7; // 组长工单
- const TYPE_TROUBLE = 8; // 故障
- const TYPE_HELP = 9; // 救援
- const TYPE_LOW_SPARE_BATTERY = 10; //备用电池电量低报警
- const TYPE_OFFLINE = 11; //离线
- const TYPE_BIKE_LOCATION_ERROR = 12;//车辆定位出现问题
- public static $typeMaps = [
- self::TYPE_CHARGE => '充电工单',
- self::TYPE_WATCH => '查看工单',
- self::TYPE_POWER_FAILURE => '断电工单',
- // self::TYPE_GPS_FAILURE => 'GPS故障工单',
- self::TYPE_ALERT => '警报工单',
- self::TYPE_STEAL => '偷盗工单',
- self::TYPE_HEADMAN => '组长工单',
- self::TYPE_TROUBLE => '故障工单',
- self::TYPE_HELP => '道路救援工单',
- self::TYPE_OTHER => '其他工单',
- self::TYPE_LOW_SPARE_BATTERY => '备用电池电量低报警',
- self::TYPE_OFFLINE => '离线工单',
- self::TYPE_BIKE_LOCATION_ERROR => '车辆定位出现问题',
- ];
- public static $typeWarningMaps = [
- self::TYPE_CHARGE => WarningLog::TYPE_BATTERY_LOW,
- self::TYPE_WATCH => 0,
- self::TYPE_POWER_FAILURE => WarningLog::TYPE_WARNING_CLOSE_ELECTRIC,
- // self::TYPE_GPS_FAILURE => 'GPS故障工单',
- self::TYPE_ALERT => WarningLog::TYPE_WARNING_BIKE_SHOCK,
- self::TYPE_STEAL => WarningLog::TYPE_WARNING_BIKE_OPEN,
- self::TYPE_HEADMAN => 0,
- self::TYPE_TROUBLE => WarningLog::TYPE_WARNING_BIKE_TROUBLE,
- self::TYPE_HELP => 0,
- self::TYPE_OTHER => 0,
- self::TYPE_LOW_SPARE_BATTERY => WarningLog::TYPE_WARNING_BATTERY_LOW,
- self::TYPE_OFFLINE => WarningLog::TYPE_BIKE_OFF_LINE,
- self::TYPE_BIKE_LOCATION_ERROR => WarningLog::TYPE_BIKE_LOCATION_ERROR,
- ];
- const PLANNED_STATUS_MEET = 1;
- const PLANNED_STATUS_WORK = 2;
- const PLANNED_STATUS_WORKED = 3;
- const PLANNED_STATUS_OVER = 4;
- public static $plannedMaps = [
- self::PLANNED_STATUS_MEET => '待接单',
- self::PLANNED_STATUS_WORK => '处理中',
- self::PLANNED_STATUS_WORKED => '已处理',
- self::PLANNED_STATUS_OVER => '已完成',
- ];
- const STATUS_OK = 1;
- const STATUS_NO = 0;
- public static $statusMaps = [
- self::STATUS_NO => '未确认',
- self::STATUS_OK => '已确认'
- ];
- const SOURCE_SYSTEM = 1;
- const SOURCE_ADMIN = 2;
- const SOURCE_REPAIR = 3;
- public static $sourceMaps = [
- self::SOURCE_SYSTEM => '系统生成',
- self::SOURCE_ADMIN => '管理员创建',
- self::SOURCE_REPAIR=>'地勤报修'
- ];
- public static $warningMaps = [
- 'battery' => '电池锁故障',
- 'bluetooth' => '蓝牙设备故障',
- 'ecu' => 'ECU通信故障',
- 'yixianzhi' => '一线制通信故障',
- 'wheel_lock' => '后轮锁故障',
- 'bms' => 'BMS故障',
- 'voice' => '语音喇叭故障',
- 'default' => '保留',
- ];
- public static function makeWorkNo(){
- // 订单流水号前缀
- $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
- for ($i = 0; $i < 10; $i++) {
- // 随机生成 6 位的数字
- $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
- // 判断是否已经存在
- if (!static::query()->where('work_no', $no)->exists()) {
- return $no;
- }
- }
- Log::warning('find order no failed');
- return false;
- }
- public function worker(){
- // 实际接单人员
- return $this->belongsTo(AdminUser::class,'worker_id','id');
- }
- public function workerOver(){
- // 实际维修人员
- return $this->belongsTo(AdminUser::class,'work_over_id','id');
- }
- public function bike(){
- return $this->belongsTo(Bike::class,'bike_id','id');
- }
- // public function user(){
- // return $this->belongsTo(User::class,'user_id','id');
- // }
- public function area(){
- return $this->belongsTo(Area::class,'area_id','id');
- }
- public function area_worker(){
- // 故障区域 所有维修人员
- return $this->hasMany(AdminUser::class,'area_id','area_id');
- }
- }
|