Browse Source

停车行为管理

master
wanghongjun 1 month ago
parent
commit
e15a476f7b
  1. 144
      app/Http/Controllers/Admin/ParkingBehaviorController.php
  2. 40
      app/Models/ParkingAccessRecord.php
  3. 35
      database/migrations/2026_04_23_143449_create_parking_access_record_table.php
  4. 7
      resources/lang/en/exports.php
  5. 7
      resources/lang/zh-CN/exports.php
  6. 7
      resources/lang/zh-TW/exports.php
  7. 4
      routes/admin/api.php

144
app/Http/Controllers/Admin/ParkingBehaviorController.php

@ -0,0 +1,144 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Exports\ParkingBehaviorExport;
use App\Models\ParkingAccessRecord;
use App\Models\ParkingInformation;
use App\Models\ParkingLicensePlate;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ParkingBehaviorController extends BaseController
{
public function index(Request $request): JsonResponse
{
try {
$select = " SELECT DATE_FORMAT(FROM_UNIXTIME(enter_time), "
. "'%Y-%m-%d') AS time_period, `license_plate_id`, "
. "COUNT(license_plate_id) AS parking_frequency, SUM(COALESCE("
. "leave_time, UNIX_TIMESTAMP()) - enter_time) AS parking_duration";
$from = " FROM `parking_access_record` ";
$group = " GROUP BY DATE_FORMAT(FROM_UNIXTIME(enter_time),"
. " '%Y-%m-%d'), `license_plate_id`";
$whereArr = [];
if ($request->has('start_time') && $request->has('end_time')) {
$start_time = $request->input('start_time');
$end_time = $request->input('end_time');
if ($start_time && $end_time) {
$end_times = strtotime($end_time . ' 23:59:59');
$start_times = strtotime($start_time . ' 00:00:00');
if ($start_times && $end_times) {
$whereArr[]
= " enter_time BETWEEN {$start_times} and {$end_times}";
}
}
}
if ($request->has('license_plate')) {
$license_plate = $request->input('license_plate');
if ($license_plate) {
$license_plate_id = ParkingLicensePlate::getValueId(
$license_plate
);
if ($license_plate_id) {
$whereArr[] = " license_plate_id = {$license_plate_id}";
} else {
$whereArr[] = " id = 0";
}
}
}
$where = $whereArr ? ' WHERE ' . implode(' AND ', $whereArr) : '';
// 分页
$page = $request->input('page', 1);
$perPage = $request->input('per_page', 10);
$havingArr = [];
if ($request->has('min_count') && $request->has('max_count')) {
$min_count = $request->input('min_count');
$max_count = $request->input('max_count');
if (is_numeric($min_count) && is_numeric($max_count)) {
$havingArr[]
= "(parking_frequency >= {$min_count} AND parking_frequency <= {$max_count})";
}
}
if ($request->has('min_times') && $request->has('max_times')) {
$min_times = $request->input('min_times');
$max_times = $request->input('max_times');
if (is_numeric($min_times) && is_numeric($max_times)) {
$havingArr[]
= "(parking_duration >= {$min_times} AND parking_duration <= {$max_times})";
}
}
$having = $havingArr ? " HAVING " . implode(' AND ', $havingArr)
: '';
$total = 0;
$all = DB::select($select . $from . $where . $group . $having);
if ($all) {
$total = count($all);
}
$offset = ($page - 1) * $perPage;
$limit = " LIMIT {$offset}, {$perPage}";
$items = DB::select(
$select . $from . $where . $group . $having . $limit
);
foreach ($items as &$item) {
$license_plate = ParkingLicensePlate::getNumber(
$item->license_plate_id
);
$item->license_plate = $license_plate;
unset($item->license_plate_id);
}
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 BinaryFileResponse
*/
public function export(): BinaryFileResponse
{
return Excel::download(
new ParkingBehaviorExport(),
__('exports.parking_behavior.list') . time() . '.xlsx'
);
}
}
/*
网站开发
帮我开发一个后台管理系统,使用后端语言PHP版本大于8.0,前端语言使用vue3,实现前后端分离,用于管理【管理内容】。
登录要求:包含登录页,
页面要求:1.登录后页面左边展示菜单,右边显示内容,默认展示首页内容,首页显示今日营业数据总览
2.第1个菜单酒水菜品菜单管理,其中包含二级菜单:分类管理、商品列表。分类管理增删改查菜品分类如大类目增加啤酒、洋酒、小吃,商品列表内容有:新增商品(商品名字、数量、价格、类型)、列表筛选(上架、下架、商品名称搜索、类型选择)、列表(显示商品列表、名称、价格、上架时间、状态等)
3.第2个菜单会员管理页面,其中包含二级菜单:会员信息、会员等级管理、充值配置、充值记录、消费记录
4.财务管理,其中包含二级菜单:数据概览(今日营收、本月总营收、营收趋势(每日k线)、收入明细(显示最新支付数据:项目、支付时间、金额、支付方式))、营业明细(列表展示今日销售酒水,支付方式、支付时间等)
5.人员管理,新增工作人员(新增或删除操作人员,设置不同的权限、不同岗位的工作人员,可修改员工里面不可查看)、操作记录(记录操作人员新增、删除、修改员工密码的操作记录)、员工销售管理(统计员工销售酒水业绩)
*/

40
app/Models/ParkingAccessRecord.php

@ -0,0 +1,40 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ParkingAccessRecord extends Model
{
use HasFactory;
protected $table = 'parking_access_record';
protected $fillable
= [
'floor_id',
'license_plate_id',
'space_id',
'status',
'enter_time',
'leave_time'
];
protected $hidden = [
'created_at',
'updated_at'
];
public function getEnterTimeAttribute($value): string
{
return get_datetime('datetime', strtotime($value));
}
public function getLeaveTimeAttribute($value): string
{
return $value ? get_datetime('datetime', strtotime($value)) : '';
}
}

35
database/migrations/2026_04_23_143449_create_parking_access_record_table.php

@ -0,0 +1,35 @@
<?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_access_record', function (Blueprint $table) {
$table->id();
$table->integer('floor_id')->comment('楼层id');
$table->integer('license_plate_id')->comment('车牌id');
$table->integer('space_id')->comment('车位id');
$table->tinyInteger('status')->default(1)->comment('状态 0离 1进');
$table->integer('enter_time')->comment('进入时间');
$table->integer('leave_time')->comment('离开时间');
$table->innoDb();
$table->index('space_id');
$table->comment('停车进出记录');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('parking_access_record');
}
};

7
resources/lang/en/exports.php

@ -66,5 +66,12 @@ return [
'license_plate' => 'license plate number',
'camera_ip' => 'IP',
'msg_content' => 'Information Content Details'
],
'parking_behavior' => [
'list' => 'Parking behavior',
'time_period' => 'time period',
'license_plate' => 'license plate number',
'parking_frequency' => 'parking frequency',
'parking_duration' => 'Parking duration(min)'
]
];

7
resources/lang/zh-CN/exports.php

@ -66,5 +66,12 @@ return [
'license_plate' => '车牌号码',
'camera_ip' => 'IP',
'msg_content' => '信息内容详情'
],
'parking_behavior' => [
'list' => '停车行为',
'time_period' => '时间段',
'license_plate' => '车牌号码',
'parking_frequency' => '停车次数',
'parking_duration' => '停车时长(min)'
]
];

7
resources/lang/zh-TW/exports.php

@ -66,5 +66,12 @@ return [
'license_plate' => '車牌號碼',
'camera_ip' => 'IP',
'msg_content' => '資訊內容詳情'
],
'parking_behavior' => [
'list' => '停車行為',
'time_period' => '時間段',
'license_plate' => '車牌號碼',
'parking_frequency' => '停車次數',
'parking_duration' => '停車時長(min)'
]
];

4
routes/admin/api.php

@ -26,6 +26,7 @@ use App\Http\Controllers\Admin\ParkingPatternSpaceController;
use App\Http\Controllers\Admin\EventCalendarController;
use App\Http\Controllers\Admin\NoticeController;
use App\Http\Controllers\Admin\LicensePlateRecognitionController;
use App\Http\Controllers\Admin\ParkingBehaviorController;
Route::group(['prefix' => 'admin'], function () {
@ -149,6 +150,8 @@ Route::group(['prefix' => 'admin'], function () {
// 车牌识别率
Route::get('/licensePlateRecognition', [LicensePlateRecognitionController::class, 'index']);
Route::get('/licensePlateRecognition/curveGraph', [LicensePlateRecognitionController::class, 'curveGraph']);
// 停车行为
Route::get('/behavior', [ParkingBehaviorController::class, 'index']);
// 系统日志
Route::get('/operationLog/index', [OperationLogController::class, 'index']);
@ -214,4 +217,5 @@ Route::group(['prefix' => 'admin'], function () {
Route::get('/operationLog/export', [OperationLogController::class, 'export']);
Route::get('/eventCalendar/export', [EventCalendarController::class, 'importTemplate']);
Route::get('/notice/export', [NoticeController::class, 'export']);
Route::get('/behavior/export', [ParkingBehaviorController::class, 'export']);
});

Loading…
Cancel
Save