78 lines
2.9 KiB
PHP
78 lines
2.9 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'));
|
||
}
|
||
|
||
// ステータス一括更新(着手=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', '選択したキューのステータスを更新しました。');
|
||
}
|
||
} |