停车场管理系统
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.
 
 

105 lines
2.5 KiB

<?php
namespace App\Services;
use App\Models\ParkingAdminUser;
use Exception;
use Illuminate\Support\Facades\DB;
class ParkingAdminUserService extends BaseService
{
public static array $memberType
= [
1 => 'DIS',
2 => 'OMHK',
3 => 'MBHK',
4 => 'GBA',
5 => 'YUC',
6 => 'VMHK',
7 => 'ST',
8 => 'RCIM',
9 => 'OMCN',
10 => 'MBCN',
11 => 'PUBLIC'
];
protected string $menuTitle = 'parking_attendant';
// 创建
public function createModel(array $data)
{
try {
DB::beginTransaction();
$model = ParkingAdminUser::query()->create([
'name' => $data['name'],
'phone' => $data['phone'],
'member_type' => $data['member_type'],
'created_at' => get_datetime()
]);
$this->logService->logCreated($model, 'parking_attendant.create');
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
// 创建
public function updateModel(array $data, $id)
{
try {
DB::beginTransaction();
$model = ParkingAdminUser::query()->findOrFail($id);
$oldValue = $model->toArray();
$update = [
'name' => $data['name'],
'phone' => $data['phone'],
'member_type' => $data['member_type'],
'status' => $data['status'] ?? 1,
'updated_at' => get_datetime()
];
$model->update($update);
$this->logService->logUpdated(
$model,
$oldValue,
'parking_attendant.update'
);
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
public function deleteModel(int $id): bool
{
try {
DB::beginTransaction();
$model = ParkingAdminUser::query()->findOrFail($id);
$this->logService->logDeleted(
$model,
'parking_attendant.delete'
);
$model->delete();
DB::commit();
return true;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
}