148 lines
4.0 KiB
PHP
148 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Payment;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class PaymentController extends Controller
|
|
{
|
|
/**
|
|
* 決済情報マスタ一覧表示
|
|
*/
|
|
public function list(Request $request)
|
|
{
|
|
$sort = $request->input('sort', 'payment_id');
|
|
$sort_type = $request->input('sort_type', 'asc');
|
|
|
|
$query = Payment::query();
|
|
|
|
$query->orderBy($sort, $sort_type);
|
|
|
|
$payments = $query->paginate(20);
|
|
|
|
return view('admin.payments.list', compact('payments', 'sort', 'sort_type'));
|
|
}
|
|
|
|
/**
|
|
* 新規登録画面表示&登録処理
|
|
*/
|
|
public function add(Request $request)
|
|
{
|
|
if ($request->isMethod('post')) {
|
|
// バリデーション
|
|
$request->validate([
|
|
'payment_companyname' => 'required|string|max:255',
|
|
'payment_add' => 'nullable|string|max:255',
|
|
'payment_detail' => 'nullable|string|max:255',
|
|
'payment_space1' => 'nullable|string|max:255',
|
|
'payment_space2' => 'nullable|string|max:255',
|
|
'payment_title' => 'nullable|string|max:255',
|
|
'payment_guide' => 'nullable|string|max:255',
|
|
'payment_inquiryname' => 'nullable|string|max:255',
|
|
'payment_inquirytel' => 'nullable|string|max:255',
|
|
'payment_time' => 'nullable|string|max:255',
|
|
|
|
]);
|
|
|
|
// 登録データ作成
|
|
$data = $request->all();
|
|
$data['operator_id'] = Auth::user()->ope_id;
|
|
|
|
Payment::create($data);
|
|
|
|
return redirect()->route('payments')->with('success', '登録しました。');
|
|
}
|
|
|
|
return view('admin.payments.add', [
|
|
'record' => null,
|
|
'mode' => 'add'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 編集画面表示&更新処理
|
|
*/
|
|
public function edit(Request $request, $payment_id)
|
|
{
|
|
$payment = Payment::findOrFail($payment_id);
|
|
|
|
if ($request->isMethod('post')) {
|
|
// バリデーション
|
|
$request->validate([
|
|
'payment_companyname' => 'required|string|max:255',
|
|
// 其他字段...
|
|
]);
|
|
|
|
$data = $request->all();
|
|
$data['operator_id'] = Auth::user()->ope_id;
|
|
|
|
$payment->update($data);
|
|
|
|
return redirect()->route('payments')->with('success', '更新しました。');
|
|
}
|
|
|
|
return view('admin.payments.edit', [
|
|
'payment' => $payment,
|
|
'isEdit' => true,
|
|
'isInfo' => false
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 詳細画面表示
|
|
*/
|
|
public function info($payment_id)
|
|
{
|
|
$payment = Payment::findOrFail($payment_id);
|
|
|
|
return view('admin.payments.info', [
|
|
'record' => $payment,
|
|
'mode' => 'info'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 削除処理
|
|
*/
|
|
public function delete(Request $request)
|
|
{
|
|
$pk = $request->input('pk', []);
|
|
|
|
// 配列に統一
|
|
$ids = is_array($pk) ? $pk : [$pk];
|
|
|
|
// 数字チェック
|
|
$ids = array_values(array_filter($ids, fn($v) => preg_match('/^\d+$/', (string) $v)));
|
|
|
|
if (empty($ids)) {
|
|
return redirect()->route('payments')->with('error', '削除対象が選択されていません。');
|
|
}
|
|
|
|
// 削除
|
|
Payment::whereIn('payment_id', $ids)->delete();
|
|
|
|
return redirect()->route('payments')->with('success', '削除しました。');
|
|
}
|
|
|
|
/**
|
|
* インポート処理
|
|
*/
|
|
public function import(Request $request)
|
|
{
|
|
// TODO: CSVなどのインポート処理を実装
|
|
return redirect()->route('payments')->with('success', 'インポート処理は未実装です');
|
|
}
|
|
|
|
/**
|
|
* エクスポート処理
|
|
*/
|
|
public function export()
|
|
{
|
|
// TODO: エクスポート処理を実装
|
|
return redirect()->route('payments')->with('success', 'エクスポート処理は未実装です');
|
|
}
|
|
}
|