feat. cafeg promocode

This commit is contained in:
ukyo 2025-08-07 14:06:02 +08:00
parent 20f1bcfbae
commit 75cc5c95e7
10 changed files with 489 additions and 259 deletions

View File

@ -5,18 +5,18 @@
use App\Http\Controllers\Controller;
use App\Imports\PromoImport;
use App\Models\Promocode;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Log;
use Maatwebsite\Excel\Facades\Excel;
use App\Models\User;
class SettingController extends Controller
{
public function promoCode(Request $request)
{
$start = Carbon::now()->month(1)->startOfMonth();
$end = Carbon::now()->endOfMonth();
$end = Carbon::now()->endOfMonth();
$result = Promocode::whereBetween('created_at', [$start, $end])->paginate(100);
@ -33,6 +33,7 @@ public function promoCodeCreate(Request $request)
$request->validate([
'file' => 'required|mimes:xlsx,xls,csv|max:2048',
]);
$from = $request->input('from'); // 默認來源為 cafeg
if ($request->hasFile('file')) {
$file = $request->file('file');
@ -55,7 +56,7 @@ public function promoCodeCreate(Request $request)
// 讀取並導入 Excel 文件
try {
Excel::import(new PromoImport, $file);
Excel::import(new PromoImport($from), $file);
return back()->with('success', '促銷代碼已成功導入!');
} catch (\Exception $e) {
return back()->with('error', '導入失敗: ' . $e->getMessage());
@ -71,17 +72,16 @@ public function adminIndex(Request $request)
public function loginStatus(Request $request)
{
$user = User::where('id', $request->id)->first();
$user = User::where('id', $request->id)->first();
$user->can_login = $request->can_login;
$user->save();
return response()->json([
'status' => 'success',
'msg' => '狀態已更新',
'status' => 'success',
'msg' => '狀態已更新',
'can_login' => $user->can_login,
]);
}
}

View File

@ -1,13 +1,13 @@
<?php
namespace App\Http\Controllers\front;
use App\Http\Controllers\Controller;
use App\Models\EmailVerifications;
use App\Models\Member;
use App\Models\Promocode;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Mail;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class MemberController extends Controller
@ -19,27 +19,55 @@ class MemberController extends Controller
*/
public function index()
{
$code = null;
$user = Auth::guard('member')->user();
if (isset(Auth::guard('member')->user()->id)) {
$user_id = Auth::guard('member')->user()->id;
$code = Promocode::where('used_count', $user_id)->latest()->first();
if (!$code) {
$code = Promocode::where('used_count', 0)->first();
$code->give_to = '首次';
$code->used_count = $user_id;
$code->save();
}
return view('front.member.index', ['code' => $code ]);
} else {
if (! $user) {
Auth::guard('member')->logout();
return redirect()->route('login');
}
$user_id = $user->id;
$today = Carbon::today()->format('Y-m-d');
// 建立一個回傳符合條件的 Promocode 的 function
$getAvailableCode = function ($from) use ($today) {
return Promocode::where('used_count', 0)
->where('from', $from)
->whereDate('valid_from', '<=', $today)
->whereDate('valid_to', '>=', $today)
->latest()
->first();
};
// 試著找一個未使用的
$code = $getAvailableCode('cafeg');
$teacode = $getAvailableCode('teamaster');
// 如果找不到,就再次找一個未使用的然後標記成首次給予
if (! $code) {
$code = $getAvailableCode('cafeg');
if ($code) {
$code->give_to = '首次';
$code->used_count = $user_id;
$code->save();
}
}
if (! $teacode) {
$teacode = $getAvailableCode('teacode');
if ($teacode) {
$teacode->give_to = '首次';
$teacode->used_count = $user_id;
$teacode->save();
}
}
return view('front.member.index', [
'code' => $code,
'teacode' => $teacode,
]);
}
/**
* Summary of profile 登入後個人資訊沒有menu
* @return \Illuminate\Contracts\View\View
@ -59,9 +87,9 @@ public function profileUpdate(Request $request)
{
// 驗證輸入的數據
$validatedData = $request->validate([
'email' => 'required|email',
'email' => 'required|email',
'password' => 'nullable|min:6', // password 與 password_confirmation 必須匹配
'phone' => 'nullable|string|max:15',
'phone' => 'nullable|string|max:15',
]);
$auth = Member::find(Auth::guard('member')->id());
@ -126,7 +154,7 @@ public function checkEmail(Request $request)
public function changeLevel(Request $request)
{
$user = Member::find($request->id);
$user = Member::find($request->id);
$user->level = $request->level;
$user->save();
return response()->json(['status' => 'success', '成功', 'level' => $request->level, 'name' => $user->level_name]);

View File

@ -1,11 +1,12 @@
<?php
namespace App\Http\Controllers\front;
use App\Http\Controllers\Controller;
use App\Models\Promocode;
use Auth;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Http\Request;
class PromoCodeController extends Controller
{
@ -23,16 +24,22 @@ public function index()
public function create(Request $request)
{
$user_id = Auth::guard('member')->user()->id;
$count = Promocode::where('used_count', $user_id)->count();
$count = Promocode::where('used_count', $user_id)->count();
$give_to = $request->input('give_to');
$row = Promocode::where('used_count', 0)->first();
$from = $request->input('from');
$row = Promocode::where('used_count', 0)
->where('from', $from)
->where(
'valid_from',
'<=',
now()
)->where('valid_to', '>=', now())
->first();
$row->used_count = $user_id;
$row->give_to = $give_to;
$row->give_to = $give_to;
$row->save();
return response()->json(['status' => 'success', 'msg' => '已成功取得', 'promocode' => $row->code, 'give_to' => $row->give_to]);
}
/**
* Summary of morePromocode
@ -46,7 +53,7 @@ public function morePromocode()
if ($user->level != 9) {
throw new Exception("Error Processing Request", 401);
} else {
$row = Promocode::where('used_count', 0)->first();
$row = Promocode::where('used_count', 0)->first();
$row->used_count = $user->id;
$row->save();
return response()->json(['status' => 'success', 'msg' => '已成功取得', 'promocode' => $row->code]);
@ -57,7 +64,6 @@ public function morePromocode()
}
}
/**
* Store a newly created resource in storage.
*/

View File

@ -1,4 +1,5 @@
<?php
namespace App\Imports;
use App\Models\Promocode;
@ -6,31 +7,109 @@
use Log;
use Maatwebsite\Excel\Concerns\ToCollection;
use function Illuminate\Log\log;
class PromoImport implements ToCollection
{
protected $from;
public function __construct($from = 'cafeg')
{
$this->from = $from;
}
public function collection(Collection $rows)
{
// 打印每一行數據(這是從 Excel 讀取的行)
if ($this->from == 'cafeg') {
foreach ($rows as $row) {
foreach ($rows as $row) {
$data = $row->toArray();
Log::info('Row data: ', ['value' => $row->toArray()[3]]);
if ($data[3] != '提货码') { // 跳過標題行
$code = $data[3];
if ($row->toArray()[3] != '提货码') // 跳過第一行
{
Promocode::create([
'code' => $row->toArray()[3], // 使用 "提货码" 列
'discount' => 100, // 假設折扣為固定值 100
'type' => 'percent', // 默認為百分比
'usage_limit' => 1, // 默認每個代碼只能使用一次
'valid_from' => date('Y-m-d'), // 當前日期
'valid_to' => date('Y-m-d', strtotime('1 day')), // 默認有效期至第二天
'is_active' => 1, // 默認啟用
]);
$promo = Promocode::where('code', $code)
->where('from', 'cafeg')
->first();
if ($promo) {
// 如果已存在,且 give_to 不為 null就更新
if ($promo->give_to !== null) {
$promo->update([
'discount' => 100,
'type' => 'percent',
'usage_limit' => 1,
'valid_from' => date('Y-m-d'),
'valid_to' => date('Y-m-d', strtotime('+1 day')),
'is_active' => 1,
'from' => 'cafeg',
]);
Log::info("已更新:{$code}");
} else {
Log::info("跳過give_to 為 null{$code}");
}
} else {
// 不存在就新增
Promocode::create([
'code' => $code,
'discount' => 100,
'type' => 'percent',
'usage_limit' => 1,
'valid_from' => date('Y-m-d'),
'valid_to' => date('Y-m-d', strtotime('+1 day')),
'is_active' => 1,
'from' => 'cafeg',
]);
Log::info("已新增:{$code}");
}
}
}
}
if ($this->from == 'teamaster') {
Log::info('import-from: teamaster');
Log::info('row', );
foreach ($rows->toArray() as $row) {
$code = $row[0];
$promo = Promocode::where('code', $code)
->where('from', 'teamaster')
->first();
if ($promo) {
// 如果已存在,且 give_to 不為 null就更新
if ($promo->give_to != null) {
$promo->update([
'discount' => 70,
'type' => 'amount',
'usage_limit' => 1,
'valid_from' => date('Y-m-d'),
'valid_to' => date('Y-m-d', strtotime('+7 day')),
'is_active' => 1,
'from' => 'teamaster',
]);
Log::info("已更新:{$code}");
} else {
Log::info("跳過give_to 為 null{$code}");
}
} else {
Log::info("新增代碼:{$code}");
// 不存在就新增
Promocode::create([
'code' => $code,
'discount' => 70,
'type' => 'amount',
'usage_limit' => 1,
'valid_from' => date('Y-m-d'),
'valid_to' => date('Y-m-d', strtotime('+7 day')),
'is_active' => 1,
'from' => 'teamaster',
]);
Log::info("已新增:{$code}");
}
}
}
}
}

View File

@ -7,20 +7,19 @@
class Promocode extends Model
{
//
protected $table = 'promocodes';
protected $fillable = [
'code',
'discount',
'type',
'usage_limit',
'used_count',
'valid_from',
'valid_to',
'is_active',
];
protected $table = 'promocodes';
protected $guarded = [];
public function getMember()
{
return $this->hasOne(Member::class, 'id', 'used_count');
}
public function getFromLabelAttribute()
{
return match ($this->from) {
'cafeg' => '朗立臣',
'teamaster' => '飲力星球',
default => '未知來源',
};
}
}

View File

@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('promocodes', function (Blueprint $table) {
$table->enum('from', ['cafeg', 'teamaster', 'unknown'])->comment('來源')->after('id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('promocodes');
}
};

View File

@ -361,65 +361,48 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
});
function changeLevel(id, lv) {
Swal.fire({
title: "確定",
text: "你即將修改此用戶權限!",
icon: "warning",
showCancelButton: true,
confirmButtonText: "確定",
cancelButtonText: "取消"
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "patch",
url: "{{ route('member.changelevel') }}",
data: {
id: id,
level: lv
},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(response) {
if (response.status == 'success') {
console.log(lv);
// lv = response.level;
name = response.name;
var view = '';
if (lv == 0) {
view = '<i class = "ri-user-line ri-22px text-danger me-2" ></i>' +
name;
}
if (lv == 1) {
view = '<i class = "ri-user-line ri-22px text-info me-2" ></i>' +
name;
}
if (lv == 2) {
view = '<i class = "ri-user-line ri-22px text-sucess me-2" > </i>' +
name;
}
if (lv == 9) {
view =
'<i class = "ri-user-line ri-22px text-warning me-2" > </i>' +
name;
}
$("#user-" + id).html(view);
Swal.fire({
title: "確定",
text: "你即將修改此用戶權限!",
icon: "warning",
showCancelButton: true,
confirmButtonText: "確定",
cancelButtonText: "取消"
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "patch",
url: "{{ route('member.changelevel') }}",
data: {
id: id,
level: lv
},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(response) {
if (response.status == 'success') {
let name = response.name;
let view = '';
if (lv == 0) {
view = '<i class="ri-user-line ri-22px text-danger me-2"></i>' + name;
} else if (lv == 1) {
view = '<i class="ri-user-line ri-22px text-info me-2"></i>' + name;
} else if (lv == 2) {
view = '<i class="ri-user-line ri-22px text-sucess me-2"></i>' + name;
} else if (lv == 9) {
view = '<i class="ri-user-line ri-22px text-warning me-2"></i>' + name;
}
$("#user-" + id).html(view);
Swal.fire("成功", "修改成功", "success");
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
Swal.fire("取消", "使用者取消操作", "error");
console.log("使用者取消操作");
}
});
}
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
Swal.fire("取消", "使用者取消操作", "error");
}
});
}
</script>
<script src="{{ asset('assets/vendor/js/dropdown-hover.js') }}"></script>
@endsection

View File

@ -49,28 +49,57 @@
<!-- Basic Layout -->
<div class="row">
<div class="col-xl">
<div class="card mb-12" style="margin-bottom: 20px;">
<div class="col-xl">
<div class="card mb-12" style="margin-bottom: 20px;">
<h5 class="card-header">Excel 匯入</h5>
<div class="card-body">
<div class="card-body">
<form action="{{route('admin.promocode.create')}}" method="POST" enctype="multipart/form-data">
@csrf
<!-- Tabs -->
<ul class="nav nav-tabs" id="importTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="cafeg-tab" data-bs-toggle="tab" data-bs-target="#cafeg-form"
type="button" role="tab" aria-controls="cafeg-form" aria-selected="true">朗立臣</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="teamaster-tab" data-bs-toggle="tab" data-bs-target="#teamaster-form"
type="button" role="tab" aria-controls="teamaster-form" aria-selected="false">飲力星球</button>
</li>
</ul>
<h5 class="card-header">輸入檔案</h5>
<div class="card-body">
<div class="mb-4">
<label for="formFile" class="form-label">檔案類型 excels</label>
<input class="form-control" name="file" type="file" id="formFile">
</div>
<!-- Tab Content -->
<div class="tab-content mt-4" id="importTabsContent">
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
</div>
<!-- 朗立臣 (cafeg) -->
<div class="tab-pane fade show active" id="cafeg-form" role="tabpanel" aria-labelledby="cafeg-tab">
<form action="{{ route('admin.promocode.create') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="mb-4">
<label for="formFile1" class="form-label">匯入 Excel朗立臣</label>
<input class="form-control" name="file" type="file" id="formFile1">
<input type="hidden" name="from" value="cafeg">
</div>
<button type="submit" class="btn btn-primary">送出</button>
</form>
</div>
<!-- 飲力星球 (teamaster) -->
<div class="tab-pane fade" id="teamaster-form" role="tabpanel" aria-labelledby="teamaster-tab">
<form action="{{ route('admin.promocode.create') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="mb-4">
<label for="formFile2" class="form-label">匯入 Excel飲力星球</label>
<input class="form-control" name="file" type="file" id="formFile2">
<input type="hidden" name="from" value="teamaster">
</div>
<button type="submit" class="btn btn-success">送出</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- DataTable with Buttons -->
<div class="card">
@ -78,7 +107,7 @@
<table class="datatables-basic table table-bordered">
<thead>
<tr>
<th style="width: 20%; !important">來源</th>
<th style="width: 20%; !important"> 優惠碼</th>
<th style="width: 15%; !important">優惠類型</th>
<th style="width: 20%; !important">折扣比例</th>
@ -89,6 +118,7 @@
<tbody>
@foreach($data as $item)
<tr>
<td>{{$item->getFromLabelAttribute()}}</td>
<td><strong class="text-danger blod">{{$item->code}}</strong></td>
<td>{{$item->type}}</td>
<td> {{ number_format($item->discount, 0) }}</td>

View File

@ -102,15 +102,17 @@ class="fw-medium">{{ Auth::guard('member')->user()->Level_Name }}</span>
<ul class="nav nav-pills " role="tablist">
<li class="nav-item">
<button type="button"
id="cafeg-tab"
class="nav-link d-flex flex-column gap-1 active" role="tab"
data-bs-toggle="tab"
data-bs-target="#navs-pills-within-card-active"
aria-controls="navs-pills-within-card-active"
aria-selected="true"><i class="tf-icons ri-home-smile-line"></i>
國王&皇后</button>
</li>
<li class="nav-item">
<button type="button" class="nav-link d-flex flex-column gap-1"
<button id= "tea-tab" type="button" class="nav-link d-flex flex-column gap-1"
role="tab" data-bs-toggle="tab"
data-bs-target="#navs-pills-within-card-link"
aria-controls="navs-pills-within-card-link"
@ -157,10 +159,39 @@ class="nav-link d-flex flex-column gap-1 active" role="tab"
</div>
</div>
<div class="tab-pane fade" id="navs-pills-within-card-link" role="tabpanel">
<div class="tab-pane fade" id="navs-pills-within-card-link"
role="tabpanel">
<h4 class="card-title">茶飲大師手搖機 飲品兌換卷</h4>
<p class="card-text">施工中 ....</p>
{{-- <a href="javascript:void(0)" class="btn btn-secondary">Go somewhere</a> --}}
<div class="form-floating form-floating-outline">
@if (Auth::guard('member')->user()->level != 9)
<input type="text" class="form-control text-danger"
style="font-size:24px; font-weight: bold;"
id="floatingInput4" aria-describedby="floatingInputHelp">
<label for="floatingInput">兌換碼</label>
{{-- <div id="floatingInputHelp" class="form-text">We'll never share your details with anyone else.</div> --}}
@else
{{-- 顯示給予誰 --}}
<div class="input-group" id ="tea-give-to">
<input type="text" class="form-control text-info"
style="font-size:24px; font-weight: bold;"
id="floatingInput5" aria-describedby="button-addon3"
placeholder="給予誰" required=true>
<button class="btn btn-outline-primary" type="button"
id="button-addon4">獲取兌換碼</button>
</div>
{{-- 顯示兌換碼 --}}
<div class="input-group" id="promocode-show-teamaster">
<input type="text" class="form-control text-danger"
style="font-size:24px; font-weight: bold;"
id="floatingInput6" aria-describedby="button-addon7">
<button class="btn btn-outline-primary" type="button"
id="button-addon7">重新獲取</button>
</div>
@endif
</div>
</div>
</div>
</div>
@ -168,112 +199,189 @@ class="nav-link d-flex flex-column gap-1 active" role="tab"
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-4 col-lg-5 col-md-5">
<!-- About User -->
<div class="card mb-6">
<div class="card-body" style="padding-top: 3%">
<small class="card-text text-uppercase text-muted small">QRCode</small>
<div class="d-flex justify-content-center" id="qrcode" style="padding-top: 3%">
<div class="row">
<div class="col-xl-4 col-lg-5 col-md-5">
<!-- About User -->
<div class="card mb-6">
<div class="card-body" style="padding-top: 3%">
<small class="card-text text-uppercase text-muted small">QRCode</small>
<div class="d-flex justify-content-center" id="qrcode"
style="padding-top: 3%">
</div>
<!-- Flexbox居中 -->
</div>
<!-- Flexbox居中 -->
</div>
<!--/ About User -->
</div>
<!--/ About User -->
</div>
<div class="col-xl-8 col-lg-7 col-md-7">
<!-- Activity Timeline -->
<div class="card card-action mb-6">
<div class="card-header align-items-center">
<h5 class="card-action-title mb-0"><i
class='ri-bar-chart-2-line ri-24px text-body me-4'></i>消費紀錄</h5>
</div>
<div class="card-body pt-5">
<!-- Order List Table -->
<div class="card">
<div class="card-datatable table-responsive">
<table class="datatables-order table">
<thead>
<tr>
<div class="col-xl-8 col-lg-7 col-md-7">
<!-- Activity Timeline -->
<div class="card card-action mb-6">
<div class="card-header align-items-center">
<h5 class="card-action-title mb-0"><i
class='ri-bar-chart-2-line ri-24px text-body me-4'></i>消費紀錄</h5>
</div>
<div class="card-body pt-5">
<!-- Order List Table -->
<div class="card">
<div class="card-datatable table-responsive">
<table class="datatables-order table">
<thead>
<tr>
<th>訂單號</th>
<th>日期</th>
<th>品項</th>
<th>金額</th>
<th>狀態</th>
<th>訂單號</th>
<th>日期</th>
<th>品項</th>
<th>金額</th>
<th>狀態</th>
</tr>
</thead>
<tbody>
<tr>
<!-- #region -->
<td colspan="5"> 目前暫無資料</td>
</tr>
</thead>
<tbody>
<tr>
<!-- #region -->
<td colspan="5"> 目前暫無資料</td>
</tr>
</tr>
</tbody>
</tbody>
</table>
</table>
</div>
</div>
</div>
</div>
<!--/ Activity Timeline -->
</div>
<!--/ Activity Timeline -->
</div>
</div>
</div>
<!-- / Header -->
<!-- Navbar pills -->
<!--/ User Profile Content -->
</div>
<!-- / Header -->
<!-- Navbar pills -->
<!--/ User Profile Content -->
<!-- / Content -->
</div>
<!-- / Content -->
<!-- beautify ignore:end -->
</div>
<!-- beautify ignore:end -->
<!-- Include necessary scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
{{-- 一開始 Loading 使用script 判斷 --}}
<!-- Include necessary scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
{{-- 一開始 Loading 使用script 判斷 --}}
<script>
$(document).ready(function() {
var id = "{{ Auth::guard('member')->user()->id }}";
$("#promocode").hide();
// $("#promocode-show").hide();
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: id, // 要顯示的內容
width: 250, // QR code 的寬度
height: 250 // QR code 的高度
});
});
$("#submit-btn").on('click', function() {
var id = "{{ Auth::guard('member')->user()->id }}";
$("#promocode").show();
var give_to = "{{ $code->give_to }}";
var code ="{{ $code->code }}";
<script>
$(document).ready(function() {
console.log("Document is ready");
var id = "{{ Auth::guard('member')->user()->id }}";
$("#promocode").hide();
$("#promocode-show-teamaster").hide();
$("#tea-give-to").hide();
// 建立 QR Code
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: id,
width: 250,
height: 250
});
console.log('code:',code);
if (code) {
// 顯示資料按鈕
$("#submit-btn").on('click', function() {
$("#promocode").show();
console.log('submit button clicked');
var give_to = "{{ $code->give_to ?? '' }}";
var code = "{{ $code->code ?? '' }}";
var t_give_to = "{{ $teacode->give_to ?? '' }}";
var t_code = "{{ $teacode->code ?? '' }}";
if (code) {
$("#give-to").hide();
$("#floatingInput2").val(code);
$("#last-give-to").html("最後給予 : " + give_to);
} else {
$("#give-to").show();
}
if (t_code) {
$("#tea-give-to").hide();
$("#floatingInput6").val(t_code);
$("#last-give-to").html("最後給予 : " + give_to);
} else {
$("#tea-give-to").show();
}
});
//tab 切換
$("#cafeg-tab").on('click', function() {
$("#promocode-show").show();
});
$("#tea-tab").on('click', function() {
$("#promocode-show-teamaster").show();
$("#promocode-show").hide();
$("#tea-give-to").hide();
});
// cafeg 請求
$("#button-addon3").on('click', function(event) {
event.preventDefault();
var give_to = $("#floatingInput3").val();
if (!give_to) return alert("請輸入給予誰的資訊");
$.ajax({
url: "{{ route('member.getpromocode') }}",
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id,
give_to: give_to,
from: 'cafeg',
},
success: function(res) {
$("#promocode-show").show();
$("#give-to").hide();
$("#floatingInput2").val(code);
$("#last-give-to").html("最後給予 : " + give_to);
} else {
$("#give-to").show();
$("#floatingInput2").val(res.promocode);
},
error: function(xhr) {
console.log(xhr.responseText);
}
console.log('id:', id);
});
});
// teamaster 請求
$("#button-addon4").on('click', function(event) {
event.preventDefault();
var give_to = $("#floatingInput5").val();
if (!give_to) return alert("請輸入給予誰的資訊");
$.ajax({
url: "{{ route('member.getpromocode') }}",
type: 'POST',
data: {
_token: '{{ csrf_token() }}',
id: id,
give_to: give_to,
from: 'teamaster',
},
success: function(res) {
$("#promocode-show-teamaster").show();
$("#tea-give-to").hide();
$("#floatingInput6").val(res.promocode);
},
error: function(xhr) {
console.log(xhr.responseText);
}
});
});
});
//給予誰
$("#button-addon2").on('click', function() {
var id = "{{ Auth::guard('member')->user()->id }}";
$("#promocode").show();
@ -283,39 +391,15 @@ class='ri-bar-chart-2-line ri-24px text-body me-4'></i>消費紀錄</h5>
console.log('id:', id);
});
$("#button-addon3").on('click', function(event) {
event.preventDefault(); // 阻止表单的默认提交行为
//給予誰
$("#button-addon7").on('click', function() {
var id = "{{ Auth::guard('member')->user()->id }}";
var give_to = $("#floatingInput3").val();
// 检查输入框的值是否为空
if (!give_to) {
alert("請輸入給予誰的資訊");
return;
}
// 發送 AJAX 請求
$.ajax({
url: "{{ route('member.getpromocode') }}", // 設定你的路由 URL
type: 'POST',
data: {
_token: '{{ csrf_token() }}', // CSRF token
id: id,
give_to: give_to
},
success: function(response) {
$("#promocode-show").show();
$("#give-to").hide();
$("#floatingInput").val(response.promocode);
$("#floatingInput2").val(response.promocode);
console.log(response); // 顯示後端回應資料
},
error: function(xhr, status, error) {
console.log(xhr.responseText); // 顯示錯誤資訊
}
});
$("#promocode").show();
$("#tea-give-to").show();
$("#floatingInput5").val("");
$("#promocode-show-teamaster").hide();
});
</script>
@endsection
</script>
@endsection

View File

@ -6,7 +6,6 @@
use App\Http\Controllers\front\RegisterController;
use App\Http\Controllers\LoginController;
use App\Http\Middleware\GuestRedirect;
use App\Http\Middleware\memberAuth;
use App\Http\Middleware\MemberRedirect;
use Illuminate\Support\Facades\Route;
@ -48,9 +47,6 @@
Route::get('google/callback', [LoginController::class, 'handleGoogleCallback'])->name('google.redirect');
Route::patch('changelevel', [MemberController::class, 'changeLevel'])->name('member.changelevel');
//前台route 登入後;
Route::prefix('member')
->middleware(['auth:member']) // 使用自定义守卫的中间件