feat. 兌換碼

This commit is contained in:
ukyo 2025-02-18 11:45:37 +08:00
parent 1ce473133d
commit dc2535723c
4 changed files with 52 additions and 20 deletions

View File

@ -4,13 +4,14 @@
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Member; use App\Models\Member;
use App\Models\Promocode;
class MemberController extends Controller class MemberController extends Controller
{ {
public function index() public function index()
{ {
$data = Member::paginate(20); $data = Member::paginate(20);
return view('admin.member.index', ['data' => $data]); $total =Promocode::where('used_count','>',0)->count();
return view('admin.member.index', ['data' => $data,'total'=>$total]);
} }
} }

View File

@ -32,7 +32,9 @@ public function index()
$code->save(); $code->save();
} }
return view('front.member.index', ['code' => $code]);
return view('front.member.index', ['code' => $code ]);
} else { } else {
Auth::guard('member')->logout(); Auth::guard('member')->logout();
return redirect()->route('login'); return redirect()->route('login');

View File

@ -242,7 +242,6 @@
@if (session('error')) @if (session('error'))
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
console.log('go there');
Swal.fire({ Swal.fire({
title: '失敗' title: '失敗'
, text: "{{ session('error') }}" , text: "{{ session('error') }}"

View File

@ -3,7 +3,7 @@
@endsection @endsection
@section('content') @section('content')
<style> <style>
.table th{ .table th {
white-space: nowrap; white-space: nowrap;
/* 禁止文字換行 */ /* 禁止文字換行 */
text-align: center; text-align: center;
@ -13,7 +13,8 @@
text-overflow: ellipsis; text-overflow: ellipsis;
/* 超出用省略號顯示 */ /* 超出用省略號顯示 */
} }
.table td{
.table td {
white-space: nowrap; white-space: nowrap;
} }
@ -31,8 +32,6 @@
table { table {
position: static !important; position: static !important;
} }
</style> </style>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@ -138,7 +137,9 @@
</div> </div>
</div> </div>
</div> </div>
@php
$pageTotal = 0;
@endphp
<!-- Users List Table --> <!-- Users List Table -->
<div class="card"> <div class="card">
<div class="card-header border-bottom"> <div class="card-header border-bottom">
@ -209,12 +210,16 @@ class="rounded-circle">
{{ $item->getPromoCode[0]->code }} {{ $item->getPromoCode[0]->code }}
</span> </span>
@endif @endif
@php
$pageTotal += count($item->getPromoCode) ;
@endphp
@if (count($item->getPromoCode) > 1) @if (count($item->getPromoCode) > 1)
<a class="text-danger" style="font-size:20px" data-bs-toggle="collapse" <a class="text-danger" style="font-size:20px" data-bs-toggle="collapse"
href="#multiCollapseExample-{{ $item->id }}" role="button" href="#multiCollapseExample-{{ $item->id }}" role="button"
aria-expanded="false" aria-controls="multiCollapseExample1"> aria-expanded="false" aria-controls="multiCollapseExample1">
{{ $item->getPromoCode[0]->code }} ({{ count($item->getPromoCode) }} {{ $item->getPromoCode[0]->code }} ({{ count($item->getPromoCode) }}
) )
</a> </a>
@endif @endif
</td> </td>
@ -273,13 +278,16 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php $i = 1 ; @endphp @php
@foreach ($item->getPromoCode as $key => $val) $i=1;
$promoCodes = $item->getPromoCode()->paginate(30); // 每頁30筆優惠碼
@endphp
@foreach ($promoCodes as $val)
@if ($i == 1) @if ($i == 1)
<tr> <tr>
@endif @endif
<td>{{ $i }} {{ $val->code }}</td> <td class="text-danger"> {{ $val->code }}</td>
<td>{{ $val->give_to }}</td> <td class="text-info">{{ $val->give_to }}</td>
@if ($i == 5) @if ($i == 5)
</tr> </tr>
@php $i = 0 @endphp @php $i = 0 @endphp
@ -287,6 +295,13 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
@php $i++; @endphp @php $i++; @endphp
@endforeach @endforeach
</tbody> </tbody>
<tfoot>
<th colspan="10">
@if($promoCodes->count()>30)
{{ $promoCodes->links() }}
@endif
</th>
</tfoot>
</table> </table>
{{-- <span class="text-danger " style="font-size:20px"> {{-- <span class="text-danger " style="font-size:20px">
@foreach ($item->getPromoCode as $key => $val) @foreach ($item->getPromoCode as $key => $val)
@ -303,6 +318,16 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
<tfoot>
<tr>
<th colspan="3">本頁兌換碼計數</th>
<th colspan="4">總兌換碼計數</th>
</tr>
<tr>
<th colspan="3" class="text-start-center"><h3 class="mb-1 me-2 text-info">{{ $pageTotal }}</h3></th>
<th colspan="4" class="text-start-center"><h3 class="mb-1 me-2 text-info">{{ $total}} </h3></th>
</tr>
</tfoot>
</table> </table>
</div> </div>
</div> </div>
@ -362,20 +387,25 @@ function changeLevel(id, lv) {
console.log(lv); console.log(lv);
// lv = response.level; // lv = response.level;
name = response.name; name = response.name;
var view =''; var view = '';
if (lv == 0) { if (lv == 0) {
view = '<i class = "ri-user-line ri-22px text-danger me-2" ></i>' + name; view = '<i class = "ri-user-line ri-22px text-danger me-2" ></i>' +
name;
} }
if (lv == 1) { if (lv == 1) {
view = '<i class = "ri-user-line ri-22px text-info me-2" ></i>'+ name; view = '<i class = "ri-user-line ri-22px text-info me-2" ></i>' +
name;
} }
if (lv == 2) { if (lv == 2) {
view = '<i class = "ri-user-line ri-22px text-sucess me-2" > </i>'+ name; view = '<i class = "ri-user-line ri-22px text-sucess me-2" > </i>' +
name;
} }
if (lv == 9) { if (lv == 9) {
view = '<i class = "ri-user-line ri-22px text-warning me-2" > </i>'+ name; view =
'<i class = "ri-user-line ri-22px text-warning me-2" > </i>' +
name;
} }
$("#user-"+id).html(view); $("#user-" + id).html(view);
} }