指摘対応エラー修正
This commit is contained in:
parent
00a15f6a35
commit
c1973b96c0
@ -14,7 +14,8 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Response;
|
||||
// use Response;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class PriceController extends Controller
|
||||
{
|
||||
@ -136,74 +137,64 @@ class PriceController extends Controller
|
||||
return self::whereIn('price_parkplaceid', $ids)->delete();
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
public function exportGet(Request $request)
|
||||
{
|
||||
$headers = [
|
||||
"Content-type" => "text/csv;charset=UTF-8",
|
||||
'Content-Encoding: UTF-8',
|
||||
"Content-Disposition" => "attachment; filename=file.csv",
|
||||
"Pragma" => "no-cache",
|
||||
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
|
||||
"Expires" => "0"
|
||||
"Content-Type" => "text/csv; charset=UTF-8",
|
||||
"Content-Disposition" => "attachment; filename=駐輪場所、料金マスタ.csv",
|
||||
];
|
||||
|
||||
$query = Price::query();
|
||||
|
||||
// 🚩 条件付きエクスポート(park_id)
|
||||
// 🔹 パラメータ取得(GETでもOK)
|
||||
if ($request->filled('park_id')) {
|
||||
$query->where('park_id', $request->input('park_id'));
|
||||
}
|
||||
|
||||
// ソート
|
||||
if ($request->filled('sort')) {
|
||||
$query->orderBy($request->input('sort'), $request->input('sort_type', 'asc'));
|
||||
}
|
||||
|
||||
$dataExport = $query->get();
|
||||
|
||||
// 🔹 CSV列定義
|
||||
$columns = [
|
||||
__('駐車場所ID'),
|
||||
__('商品名'),
|
||||
__('期間'),
|
||||
__('駐輪場ID'),
|
||||
__('駐輪場名'),
|
||||
__('車種区分ID'),
|
||||
__('車種区分'),
|
||||
__('駐輪分類ID'),
|
||||
__('駐輪分類'),
|
||||
__('利用者分類ID'),
|
||||
__('利用者分類'),
|
||||
__('駐車車室ID'),
|
||||
__('駐輪料金(税込)'),
|
||||
'駐車場所ID', '商品名', '期間', '駐輪場ID', '駐輪場名',
|
||||
'車種区分ID', '車種区分', '駐輪分類ID', '駐輪分類',
|
||||
'利用者分類ID', '利用者分類', '駐車車室ID', '駐輪料金(税込)',
|
||||
];
|
||||
|
||||
$filename = "駐輪場所、料金マスタ.csv";
|
||||
$file = fopen($filename, 'w+');
|
||||
// 🔹 CSV生成
|
||||
$filename = '駐輪場所、料金マスタ.csv';
|
||||
$path = storage_path('app/' . $filename);
|
||||
$file = fopen($path, 'w+');
|
||||
fwrite($file, "\xEF\xBB\xBF"); // Excel対応のBOM
|
||||
fputcsv($file, $columns);
|
||||
|
||||
foreach ($dataExport as $items) {
|
||||
foreach ($dataExport as $item) {
|
||||
fputcsv($file, [
|
||||
$items->price_parkplaceid,
|
||||
$items->prine_name,
|
||||
$items->price_month,
|
||||
$items->park_id,
|
||||
optional($items->getPark())->park_name,
|
||||
$items->psection_id,
|
||||
optional($items->getPSection())->psection_subject,
|
||||
$items->price_ptypeid,
|
||||
optional($items->getPType())->ptype_subject,
|
||||
$items->user_categoryid,
|
||||
optional($items->getUserType())->print_name,
|
||||
$items->pplace_id,
|
||||
$items->price,
|
||||
$item->price_parkplaceid,
|
||||
$item->prine_name,
|
||||
$item->price_month,
|
||||
$item->park_id,
|
||||
optional($item->getPark())->park_name,
|
||||
$item->psection_id,
|
||||
optional($item->getPSection())->psection_subject,
|
||||
$item->price_ptypeid,
|
||||
optional($item->getPType())->ptype_subject,
|
||||
$item->user_categoryid,
|
||||
optional($item->getUserType())->print_name,
|
||||
$item->pplace_id,
|
||||
$item->price,
|
||||
]);
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
|
||||
return Response::download($filename, $filename, $headers);
|
||||
// 🔹 ダウンロードレスポンス
|
||||
return response()->download($path, $filename, $headers)->deleteFileAfterSend(true);
|
||||
}
|
||||
|
||||
|
||||
public function import(Request $request)
|
||||
{
|
||||
$file = $request->file('file');
|
||||
|
||||
@ -17,7 +17,7 @@ class Price extends Model
|
||||
5 => '12ヶ月',
|
||||
];
|
||||
|
||||
protected $table = 'price_a';
|
||||
protected $table = 'price';
|
||||
protected $primaryKey = 'price_parkplaceid';
|
||||
|
||||
protected $fillable = [
|
||||
@ -44,14 +44,14 @@ class Price extends Model
|
||||
{
|
||||
$query = self::query()
|
||||
->select(
|
||||
'price_a.*',
|
||||
'price.*',
|
||||
\DB::raw("CONCAT_WS('/', usertype.usertype_subject1, usertype.usertype_subject2, usertype.usertype_subject3) as user_category_name"),
|
||||
'psection.psection_subject',
|
||||
'ptype.ptype_subject'
|
||||
)
|
||||
->leftJoin('usertype', 'price_a.user_categoryid', '=', 'usertype.user_categoryid')
|
||||
->leftJoin('psection', 'price_a.psection_id', '=', 'psection.psection_id')
|
||||
->leftJoin('ptype', 'price_a.price_ptypeid', '=', 'ptype.ptype_id');
|
||||
->leftJoin('usertype', 'price.user_categoryid', '=', 'usertype.user_categoryid')
|
||||
->leftJoin('psection', 'price.psection_id', '=', 'psection.psection_id')
|
||||
->leftJoin('ptype', 'price.price_ptypeid', '=', 'ptype.ptype_id');
|
||||
|
||||
// ソート対象カラム
|
||||
$allowedSortColumns = [
|
||||
|
||||
@ -41,17 +41,17 @@
|
||||
{{-- 削除 --}}
|
||||
<button type="button" class="btn btn-sm btn-default mr10" id="delete">{{ __('削除') }}</button>
|
||||
|
||||
{{-- CSV出力(全件 or ソート条件付き) --}}
|
||||
<form id="form_export" method="POST" action="{{ route('prices_export') }}" class="d-inline">
|
||||
|
||||
<form id="form_export_csv" method="POST" action="{{ route('prices_export') }}" style="display:inline;">
|
||||
@csrf
|
||||
<input type="hidden" name="park_id" value="{{ $park_id ?? '' }}">
|
||||
<input type="hidden" name="sort" value="{{ $sort ?? '' }}">
|
||||
<input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">
|
||||
<button type="button" class="btn btn-sm btn-default mr10" id="btn_export_csv">CSV出力</button>
|
||||
<button type="button" id="export_csv" class="btn btn-sm btn-default mr10">
|
||||
CSV出力
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
{{-- エクスポート(条件選択モーダル) --}}
|
||||
<button type="button" class="btn btn-sm btn-default mr10" data-toggle="modal" data-target="#exportModal">
|
||||
エクスポート
|
||||
@ -83,7 +83,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer justify-content-center">
|
||||
<button type="submit" class="btn btn-primary w-25">OK</button>
|
||||
<button type="submit" class="btn btn-primary w-25">はい</button>
|
||||
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
|
||||
</div>
|
||||
</form>
|
||||
@ -107,7 +107,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer justify-content-center">
|
||||
<button type="submit" class="btn btn-primary w-25">OK</button>
|
||||
<button type="submit" class="btn btn-primary w-25">はい</button>
|
||||
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
|
||||
</div>
|
||||
</form>
|
||||
@ -225,65 +225,7 @@
|
||||
</div>
|
||||
|
||||
</section>
|
||||
@endsection
|
||||
|
||||
|
||||
@section('scripts')
|
||||
<!-- 载入 jQuery 和 jquery-confirm 工具包(从 CDN) -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
|
||||
|
||||
<!-- CSV 出力脚本 -->
|
||||
<script>
|
||||
$(function() {
|
||||
// ▼ CSV出力ボタン押下
|
||||
$('#btn_export_csv').on('click', function () {
|
||||
const _action = $(this).closest('form').attr('action') || '';
|
||||
|
||||
const park_id = $('#park_id').val() || '';
|
||||
const user_category_id = $('#user_category_id').val() || '';
|
||||
const price_parkplaceid = $('#price_parkplaceid').val() || '';
|
||||
const prine_name = $('#prine_name').val() || '';
|
||||
const ptype_id = $('#ptype_id').val() || '';
|
||||
const psection_id = $('#psection_id').val() || '';
|
||||
const pplace_id = $('#pplace_id').val() || '';
|
||||
const sort = $('input[name="sort"]').val() || '';
|
||||
const sort_type = $('input[name="sort_type"]').val() || '';
|
||||
|
||||
$.confirm({
|
||||
title: '確認ダイアログ',
|
||||
content: 'CSVファイルを出力します。よろしいですか?',
|
||||
buttons: {
|
||||
ok: {
|
||||
text: 'はい',
|
||||
btnClass: 'btn-primary',
|
||||
keys: ['enter'],
|
||||
action: function() {
|
||||
const url =
|
||||
`${_action}?` +
|
||||
`park_id=${encodeURIComponent(park_id)}` +
|
||||
`&user_category_id=${encodeURIComponent(user_category_id)}` +
|
||||
`&price_parkplaceid=${encodeURIComponent(price_parkplaceid)}` +
|
||||
`&prine_name=${encodeURIComponent(prine_name)}` +
|
||||
`&ptype_id=${encodeURIComponent(ptype_id)}` +
|
||||
`&psection_id=${encodeURIComponent(psection_id)}` +
|
||||
`&pplace_id=${encodeURIComponent(pplace_id)}` +
|
||||
`&sort=${encodeURIComponent(sort)}` +
|
||||
`&sort_type=${encodeURIComponent(sort_type)}` +
|
||||
`&isExport=1`;
|
||||
|
||||
window.location.href = url;
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: 'いいえ'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
|
||||
|
||||
|
||||
@ -184,8 +184,12 @@ Route::middleware('auth')->group(function () {
|
||||
Route::match(['get', 'post'], '/admin/prices/info/{id}', [PriceController::class, 'info'])->name('price_info')->where(['id' => '[0-9]+']);
|
||||
Route::match(['get', 'post'], '/admin/prices/delete', [PriceController::class, 'delete'])->name('prices_delete');
|
||||
Route::match(['get', 'post'], '/admin/prices/import', [PriceController::class, 'import'])->name('prices_import');
|
||||
|
||||
// kin 修正
|
||||
Route::post('/admin/prices/export', [PriceController::class, 'export'])->name('prices_export');
|
||||
// CSV出力(GET対応版)
|
||||
Route::get('/admin/prices/export', [PriceController::class, 'exportGet'])
|
||||
->name('prices_export');
|
||||
|
||||
|
||||
//車種区分マスタ
|
||||
Route::match(['get', 'post'], '/admin/psection', [PsectionController::class, 'list'])->name('psections');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user