20 changed files with 917 additions and 1 deletions
@ -0,0 +1,31 @@ |
|||
<?php |
|||
|
|||
namespace App\Exports; |
|||
|
|||
use Maatwebsite\Excel\Concerns\FromArray; |
|||
|
|||
class ParkingSpaceRepairTemplateExport implements FromArray |
|||
{ |
|||
public function array(): array |
|||
{ |
|||
return [ |
|||
[ |
|||
__exports('global.index'), |
|||
__exports('parking_space.number'), |
|||
__exports('parking_space.floor'), |
|||
__exports('whitelist.parking'), |
|||
__exports('parking_repair_list.start_at'), |
|||
__exports('parking_repair_list.end_at') |
|||
], |
|||
[ |
|||
'1', |
|||
'L1M01', |
|||
'L1M', |
|||
'MSCP', |
|||
date("Y-m-d 10:00:00"), |
|||
date("Y-m-d 18:00:00") |
|||
] |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,469 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use App\Exceptions\CustomException; |
|||
use App\Exports\ParkingSpaceRepairTemplateExport; |
|||
use App\Imports\ParkingSpaceRepairImport; |
|||
use App\Models\AdminFloor; |
|||
use App\Models\AdminUsers; |
|||
use App\Models\Parking; |
|||
use App\Models\ParkingSpace; |
|||
use App\Models\ParkingSpaceRepair; |
|||
use App\Services\ApiResponseService; |
|||
use App\Services\ParkingSpaceRepairService; |
|||
use Exception; |
|||
use Illuminate\Http\JsonResponse; |
|||
use Illuminate\Http\Request; |
|||
use Illuminate\Support\Facades\Storage; |
|||
use Illuminate\Support\Facades\Validator; |
|||
use Illuminate\Validation\ValidationException; |
|||
use Maatwebsite\Excel\Facades\Excel; |
|||
|
|||
class ParkingSpaceRepairController extends BaseController |
|||
{ |
|||
|
|||
protected string $menuUri = 'parkingRepair'; |
|||
|
|||
/** |
|||
* @var ParkingSpaceRepairService |
|||
*/ |
|||
protected ParkingSpaceRepairService $service; |
|||
|
|||
/** |
|||
* 构造函数 |
|||
* @param ApiResponseService $responseService |
|||
* @param ParkingSpaceRepairService $service |
|||
*/ |
|||
public function __construct( |
|||
ApiResponseService $responseService, |
|||
ParkingSpaceRepairService $service |
|||
) { |
|||
parent::__construct($responseService); |
|||
$this->service = $service; |
|||
} |
|||
|
|||
/** |
|||
* @param Request $request |
|||
* @return JsonResponse |
|||
*/ |
|||
public function index(Request $request): JsonResponse |
|||
{ |
|||
try { |
|||
$query = ParkingSpaceRepair::query(); |
|||
|
|||
if ($request->has('parking_space_number')) { |
|||
$number = $request->input('parking_space_number'); |
|||
if ($number) { |
|||
$space_id = ParkingSpace::getValueId($number); |
|||
if ($space_id) { |
|||
$query->where('space_id', $space_id); |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if ($request->has('parking_id')) { |
|||
$parking_id = $request->input('parking_id'); |
|||
$floor_id = $request->input('floor_id'); |
|||
if ($parking_id && !$floor_id) { |
|||
$floor_ids = AdminFloor::query()->where( |
|||
'building_floor', |
|||
$parking_id |
|||
)->pluck('id')->toArray(); |
|||
if ($floor_ids) { |
|||
$space_ids = ParkingSpace::query()->whereIn( |
|||
'floor_id', |
|||
$floor_ids |
|||
)->pluck('id')->toArray(); |
|||
if ($space_ids) { |
|||
$query->whereIn('space_id', $space_ids); |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if ($request->has('floor_id')) { |
|||
$floor_id = $request->input('floor_id'); |
|||
if ($floor_id) { |
|||
$space_ids = ParkingSpace::query()->where( |
|||
'floor_id', |
|||
$floor_id |
|||
)->pluck('id')->toArray(); |
|||
if ($space_ids) { |
|||
$query->whereIn('space_id', $space_ids); |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if ($request->has('start_date')) { |
|||
$start_date = $request->input('start_date'); |
|||
if ($start_date) { |
|||
$query->where('start_at', '>=', $start_date . ' 00:00:00'); |
|||
} |
|||
} |
|||
|
|||
if ($request->has('end_date')) { |
|||
$end_date = $request->input('end_date'); |
|||
if ($end_date) { |
|||
$query->where('end_at', '<=', $end_date . ' 23:59:59'); |
|||
} |
|||
} |
|||
|
|||
if ($request->has('admin_user')) { |
|||
$admin_user = $request->input('admin_user'); |
|||
if ($admin_user) { |
|||
$admin_user_ids = AdminUsers::getIds($admin_user); |
|||
if ($admin_user_ids) { |
|||
$query->whereIn('admin_user_id', $admin_user_ids); |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 分页 |
|||
$page = $request->input('page', 1); |
|||
$perPage = $request->input('per_page', 10); |
|||
|
|||
$total = $query->count(); |
|||
$items = $query->latest()->forPage($page, $perPage)->get()->each( |
|||
function ($item) { |
|||
return $this->service->getItem($item); |
|||
} |
|||
); |
|||
|
|||
return $this->responseService->success([ |
|||
'items' => $items, |
|||
'total' => $total, |
|||
'page' => $page, |
|||
'per_page' => $perPage, |
|||
'last_page' => ceil($total / $perPage), |
|||
]); |
|||
} catch (Exception $e) { |
|||
$m_prefix = __('exception.exception_handler.resource'); |
|||
return $this->responseService->systemError( |
|||
$m_prefix . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 列表搜索数据 |
|||
* @return JsonResponse |
|||
*/ |
|||
public function search(): JsonResponse |
|||
{ |
|||
try { |
|||
$data = [ |
|||
'parking_list' => Parking::getData(), |
|||
'floor_list' => AdminFloor::getData() |
|||
]; |
|||
return $this->responseService->success($data); |
|||
} catch (Exception $e) { |
|||
$m_prefix = __('exception.exception_handler.resource'); |
|||
return $this->responseService->systemError( |
|||
$m_prefix . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @return JsonResponse |
|||
*/ |
|||
public function create(): JsonResponse |
|||
{ |
|||
try { |
|||
$data = [ |
|||
'parking_space_list' => ParkingSpace::getFloorData() |
|||
]; |
|||
return $this->responseService->success($data); |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.get_data_failed') . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param string $id |
|||
* @return JsonResponse |
|||
*/ |
|||
public function edit(string $id): JsonResponse |
|||
{ |
|||
try { |
|||
$this->validateId($id, ParkingSpaceRepair::class); |
|||
$data = [ |
|||
'parking_space_list' => ParkingSpace::getFloorData(), |
|||
'item' => ParkingSpaceRepair::query()->find($id, [ |
|||
'id', |
|||
'space_id', |
|||
'start_at', |
|||
'end_at' |
|||
]) |
|||
]; |
|||
$ParkingSpace = ParkingSpace::query()->find( |
|||
$data['item']['space_id'] |
|||
); |
|||
$data['item']['parking_space_name'] = $ParkingSpace['number']; |
|||
$data['item']['floor'] = AdminFloor::getName( |
|||
$ParkingSpace['floor_id'] |
|||
); |
|||
unset($data['item']['space_id']); |
|||
return $this->responseService->success($data); |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.get_data_failed') . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param Request $request |
|||
* @param string $id |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function update(Request $request, string $id): JsonResponse |
|||
{ |
|||
try { |
|||
$data = $request->all(); |
|||
$this->saveValidator($data); |
|||
$data['admin_user_id'] = $this->adminUserId; |
|||
$this->service->updateModel($data, $id); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.update_succeeded') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('admin.operation_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* @param int $id |
|||
* @return void |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
protected function saveValidator(array $data, int $id = 0): void |
|||
{ |
|||
$rules = [ |
|||
'parking_space_name' => 'required', |
|||
'start_at' => 'required', |
|||
'end_at' => 'required' |
|||
]; |
|||
$messages = [ |
|||
'parking_space_name.required' => __validation( |
|||
'parking_repair_list.psn_empty' |
|||
), |
|||
'start_at.required' => __validation( |
|||
'parking_repair_list.s_empty' |
|||
), |
|||
'end_at.required' => __validation( |
|||
'parking_repair_list.e_empty' |
|||
) |
|||
]; |
|||
if ($id) { |
|||
$this->validateId($id, ParkingSpaceRepair::class); |
|||
} |
|||
$validator = Validator::make($data, $rules, $messages); |
|||
|
|||
$start_at_times = strtotime($data['start_at']); |
|||
$end_at_times = strtotime($data['end_at']); |
|||
if ($start_at_times >= $end_at_times) { |
|||
throw new CustomException( |
|||
__validation('parking_repair_list.date_error') |
|||
); |
|||
} |
|||
|
|||
if ($validator->fails()) { |
|||
throw new ValidationException($validator); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param string $id |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function destroy(string $id): JsonResponse |
|||
{ |
|||
try { |
|||
$this->validateId($id, ParkingSpaceRepair::class); |
|||
$this->service->deleteModel($id); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.delete_succeeded') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('admin.operation_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param Request $request |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function batchDelete(Request $request): JsonResponse |
|||
{ |
|||
try { |
|||
$data = $request->all(); |
|||
$rules = [ |
|||
'ids' => 'required|array', |
|||
]; |
|||
$messages = [ |
|||
'ids.required' => __validation( |
|||
'parking_repair_list.ids_empty' |
|||
), |
|||
'ids.array' => __validation( |
|||
'parking_repair_list.ids_array' |
|||
), |
|||
]; |
|||
$validator = Validator::make($data, $rules, $messages); |
|||
|
|||
if ($validator->fails()) { |
|||
throw new ValidationException($validator); |
|||
} |
|||
$ids = $data['ids']; |
|||
$this->service->batchDeleteModel($ids); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.delete_succeeded') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('admin.operation_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public function batchImport(Request $request) |
|||
{ |
|||
try { |
|||
// 1. 验证上传的文件 |
|||
$data = $request->all(); |
|||
$validator = Validator::make($data, [ |
|||
'file' => 'required|mimes:xlsx,xls,csv,txt|max:2048' |
|||
], [ |
|||
'file.required' => __validation('admin_list_vip.file_empty'), |
|||
'file.mimes' => __validation('admin_list_vip.file_mimes'), |
|||
'file.max' => __validation('admin_list_vip.file_max') |
|||
]); |
|||
if ($validator->fails()) { |
|||
throw new ValidationException($validator); |
|||
} |
|||
|
|||
// 2. 获取上传的文件 |
|||
$file = $request->file('file'); |
|||
|
|||
// 3. 正确的做法:先存储文件,再获取绝对路径进行导入 |
|||
$path = $file->store('imports'); |
|||
|
|||
// 4. 执行导入(使用存储后的绝对路径) |
|||
// storage_path('app') 获取 storage/app 的绝对路径 |
|||
Excel::import( |
|||
new ParkingSpaceRepairImport($this->adminUserId), |
|||
storage_path('app/' . $path) |
|||
); |
|||
|
|||
// 5. (可选)导入完成后删除临时文件 |
|||
Storage::delete($path); |
|||
|
|||
return $this->responseService->success( |
|||
__('controller.import.success') |
|||
); |
|||
} catch (ValidationException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('exception.admin_vip_list.import_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param Request $request |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function store(Request $request): JsonResponse |
|||
{ |
|||
try { |
|||
$data = $request->all(); |
|||
$this->saveValidator($data); |
|||
$data['admin_user_id'] = $this->adminUserId; |
|||
$this->service->createModel($data); |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.save_succeeded') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('admin.operation_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public function downloadTemplate() |
|||
{ |
|||
return Excel::download( |
|||
new ParkingSpaceRepairTemplateExport(), |
|||
set_space_underline(__exports('parking_repair_list.list')) |
|||
. get_datetime('date_') |
|||
. '.xlsx' |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* @return JsonResponse |
|||
* @throws CustomException |
|||
* @throws ValidationException |
|||
*/ |
|||
public function synchronizeList(): JsonResponse |
|||
{ |
|||
try { |
|||
return $this->responseService->success( |
|||
null, |
|||
__('admin.operation_successful') |
|||
); |
|||
} catch (ValidationException|CustomException $e) { |
|||
throw $e; |
|||
} catch (Exception $e) { |
|||
return $this->responseService->systemError( |
|||
__('admin.operation_failed') . ':' |
|||
. $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
<?php |
|||
|
|||
namespace App\Imports; |
|||
|
|||
use App\Models\Parking; |
|||
use App\Models\ParkingSpace; |
|||
use App\Services\OperationLogService; |
|||
use App\Services\ParkingSpaceRepairService; |
|||
use Maatwebsite\Excel\Concerns\ToModel; |
|||
use Maatwebsite\Excel\Concerns\WithChunkReading; |
|||
|
|||
class ParkingSpaceRepairImport implements ToModel, WithChunkReading |
|||
{ |
|||
protected int $index = 1; |
|||
protected int $user_id; |
|||
|
|||
public function __construct($admin_user_id) |
|||
{ |
|||
$this->user_id = $admin_user_id; |
|||
} |
|||
|
|||
public function model(array $row) |
|||
{ |
|||
if ($this->index == 1) { |
|||
$this->index += 1; |
|||
return; |
|||
} |
|||
$space_number = $row[1]; |
|||
if (empty($space_number)) { |
|||
return; |
|||
} |
|||
$floor_name = $row[2]; |
|||
if (empty($floor_name)) { |
|||
return; |
|||
} |
|||
$parking_name = $row[3]; |
|||
if (empty($parking_name)) { |
|||
return; |
|||
} |
|||
$start_at = $row[4]; |
|||
$start_times = strtotime($start_at); |
|||
if (empty($start_at) || !$start_times) { |
|||
return; |
|||
} |
|||
$end_at = $row[5]; |
|||
$end_times = strtotime($end_at); |
|||
if (empty($end_at) || !$end_times) { |
|||
return; |
|||
} |
|||
if ($start_times >= $end_times) { |
|||
return; |
|||
} |
|||
$space_id = ParkingSpace::getValueId($space_number); |
|||
if (empty($space_id)) { |
|||
return; |
|||
} |
|||
|
|||
$service = new ParkingSpaceRepairService(new OperationLogService()); |
|||
$service->createModel([ |
|||
'admin_user_id' => $this->user_id, |
|||
'parking_space_name' => $space_number, |
|||
'start_at' => date("Y-m-d H:i:s", $start_times), |
|||
'end_at' => date("Y-m-d H:i:s", $end_times) |
|||
]); |
|||
} |
|||
|
|||
public function chunkSize(): int |
|||
{ |
|||
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析 |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
|
|||
class ParkingSpaceRepair extends Model |
|||
{ |
|||
use HasFactory, SoftDeletes; |
|||
|
|||
protected $table = 'parking_space_repair'; |
|||
|
|||
protected $fillable |
|||
= [ |
|||
'space_id', |
|||
'parking_id', |
|||
'admin_user_id', |
|||
'start_at', |
|||
'end_at', |
|||
'sync_status', |
|||
'sync_at' |
|||
]; |
|||
|
|||
protected $hidden |
|||
= [ |
|||
'created_at', |
|||
'updated_at', |
|||
'deleted_at' |
|||
]; |
|||
|
|||
public function getStartAtAttribute($value): string |
|||
{ |
|||
return $value ? date("Y-m-d H:i:s", strtotime($value)) : $value; |
|||
} |
|||
|
|||
public function getEndAtAttribute($value): string |
|||
{ |
|||
return $value ? date("Y-m-d H:i:s", strtotime($value)) : $value; |
|||
} |
|||
|
|||
public function getSyncAtAttribute($value): string |
|||
{ |
|||
return $value ? date("Y-m-d H:i:s", strtotime($value)) : ''; |
|||
} |
|||
} |
|||
@ -0,0 +1,171 @@ |
|||
<?php |
|||
|
|||
namespace App\Services; |
|||
|
|||
use App\Models\AdminFloor; |
|||
use App\Models\AdminUsers; |
|||
use App\Models\Parking; |
|||
use App\Models\ParkingSpace; |
|||
use App\Models\ParkingSpaceRepair; |
|||
use Exception; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class ParkingSpaceRepairService extends BaseService |
|||
{ |
|||
|
|||
public array $syncStatusArr |
|||
= [ |
|||
'not_synced', |
|||
'synced' |
|||
]; |
|||
protected string $menuTitle = 'parking_repair_list'; |
|||
|
|||
public function getItem($item) |
|||
{ |
|||
$ParkingSpace = ParkingSpace::query()->find($item['space_id']); |
|||
$item['parking_space_number'] = $ParkingSpace['number']; |
|||
$Floor = AdminFloor::query()->find($ParkingSpace['floor_id']); |
|||
$item['floor'] = $Floor['name']; |
|||
$item['parking'] = Parking::getName($Floor['building_floor']); |
|||
$item['admin_user'] = AdminUsers::getUsername($item['admin_user_id']); |
|||
$syncStatusArr = $this->getSyncStatus(); |
|||
$item['sync_status_str'] = $syncStatusArr[$item['sync_status']] ?? ''; |
|||
unset($item['admin_user_id'], $item['space_id']); |
|||
return $item; |
|||
} |
|||
|
|||
/** |
|||
* @return array|string[] |
|||
*/ |
|||
public function getSyncStatus(): array |
|||
{ |
|||
$syncStatusArr = $this->syncStatusArr; |
|||
foreach ($syncStatusArr as $key => $value) { |
|||
$syncStatusArr[$key] = __service($this->menuTitle . '.' . $value); |
|||
} |
|||
return $syncStatusArr; |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* @throws Exception |
|||
*/ |
|||
public function createModel(array $data) |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
$spaceNameArr = explode(',', $data['parking_space_name']); |
|||
foreach ($spaceNameArr as $parking_space_name) { |
|||
$space_id = ParkingSpace::getValueId($parking_space_name); |
|||
|
|||
$model = ParkingSpaceRepair::query()->create([ |
|||
'space_id' => $space_id, |
|||
'admin_user_id' => $data['admin_user_id'], |
|||
'start_at' => $data['start_at'], |
|||
'end_at' => $data['end_at'], |
|||
'created_at' => get_datetime() |
|||
]); |
|||
|
|||
$this->logService->logCreated( |
|||
$model, |
|||
$this->menuTitle . '.create' |
|||
); |
|||
} |
|||
|
|||
DB::commit(); |
|||
return $model; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* @param int $id |
|||
* @throws Exception |
|||
*/ |
|||
public function updateModel(array $data, int $id) |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
|
|||
$space_id = ParkingSpace::getValueId($data['parking_space_name']); |
|||
|
|||
// 更新 |
|||
$model = ParkingSpaceRepair::query()->findOrFail($id); |
|||
$oldValues = $model->toArray(); |
|||
|
|||
$model->update([ |
|||
'space_id' => $space_id, |
|||
'admin_user_id' => $data['admin_user_id'], |
|||
'start_at' => $data['start_at'], |
|||
'end_at' => $data['end_at'], |
|||
'updated_at' => get_datetime() |
|||
]); |
|||
|
|||
$this->logService->logUpdated( |
|||
$model, |
|||
$oldValues, |
|||
$this->menuTitle . '.update' |
|||
); |
|||
|
|||
DB::commit(); |
|||
return $model; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param $id |
|||
* @return bool |
|||
* @throws Exception |
|||
*/ |
|||
public function deleteModel($id): bool |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
|
|||
$model = ParkingSpaceRepair::query()->findOrFail($id); |
|||
|
|||
$this->logService->logDeleted($model, $this->menuTitle . '.delete'); |
|||
|
|||
$model->delete(); |
|||
|
|||
DB::commit(); |
|||
return true; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param $ids |
|||
* @return bool |
|||
* @throws Exception |
|||
*/ |
|||
public function batchDeleteModel($ids): bool |
|||
{ |
|||
try { |
|||
DB::beginTransaction(); |
|||
|
|||
foreach ($ids as $id) { |
|||
$model = ParkingSpaceRepair::query()->findOrFail($id); |
|||
$this->logService->logDeleted( |
|||
$model, |
|||
$this->menuTitle . '.delete' |
|||
); |
|||
$model->delete(); |
|||
} |
|||
|
|||
DB::commit(); |
|||
return true; |
|||
} catch (Exception $e) { |
|||
DB::rollBack(); |
|||
throw $e; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
return new class extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
*/ |
|||
public function up(): void |
|||
{ |
|||
Schema::create('parking_space_repair', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->integer('space_id')->comment('车位'); |
|||
$table->integer('admin_user_id')->comment('操作员'); |
|||
$table->timestamp('start_at')->comment('维修开始时间'); |
|||
$table->timestamp('end_at')->nullable()->comment('维修结束时间'); |
|||
$table->tinyInteger('sync_status')->default(0)->comment('同步状态'); |
|||
$table->timestamp('sync_at')->nullable()->comment('维修结束时间'); |
|||
$table->timestamps(); |
|||
$table->softDeletes(); |
|||
$table->innoDb(); |
|||
$table->comment('车位维修'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('parking_space_repair'); |
|||
} |
|||
}; |
|||
Loading…
Reference in new issue