You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

166 lines
4.8 KiB

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Interval extends Model
{
use HasFactory;
protected $table = 'interval_data';
protected $fillable = [
'is_outlaw',
'start_id',
'end_id',
'start_time',
'end_time',
'start_location',
'end_location',
'start_serialnumber',
'end_serialnumber',
'start_picture',
'end_picture',
'start_video',
'end_video',
'carnumber',
'cartype',
'start_path',
'end_path',
'distance',
'limit_speed',
'alert_speed',
'outlaw_speed',
'limit_time',
'cert',
'diff',
'speed',
'location',
'mergedone',
'intervalnumber',
'faildata',
'failreason',
'violationcode',
'processcheck',
'postcheck',
'jsoncheck',
'unreportreason',
'unreportpicture',
'unreportmergedone',
'merge_picture'
];
protected $hidden = [
'created_at',
'updated_at',
'deleted_at'
];
protected $casts = [
'is_outlaw' => 'boolean',
'distance' => 'float',
'limit_speed' => 'float',
'alert_speed' => 'float',
'outlaw_speed' => 'float',
'limit_time' => 'float',
'diff' => 'float',
'mergedone' => 'boolean',
'faildata' => 'boolean',
'processcheck' => 'integer',
'postcheck' => 'integer',
'unreportmergedone' => 'integer'
];
// append fields
protected $appends = [
'law_type',
];
public function violationlaw()
{
return $this->hasOne(ViolationLaw::class, 'violationcode', 'violationcode');
}
public function getLawTypeAttribute()
{
// 取得陣列
$violationtype = "區間超速";
// $violationtype = [];
if ($violationtype == "未依標誌標線號誌" || $violationtype == "未依標誌標線行駛" || $violationtype == "機車未依規定兩段式左轉") {
$violationtype = ["未依標誌標線號誌行駛"];
} else if ($violationtype == "闖紅燈") {
$violationtype = ["闖紅燈", "紅燈右轉", "紅燈越線"];
} else if ($violationtype == "未禮讓行人") {
$violationtype = ["未禮讓行人"];
} else if ($violationtype == "違規停車") {
$violationtype = ["違規停車"];
} else if ($violationtype == "未保持路口淨空") {
$violationtype = ["未保持路口淨空"];
} else if ($violationtype == "超速") {
$violationtype = ["超速"];
} else {
$violationtype = [$violationtype];
}
$except_arr =[
'3310146',
'3310148',
'4340069'
];
$types = ViolationLaw::whereIn('type', $violationtype)->whereNotIn('violationcode',$except_arr)->get();
$lawData = [];
foreach ($types as $type) {
$lawData["$type->violationcode"] = "[$type->violationcode] $type->display_name";
}
$customLaws = ViolationLaw::whereIn('violationcode', ['72000041', '72000051', '72000061'])->get();
foreach ($customLaws as $type) {
$lawData["$type->violationcode"] = "[$type->violationcode] $type->display_name";
}
return $lawData;
}
// public function getMergePictureAttribute($value)
// {
// // replace * with /
// return 'ParsingFiles/Interval/' . str_replace('*', '/', $value);
// }
// public function getStartPictureAttribute($value)
// {
// return $value ? asset('storage/' . $value) : null;
// }
// public function getEndPictureAttribute($value)
// {
// return $value ? asset('storage/' . $value) : null;
// }
// public function getStartVideoAttribute($value)
// {
// return $value ? asset('storage/' . $value) : null;
// }
// public function getEndVideoAttribute($value)
// {
// return $value ? asset('storage/' . $value) : null;
// }
// public function getUnreportPictureAttribute($value)
// {
// return $value ? asset('storage/' . $value) : null;
// }
// public function getMergePictureAttribute($value)
// {
// return $value ? asset('storage/' . $value) : null;
// }
// public function getCreatedAtAttribute($value)
// {
// return $value ? date('Y-m-d H:i:s', strtotime($value)) : null;
// }
// public function getUpdatedAtAttribute($value)
// {
// return $value ? date('Y-m-d H:i:s', strtotime($value)) : null;
// }
// public function getDeletedAtAttribute($value)
// {
// return $value ? date('Y-m-d H:i:s', strtotime($value)) : null;
// }
}