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.
114 lines
2.8 KiB
114 lines
2.8 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ParkingSpace extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $table = 'parking_space';
|
|
|
|
protected $fillable
|
|
= [
|
|
'floor_id',
|
|
'number',
|
|
'space_attr_id',
|
|
'license_plate_id',
|
|
'berthing_time',
|
|
'recognition',
|
|
'status',
|
|
'space_type_id',
|
|
'operation_type',
|
|
'pic_url',
|
|
'customer_id',
|
|
'member_id',
|
|
'region_id'
|
|
];
|
|
|
|
protected $hidden
|
|
= [
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at'
|
|
];
|
|
|
|
|
|
public function getUpdatedAtAttribute($value): string
|
|
{
|
|
return is_null($value)
|
|
? ''
|
|
: date('Y-m-d H:i', strtotime($value));
|
|
}
|
|
|
|
public function getBerthingTimeAttribute($value): string
|
|
{
|
|
return is_null($value)
|
|
? ''
|
|
: date('Y-m-d H:i', strtotime($value));
|
|
}
|
|
|
|
public static function getNumber($id)
|
|
{
|
|
return self::query()->where('id', $id)->value('number');
|
|
}
|
|
|
|
public static function getId($number)
|
|
{
|
|
return self::query()->where('number', 'like', "%{$number}%")->pluck(
|
|
'id'
|
|
)->toArray();
|
|
}
|
|
|
|
public static function getValueId($number)
|
|
{
|
|
return self::query()->where('number', $number)->value('id');
|
|
}
|
|
|
|
public static function getCount()
|
|
{
|
|
return self::query()->count();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return self::query()->orderBy('created_at', 'desc')->select(
|
|
['id', 'number']
|
|
)->get()->toArray();
|
|
}
|
|
|
|
public static function getFloorData()
|
|
{
|
|
return self::query()->orderBy('created_at', 'desc')->select(
|
|
['id', 'number', 'floor_id']
|
|
)->get()->each(function ($item) {
|
|
$item['floor'] = AdminFloor::getName($item['floor_id']);
|
|
unset($item['floor_id']);
|
|
return $item;
|
|
})->toArray();
|
|
}
|
|
|
|
public static function getModeFloorCount($floor_id, $spaceIds, $status = '11', $type = '')
|
|
{
|
|
$model = self::query();
|
|
$model->where('floor_id', $floor_id);
|
|
$model->whereIn('id', $spaceIds);
|
|
if ($status == '11') {
|
|
$model->whereIn('status', [0, 1]);
|
|
} else {
|
|
$model->where('status', $status);
|
|
}
|
|
if ($type) {
|
|
$model->where('space_type_id', $type);
|
|
}
|
|
return $model->count();
|
|
}
|
|
|
|
public static function getFloorCount($floor_id)
|
|
{
|
|
return self::query()->where('floor_id', $floor_id)->count();
|
|
}
|
|
}
|
|
|