Browse Source

限制超管无法删除,VIP列表优化

master
wanghongjun 1 month ago
parent
commit
f6fc991fc2
  1. 2
      app/Exports/ParkingVipListExport.php
  2. 55
      app/Http/Controllers/Admin/VipAccessRecordController.php
  3. 7
      app/Http/Controllers/Admin/VipListController.php
  4. 6
      app/Imports/ParkingVipListImport.php
  5. 2
      app/Models/ParkingVipList.php
  6. 3
      app/Services/AdminUsersService.php
  7. 19
      app/Services/ParkingLicensePlateService.php
  8. 15
      app/Services/ParkingVipListService.php
  9. 2
      database/migrations/2026_03_02_110943_create_parking_vip_list_table.php
  10. 4
      database/migrations/2026_03_04_160517_create_parking_vip_access_record_table.php
  11. 3
      resources/lang/en/service.php
  12. 3
      resources/lang/zh-CN/service.php
  13. 3
      resources/lang/zh-TW/service.php

2
app/Exports/ParkingVipListExport.php

@ -3,6 +3,7 @@
namespace App\Exports;
use App\Models\AdminUsers;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingVipList;
use Illuminate\Database\Eloquent\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
@ -16,6 +17,7 @@ class ParkingVipListExport implements FromCollection, WithHeadings
public function collection(): Collection
{
return ParkingVipList::all()->each(function ($item) {
$item['license'] = ParkingLicensePlate::getNumber($item['license_id']);
$item['user_id'] = AdminUsers::getUsername(
$item['user_id']
);

55
app/Http/Controllers/Admin/VipAccessRecordController.php

@ -3,6 +3,8 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingSpace;
use App\Models\ParkingVipAccessRecord;
use App\Models\ParkingVipList;
use App\Models\ParkingSpaceType;
@ -36,31 +38,36 @@ class VipAccessRecordController extends Controller
if ($request->has('space_type')) {
$space_type = $request->input('space_type');
if (!empty($space_type)) {
$space_type_ids = ParkingSpaceType::query()->where(
'name',
'like',
"%{$space_type}%"
)->pluck('id');
$query->whereIn('parking_space_id', $space_type_ids);
$query->where('space_type_id', $space_type);
}
}
if ($request->exists('space_number')) {
$space_number = $request->input('space_number');
if (!empty($space_number)) {
$space_id = ParkingSpace::getId($space_number);
if ($space_id) {
$query->where('space_id', $space_id);
} else {
$query->where('id', 0);
}
}
}
if ($request->has('license')) {
$license = $request->input('license');
if (!empty($license)) {
$vipIds = ParkingVipList::query()->where(
'license',
'like',
"%{$license}%"
)->pluck('id');
if ($vipIds) {
$query->whereIn('vip_list_id', $vipIds);
$license_ids = ParkingLicensePlate::getId($license);
if ($license_ids) {
$vipIds = ParkingVipList::query()->whereIn(
'license_id',
$license_ids
)->pluck('id');
if ($vipIds) {
$query->whereIn('vip_list_id', $vipIds);
} else {
$query->where('id', 0);
}
} else {
$query->where('id', 0);
}
@ -125,20 +132,18 @@ class VipAccessRecordController extends Controller
protected function optionItem($item)
{
$item['license_number'] = ParkingVipList::query()->where(
'id',
$item['vip_list_id']
)->value('license');
$item['space_type'] = ParkingSpaceType::query()->where(
'id',
$item
['parking_space_id']
)->value('name');
$item['space_number'] = "";
$license_id = ParkingVipList::query()->where(
'id',
$item['vip_list_id']
)->value('license_id') ?? 0;
$item['license_number'] = ParkingLicensePlate::getNumber($license_id)
?? '';
$item['space_number'] = ParkingSpace::getNumber($item['space_id']);
$item['space_type'] = ParkingSpaceType::getName($item['space_type_id']);
unset(
$item['vip_list_id'],
$item['parking_space_id'],
$item['parking_number_id']
$item['space_id'],
$item['space_type_id']
);
return $item;
}

7
app/Http/Controllers/Admin/VipListController.php

@ -7,6 +7,7 @@ use App\Exports\ParkingVipListExport;
use App\Exports\ParkingVipListImportTemplateExport;
use App\Imports\ParkingVipListImport;
use App\Models\AdminUsers;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingVipList;
use App\Services\ParkingVipListService;
use App\Services\ApiResponseService;
@ -51,7 +52,8 @@ class VipListController extends BaseController
if ($request->has('license')) {
$license = $request->input('license');
if (!empty($license)) {
$query->where('license', 'like', "%{$license}%");
$license_id = ParkingLicensePlate::getValueId($license);
$query->where('license_id', $license_id);
}
}
// 分页
@ -64,7 +66,8 @@ class VipListController extends BaseController
$item['username'] = AdminUsers::getUsername(
$item['user_id']
);
unset($item['user_id']);
$item['license'] = ParkingLicensePlate::getNumber($item['license_id']);
unset($item['user_id'], $item['license_id']);
return $item;
}
);

6
app/Imports/ParkingVipListImport.php

@ -4,6 +4,7 @@ namespace App\Imports;
use App\Models\ParkingVipList;
use App\Services\OperationLogService;
use App\Services\ParkingLicensePlateService;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
@ -29,11 +30,12 @@ class ParkingVipListImport implements ToModel, WithHeadingRow
{
if (isset($row['license_plate_no']) && $row['license_plate_no']) {
$license = $row['license_plate_no'];
if (!ParkingVipList::query()->where('license', $license)
$license_id = (new ParkingLicensePlateService($this->logService))->createLicenseId($license);
if (!ParkingVipList::query()->where('license_id', $license_id)
->exists()
) {
$model = ParkingVipList::query()->create([
'license' => $license,
'license_id' => $license_id,
'user_id' => Auth::guard('sanctum')->user()['id'],
'created_at' => get_datetime()
]);

2
app/Models/ParkingVipList.php

@ -13,7 +13,7 @@ class ParkingVipList extends Model
protected $table = 'parking_vip_list';
protected $fillable = [
'license',
'license_id',
'user_id'
];

3
app/Services/AdminUsersService.php

@ -158,6 +158,9 @@ final class AdminUsersService
DB::beginTransaction();
$model = AdminUsers::findOrFail($id);
if ($model['username'] == 'Admin' || $id == 1) {
throw new Exception(__('service.admin_user.not_del'));
}
$this->logService->logDeleted($model, 'admin_user.delete');

19
app/Services/ParkingLicensePlateService.php

@ -3,9 +3,8 @@
namespace App\Services;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingSpaceType;
use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class ParkingLicensePlateService
@ -155,4 +154,20 @@ class ParkingLicensePlateService
}
}
public function createLicenseId($number, $space_type_id = 0)
{
$license_id = ParkingLicensePlate::getValueId($number);
if (!$license_id) {
if (!$space_type_id) {
$space_type = ParkingSpaceType::getDefaultData();
$space_type_id = $space_type['id'] ?? 0;
}
$licenseModel = $this->createData([
'number' => $number,
'space_type_id' => $space_type_id
]);
$license_id = $licenseModel->id;
}
return $license_id;
}
}

15
app/Services/ParkingVipListService.php

@ -2,6 +2,8 @@
namespace App\Services;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingSpaceType;
use App\Models\ParkingVipList;
use Exception;
use Illuminate\Database\Eloquent\Builder;
@ -37,7 +39,10 @@ class ParkingVipListService
try {
DB::beginTransaction();
if (ParkingVipList::query()->where('license', $data['license'])
$ParkingLicensePlateService = new ParkingLicensePlateService($this->logService);
$license_id = $ParkingLicensePlateService->createLicenseId($data['license']);
if (ParkingVipList::query()->where('license_id', $license_id)
->exists()
) {
throw new Exception(
@ -46,7 +51,7 @@ class ParkingVipListService
}
$model = ParkingVipList::query()->create([
'license' => $data['license'],
'license_id' => $license_id,
'user_id' => Auth::guard('sanctum')->user()['id'],
'created_at' => get_datetime()
]);
@ -73,9 +78,13 @@ class ParkingVipListService
try {
DB::beginTransaction();
$license = $data['license'];
$ParkingLicensePlateService = new ParkingLicensePlateService($this->logService);
$license_id = $ParkingLicensePlateService->createLicenseId($license);
// 验证
$existsWhere = [
['license', '=', $data['license']],
['license_id', '=', $license_id],
['id', '<>', $id]
];
if (ParkingVipList::query()->where($existsWhere)->exists()) {

2
database/migrations/2026_03_02_110943_create_parking_vip_list_table.php

@ -13,7 +13,7 @@ return new class extends Migration
{
Schema::create('parking_vip_list', function (Blueprint $table) {
$table->id();
$table->string('license', 20)->comment('车牌号码');
$table->integer('license_id')->comment('车牌号码id');
$table->integer('user_id')->comment('管理员id');
$table->timestamps();
$table->softDeletes();

4
database/migrations/2026_03_04_160517_create_parking_vip_access_record_table.php

@ -13,8 +13,8 @@ return new class extends Migration
{
Schema::create('parking_vip_access_record', function (Blueprint $table) {
$table->id();
$table->integer('parking_space_id')->index('parking_space_id')->comment('车位类型');
$table->integer('parking_number_id')->comment('车位编号');
$table->integer('space_id')->index('space_id')->comment('车位编号');
$table->integer('space_type_id')->comment('车位类型');
$table->integer('vip_list_id')->index('vip_list_id')->comment('vip名单编号');
$table->dateTime('enter_time')->comment('进入时间');
$table->dateTime('leave_time')->comment('离开时间');

3
resources/lang/en/service.php

@ -6,7 +6,8 @@ return [
'menu_error' => 'The role number parameter is incorrect'
],
'admin_user' => [
'name_exists' => 'The user account already exists'
'name_exists' => 'The user account already exists',
'not_del' => 'Super management account cannot be deleted'
],
'admin_translation' => [
'data_exists' => 'Translation configuration already exists'

3
resources/lang/zh-CN/service.php

@ -6,7 +6,8 @@ return [
'menu_error' => '角色编号参数有误'
],
'admin_user' => [
'name_exists' => '用户账号已存在'
'name_exists' => '用户账号已存在',
'not_del' => '超管账号不可删除'
],
'admin_translation' => [
'data_exists' => '翻译配置已存在'

3
resources/lang/zh-TW/service.php

@ -6,7 +6,8 @@ return [
'menu_error' => '角色編號參數有誤'
],
'admin_user' => [
'name_exists' => '用戶帳號已存在'
'name_exists' => '用戶帳號已存在',
'not_del' => '超管帳號不可删除'
],
'admin_translation' => [
'data_exists' => '翻譯配寘已存在'

Loading…
Cancel
Save