14 changed files with 385 additions and 3 deletions
@ -0,0 +1,62 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Exports; |
||||
|
|
||||
|
use App\Services\OperationLogService; |
||||
|
use App\Services\ParkingManualCorrectionService; |
||||
|
use Maatwebsite\Excel\Concerns\FromArray; |
||||
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
||||
|
|
||||
|
class ParkingManualCorrectionExport implements FromArray, WithHeadings |
||||
|
{ |
||||
|
|
||||
|
public array $parents = []; |
||||
|
public ParkingManualCorrectionService $service; |
||||
|
|
||||
|
public function __construct($parents) |
||||
|
{ |
||||
|
$this->parents = $parents; |
||||
|
$this->service = new ParkingManualCorrectionService( |
||||
|
new OperationLogService() |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public function array(): array |
||||
|
{ |
||||
|
$data = []; |
||||
|
$index = 1; |
||||
|
$query = $this->service->indexQuery($this->parents); |
||||
|
$query->select()->get()->each( |
||||
|
function ($item) use (&$data, &$index) { |
||||
|
$oldItem = $this->service->getItem($item); |
||||
|
$data[] = [ |
||||
|
'id' => $index, |
||||
|
'enter_time' => $oldItem['enter_time'], |
||||
|
'space_number' => $oldItem['space_number'], |
||||
|
'old_license_place' => $oldItem['old_license_place'], |
||||
|
'updated_at' => $oldItem['update_time'], |
||||
|
'username' => $oldItem['username'], |
||||
|
'new_license_place' => $oldItem['new_license_place'] |
||||
|
]; |
||||
|
$index += 1; |
||||
|
} |
||||
|
); |
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function headings(): array |
||||
|
{ |
||||
|
return [ |
||||
|
__('exports.global.index'), |
||||
|
__('exports.parking_space.enter_time'), |
||||
|
__('exports.parking_space.space_number'), |
||||
|
__('exports.parking_space.old_license_place'), |
||||
|
__('exports.parking_space.updated_at'), |
||||
|
__('exports.parking_space.username'), |
||||
|
__('exports.parking_space.new_license_place') |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Admin; |
||||
|
|
||||
|
use App\Exports\ParkingManualCorrectionExport; |
||||
|
use App\Services\ApiResponseService; |
||||
|
use App\Services\ParkingManualCorrectionService; |
||||
|
use Exception; |
||||
|
use Illuminate\Http\JsonResponse; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Maatwebsite\Excel\Facades\Excel; |
||||
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
||||
|
|
||||
|
class ParkingManualCorrectionController extends BaseController |
||||
|
{ |
||||
|
|
||||
|
protected string $menuUri = 'manualCorrection'; |
||||
|
|
||||
|
protected ParkingManualCorrectionService $service; |
||||
|
|
||||
|
/** |
||||
|
* 构造函数 |
||||
|
* @param ApiResponseService $responseService |
||||
|
* @param ParkingManualCorrectionService $service |
||||
|
*/ |
||||
|
public function __construct( |
||||
|
ApiResponseService $responseService, |
||||
|
ParkingManualCorrectionService $service |
||||
|
) { |
||||
|
parent::__construct($responseService); |
||||
|
$this->service = $service; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Display a listing of the resource. |
||||
|
*/ |
||||
|
public function index(Request $request): JsonResponse |
||||
|
{ |
||||
|
try { |
||||
|
$query = $this->service->indexQuery($request->all()); |
||||
|
|
||||
|
// 分页 |
||||
|
$page = $request->input('page', 1); |
||||
|
$perPage = $request->input('per_page', 10); |
||||
|
$total = $query->count(); |
||||
|
$_this = $this; |
||||
|
$items = $query->latest()->forPage($page, $perPage)->get()->each( |
||||
|
function ($item) use ($_this) { |
||||
|
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() |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Request $request |
||||
|
* @return BinaryFileResponse |
||||
|
*/ |
||||
|
public function export(Request $request): BinaryFileResponse |
||||
|
{ |
||||
|
return Excel::download( |
||||
|
new ParkingManualCorrectionExport($request->all()), |
||||
|
set_space_underline(__('exports.manual_correction.list')) |
||||
|
. get_datetime('date_') |
||||
|
. '.xlsx' |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class ParkingManualCorrection extends Model |
||||
|
{ |
||||
|
use HasFactory; |
||||
|
|
||||
|
protected $table = 'parking_manual_correction'; |
||||
|
|
||||
|
protected $fillable = [ |
||||
|
'enter_time', |
||||
|
'space_id', |
||||
|
'old_license_id', |
||||
|
'admin_user_id', |
||||
|
'new_license_id' |
||||
|
]; |
||||
|
|
||||
|
protected $hidden = [ |
||||
|
'updated_at' |
||||
|
]; |
||||
|
|
||||
|
public function getEnterTimeAttribute($value): string |
||||
|
{ |
||||
|
return $value ? date("Y-m-d H:i:s", strtotime($value)) : $value; |
||||
|
} |
||||
|
|
||||
|
public function getCreatedAtAttribute($value): string |
||||
|
{ |
||||
|
return $value ? date("Y-m-d H:i:s", strtotime($value)) : $value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,121 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Services; |
||||
|
|
||||
|
use App\Models\AdminUsers; |
||||
|
use App\Models\ParkingLicensePlate; |
||||
|
use App\Models\ParkingManualCorrection; |
||||
|
use App\Models\ParkingSpace; |
||||
|
|
||||
|
class ParkingManualCorrectionService extends BaseService |
||||
|
{ |
||||
|
protected string $menuTitle = 'manual_correction'; |
||||
|
|
||||
|
public function createData($data, $user_id) |
||||
|
{ |
||||
|
$data = [ |
||||
|
'enter_time' => $data['enter_time'], |
||||
|
'space_id' => $data['space_id'], |
||||
|
'old_license_id' => $data['old_license_id'], |
||||
|
'admin_user_id' => $user_id, |
||||
|
'new_license_id' => $data['new_license_id'], |
||||
|
'created_at' => date("Y-m-d H:i:s", time()) |
||||
|
]; |
||||
|
$model = ParkingManualCorrection::query()->create($data); |
||||
|
$this->logService->logCreated($model, $this->menuTitle . '.create'); |
||||
|
$data = $model->toArray(); |
||||
|
return $data['id'] ?? 0; |
||||
|
} |
||||
|
|
||||
|
public function indexQuery($param) |
||||
|
{ |
||||
|
$query = ParkingManualCorrection::query(); |
||||
|
|
||||
|
if (isset($param['space_number']) && !empty($param['space_number'])) { |
||||
|
$space_ids = ParkingSpace::getId($param['space_number']); |
||||
|
if ($space_ids) { |
||||
|
$query->whereIn('space_id', $space_ids); |
||||
|
} else { |
||||
|
$query->where('id', 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (isset($param['old_license_place']) |
||||
|
&& !empty($param['old_license_place']) |
||||
|
) { |
||||
|
$old_id_arr = ParkingLicensePlate::getId( |
||||
|
$param['old_license_place'] |
||||
|
); |
||||
|
$old_id_arr ? $query->whereIn( |
||||
|
'old_license_id', |
||||
|
$old_id_arr |
||||
|
) : $query->where('id', 0); |
||||
|
} |
||||
|
|
||||
|
if (isset($param['start_date']) |
||||
|
&& !empty($param['start_date']) |
||||
|
&& strtotime($param['start_date']) |
||||
|
) { |
||||
|
$start_date = date( |
||||
|
"Y-m-d 00:00:00", |
||||
|
strtotime($param['start_date']) |
||||
|
); |
||||
|
if ($start_date) { |
||||
|
$query->where('created_at', '>=', $start_date); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (isset($param['end_date']) |
||||
|
&& !empty($param['end_date']) |
||||
|
&& strtotime($param['end_date']) |
||||
|
) { |
||||
|
$end_date = date( |
||||
|
"Y-m-d 00:00:00", |
||||
|
strtotime($param['end_date']) |
||||
|
); |
||||
|
if ($end_date) { |
||||
|
$query->where('created_at', '<', $end_date); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (isset($param['username']) && !empty($param['username'])) { |
||||
|
$ids = AdminUsers::getIds($param['username']); |
||||
|
if ($ids) { |
||||
|
$query->whereIn('admin_user_id', $ids); |
||||
|
} else { |
||||
|
$query->where('id', 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (isset($param['new_license_place']) |
||||
|
&& !empty($param['new_license_place']) |
||||
|
) { |
||||
|
$new_id_arr = ParkingLicensePlate::getId( |
||||
|
$param['new_license_place'] |
||||
|
); |
||||
|
$new_id_arr ? $query->whereIn( |
||||
|
'new_license_id', |
||||
|
$new_id_arr |
||||
|
) : $query->where('id', 0); |
||||
|
} |
||||
|
|
||||
|
$query->orderBy('id', 'desc'); |
||||
|
|
||||
|
return $query; |
||||
|
} |
||||
|
|
||||
|
public function getItem($item) |
||||
|
{ |
||||
|
$item['space_number'] = ParkingSpace::getNumber($item['space_id']); |
||||
|
$item['old_license_place'] = ParkingLicensePlate::getNumber( |
||||
|
$item['old_license_id'] |
||||
|
); |
||||
|
$item['new_license_place'] = ParkingLicensePlate::getNumber( |
||||
|
$item['new_license_id'] |
||||
|
); |
||||
|
$item['username'] = AdminUsers::getUsername($item['admin_user_id']); |
||||
|
$item['update_time'] = $item['created_at']; |
||||
|
unset($item['space_id'], $item['old_license_id'], $item['new_license_id'], $item['admin_user_id'], $item['created_at']); |
||||
|
return $item; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?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_manual_correction', function (Blueprint $table) { |
||||
|
$table->id(); |
||||
|
$table->dateTime('enter_time')->comment('进入车位时间'); |
||||
|
$table->integer('space_id')->comment('车位id'); |
||||
|
$table->integer('old_license_id')->comment('原本车牌号码'); |
||||
|
$table->integer('admin_user_id')->comment('操作员'); |
||||
|
$table->integer('new_license_id')->comment('现时车牌号码'); |
||||
|
$table->index('space_id', 'space_id'); |
||||
|
$table->comment('车位车牌修正记录'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Reverse the migrations. |
||||
|
*/ |
||||
|
public function down(): void |
||||
|
{ |
||||
|
Schema::dropIfExists('parking_manual_correction'); |
||||
|
} |
||||
|
}; |
||||
Loading…
Reference in new issue