116 lines
4.3 KiB
PHP
116 lines
4.3 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Http\Controllers\Controller;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
class InformationController extends Controller
|
||
{
|
||
public function list(Request $request)
|
||
{
|
||
// パラメータ
|
||
$period = $request->input('period', 'month'); // month | all
|
||
$type = $request->input('type', 'all'); // task(<99) | hard(>99) | all
|
||
$status = $request->input('status', 'untreated'); // untreated(=1) | inprogress(=2) | done(=3) | all
|
||
|
||
$q = DB::table('operator_que as oq')
|
||
->leftJoin('user as u', 'oq.user_id', '=', 'u.user_id')
|
||
->leftJoin('park as p', 'oq.park_id', '=', 'p.park_id')
|
||
// オペレータマスタ(テーブル・カラム名は環境に合わせて調整)
|
||
->leftJoin('ope as o', 'oq.operator_id', '=', 'o.ope_id')
|
||
->select(
|
||
'oq.que_id','oq.que_class','oq.user_id',
|
||
DB::raw('u.user_name as user_name'),
|
||
'oq.contract_id','oq.park_id',
|
||
DB::raw('p.park_name as park_name'),
|
||
'oq.que_comment','oq.que_status','oq.que_status_comment',
|
||
'oq.work_instructions','oq.created_at','oq.updated_at','oq.operator_id',
|
||
DB::raw('o.ope_name as operator_name')
|
||
);
|
||
|
||
// 期間: 登録日ベース(最新1ヵ月 or 全期間)
|
||
if ($period === 'month') {
|
||
$q->where('oq.created_at', '>=', now()->subMonth());
|
||
}
|
||
|
||
// 種別: que_class
|
||
if ($type === 'task') {
|
||
$q->where('oq.que_class', '<', 99);
|
||
} elseif ($type === 'hard') {
|
||
$q->where('oq.que_class', '>', 99);
|
||
} // all は絞り込みなし
|
||
|
||
// ステータス: que_status
|
||
if ($status === 'untreated') {
|
||
$q->where('oq.que_status', 1);
|
||
} elseif ($status === 'inprogress') {
|
||
$q->where('oq.que_status', 2);
|
||
} elseif ($status === 'done') {
|
||
$q->where('oq.que_status', 3);
|
||
} // all は絞り込みなし
|
||
|
||
$jobs = $q->orderBy('oq.que_id')->paginate(20)->appends($request->query());
|
||
|
||
return view('admin.information.list', compact('jobs','period','type','status'));
|
||
}
|
||
|
||
// ダッシュボード表示
|
||
public function dashboard(Request $request)
|
||
{
|
||
// ダッシュボード統計情報を集計
|
||
|
||
// 駐輪場の総収容台数
|
||
$totalCapacity = DB::table('park')
|
||
->sum('park_capacity') ?? 0;
|
||
|
||
// 予約待ち人数(regular_contractで状態チェック)
|
||
$totalWaiting = DB::table('regular_contract')
|
||
->whereIn('rc_status', [1]) // 待機中など
|
||
->count();
|
||
|
||
// 利用率計算(使用中台数 / 総容量)
|
||
$utilizationRate = $totalCapacity > 0
|
||
? round((DB::table('park')
|
||
->where('park_status', 1)
|
||
->sum('park_capacity') ?? 0) / $totalCapacity * 100)
|
||
: 0;
|
||
|
||
$totalStats = [
|
||
'total_cities' => DB::table('city')->count(),
|
||
'total_parks' => DB::table('park')->count(),
|
||
'total_contracts' => DB::table('regular_contract')->count(),
|
||
'total_users' => DB::table('user')->count(),
|
||
'total_devices' => DB::table('device')->count(),
|
||
'today_queues' => DB::table('operator_que')
|
||
->whereDate('created_at', today())
|
||
->count(),
|
||
'total_waiting' => $totalWaiting,
|
||
'total_capacity' => $totalCapacity,
|
||
'total_utilization_rate' => $utilizationRate,
|
||
];
|
||
|
||
return view('admin.information.dashboard', compact('totalStats'));
|
||
}
|
||
|
||
// ステータス一括更新(着手=2 / 対応完了=3)
|
||
public function updateStatus(Request $request)
|
||
{
|
||
$request->validate([
|
||
'ids' => 'required|array',
|
||
'action' => 'required|in:inprogress,done',
|
||
]);
|
||
|
||
$new = $request->action === 'inprogress' ? 2 : 3;
|
||
|
||
DB::table('operator_que')
|
||
->whereIn('que_id', $request->ids)
|
||
->update([
|
||
'que_status' => $new,
|
||
'updated_at' => now(),
|
||
]);
|
||
|
||
return back()->with('success', '選択したキューのステータスを更新しました。');
|
||
}
|
||
} |