3 changed files with 163 additions and 0 deletions
@ -0,0 +1,113 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
use App\Models\AdminVipAccessRecord; |
|||
use App\Models\AdminVipList; |
|||
use App\Services\ApiResponseService; |
|||
use Exception; |
|||
use Illuminate\Http\JsonResponse; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class VipAccessRecordController extends Controller |
|||
{ |
|||
|
|||
/** |
|||
* @var ApiResponseService |
|||
*/ |
|||
protected ApiResponseService $responseService; |
|||
|
|||
/** |
|||
* @param ApiResponseService $responseService |
|||
*/ |
|||
public function __construct( |
|||
ApiResponseService $responseService |
|||
) { |
|||
$this->responseService = $responseService; |
|||
} |
|||
|
|||
public function index(Request $request): JsonResponse |
|||
{ |
|||
try { |
|||
$query = AdminVipAccessRecord::query(); |
|||
|
|||
if ($request->has('space')) { |
|||
$space = $request->input('space'); |
|||
$query->where('parking_space_id', 'like', "%{$space}%"); |
|||
} |
|||
|
|||
if ($request->has('space_number')) { |
|||
// $space_number = $request->input('space_number'); |
|||
} |
|||
|
|||
if ($request->has('license')) { |
|||
$license = $request->input('license'); |
|||
$vipIds = AdminVipList::query()->where( |
|||
'license', |
|||
'like', |
|||
"%{$license}%" |
|||
)->pluck('id'); |
|||
if ($vipIds) { |
|||
$query->whereIn('vip_list_id', $vipIds); |
|||
} else { |
|||
$query->where('id', 0); |
|||
} |
|||
} |
|||
|
|||
if ($request->has('enter_start_time') |
|||
&& $request->has( |
|||
'enter_end_time' |
|||
) |
|||
) { |
|||
$enter_start_time = $request->input('enter_start_time'); |
|||
$enter_end_time = $request->input('enter_end_time'); |
|||
$query->whereBetween( |
|||
'enter_time', |
|||
[$enter_start_time, $enter_end_time] |
|||
); |
|||
} |
|||
|
|||
if ($request->has('leave_start_time') |
|||
&& $request->has( |
|||
'leave_end_time' |
|||
) |
|||
) { |
|||
$leave_start_time = $request->input('leave_start_time'); |
|||
$leave_end_time = $request->input('leave_end_time'); |
|||
$query->whereBetween( |
|||
'enter_time', |
|||
[$leave_start_time, $leave_end_time] |
|||
); |
|||
} |
|||
|
|||
// 分页 |
|||
$page = $request->input('page', 1); |
|||
$perPage = $request->input('per_page', 10); |
|||
|
|||
$total = $query->count(); |
|||
$items = $query->latest()->forPage($page, $perPage)->get()->each( |
|||
function ($item) { |
|||
$item['license_number'] = AdminVipList::query()->where( |
|||
'id', |
|||
$item['vip_list_id'] |
|||
)->value('license'); |
|||
return $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.get_user_info_list_failed'); |
|||
return $this->responseService->systemError( |
|||
$m_prefix . ':' . $e->getMessage() |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class AdminVipAccessRecord extends Model |
|||
{ |
|||
use HasFactory; |
|||
|
|||
protected $table = 'admin_vip_access_record'; |
|||
|
|||
protected $hidden = [ |
|||
'created_at', |
|||
'updated_at' |
|||
]; |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<?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('admin_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('vip_list_id')->index('vip_list_id')->comment('vip名单编号'); |
|||
$table->dateTime('enter_time')->comment('进入时间'); |
|||
$table->dateTime('leave_time')->comment('离开时间'); |
|||
$table->timestamps(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('admin_vip_access_record'); |
|||
} |
|||
}; |
|||
Loading…
Reference in new issue