Compare commits
No commits in common. "2b8c5be3d12fb42b1a2d61d4ddc3f89efbb13dda" and "265e5799a3aff8d007b56fabb1d19d02064c3e4c" have entirely different histories.
2b8c5be3d1
...
265e5799a3
@ -4,14 +4,13 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Member;
|
||||
use App\Models\Promocode;
|
||||
|
||||
class MemberController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = Member::paginate(20);
|
||||
$total =Promocode::where('used_count','>',0)->count();
|
||||
return view('admin.member.index', ['data' => $data,'total'=>$total]);
|
||||
return view('admin.member.index', ['data' => $data]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,14 +5,14 @@
|
||||
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();
|
||||
@ -33,7 +33,6 @@ 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');
|
||||
@ -56,7 +55,7 @@ public function promoCodeCreate(Request $request)
|
||||
|
||||
// 讀取並導入 Excel 文件
|
||||
try {
|
||||
Excel::import(new PromoImport($from), $file);
|
||||
Excel::import(new PromoImport, $file);
|
||||
return back()->with('success', '促銷代碼已成功導入!');
|
||||
} catch (\Exception $e) {
|
||||
return back()->with('error', '導入失敗: ' . $e->getMessage());
|
||||
@ -82,6 +81,7 @@ public function loginStatus(Request $request)
|
||||
'can_login' => $user->can_login,
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,22 +42,12 @@ public function redirectToProvider(Request $request)
|
||||
*/
|
||||
public function handleProviderCallback(Request $request)
|
||||
{
|
||||
// 如果用户取消了授权
|
||||
if ($request->has('error') && $request->get('error') === 'access_denied') {
|
||||
|
||||
// 从 Session 获取 $redirectTo
|
||||
$redirectTo = session('redirect_to', 'member');
|
||||
|
||||
if ($redirectTo === 'admin') {
|
||||
return redirect()->route('admin.login')->with('error', '您已取消 LINE 授权');
|
||||
} else {
|
||||
return redirect()->route('login')->with('error', '您已取消 LINE 授权');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取 LINE 用户信息
|
||||
$user = Socialite::driver('line')->user();
|
||||
Log::info('line', ['user' => $user]);
|
||||
|
||||
$lineId = $user->getId();
|
||||
$name = $user->getName();
|
||||
$avatar = $user->getAvatar() ?? '';
|
||||
@ -65,12 +55,9 @@ public function handleProviderCallback(Request $request)
|
||||
|
||||
Log::info('email', [$email]);
|
||||
|
||||
// 从 Session 获取跳转路径
|
||||
$redirectTo = session('redirect_to', 'member');
|
||||
|
||||
if ($redirectTo === 'admin') {
|
||||
if ($redirectTo == 'admin') {
|
||||
// Admin 登录逻辑
|
||||
$existingUser = User::where('line_id', $lineId)
|
||||
$existingUser = $user = User::where('line_id', $lineId)
|
||||
->orWhere('email', $email)
|
||||
->first();
|
||||
|
||||
@ -107,6 +94,7 @@ public function handleProviderCallback(Request $request)
|
||||
'password' => bcrypt(env('DEFAULT_PASSWORD')),
|
||||
'source' => 'cafeg',
|
||||
'avatar' => $avatar,
|
||||
|
||||
'email' => $email,
|
||||
]);
|
||||
Auth::guard('member')->login($newUser);
|
||||
@ -117,14 +105,7 @@ public function handleProviderCallback(Request $request)
|
||||
? redirect()->route('member.index')
|
||||
: redirect()->route('member.profile');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('LINE 登录失败: ' . $e->getMessage());
|
||||
|
||||
// 发生异常时,返回登录页面并提示错误
|
||||
return redirect()->route('login')->with('error', 'LINE 登录失败,请稍后再试');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function adminLogout()
|
||||
{
|
||||
@ -157,7 +138,7 @@ public function memberNormalLogin(Request $request)
|
||||
return redirect()->route('member.index');
|
||||
} else {
|
||||
|
||||
return redirect()->route('login')->with('error', '帳號密碼錯誤');
|
||||
return redirect()->route('front.login.view')->with('error', '帳號密碼錯誤');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Mail;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class MemberController extends Controller
|
||||
@ -19,55 +19,25 @@ class MemberController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::guard('member')->user();
|
||||
$code = null;
|
||||
|
||||
if (! $user) {
|
||||
Auth::guard('member')->logout();
|
||||
return redirect()->route('login');
|
||||
}
|
||||
if (isset(Auth::guard('member')->user()->id)) {
|
||||
$user_id = Auth::guard('member')->user()->id;
|
||||
$code = Promocode::where('used_count', $user_id)->latest()->first();
|
||||
|
||||
$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 = Promocode::where('used_count', 0)->first();
|
||||
$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]);
|
||||
} else {
|
||||
Auth::guard('member')->logout();
|
||||
return redirect()->route('front.login.view');
|
||||
}
|
||||
}
|
||||
|
||||
return view('front.member.index', [
|
||||
'code' => $code,
|
||||
'teacode' => $teacode,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary of profile 登入後個人資訊沒有menu
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\front;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Promocode;
|
||||
use Auth;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Exception;
|
||||
|
||||
class PromoCodeController extends Controller
|
||||
{
|
||||
@ -23,25 +22,17 @@ public function index()
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
|
||||
$user_id = Auth::guard('member')->user()->id;
|
||||
$count = Promocode::where('used_count', $user_id)->count();
|
||||
$give_to = $request->input('give_to');
|
||||
$from = $request->input('from');
|
||||
$row = Promocode::where('used_count', 0)
|
||||
->where('from', $from)
|
||||
->first();
|
||||
|
||||
|
||||
|
||||
if (!$row) {
|
||||
return response()->json(['status' => 'error', 'msg' => '目前無可用的優惠碼']);
|
||||
}
|
||||
|
||||
$row = Promocode::where('used_count', 0)->first();
|
||||
$row->used_count = $user_id;
|
||||
$row->give_to = $give_to;
|
||||
$row->save();
|
||||
return response()->json(['status' => 'success', 'msg' => '已成功取得', 'promocode' => $row->code, 'give_to' => $row->give_to]);
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Summary of morePromocode
|
||||
@ -66,6 +57,7 @@ public function morePromocode()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
||||
@ -35,8 +35,14 @@ public function create(Request $request)
|
||||
'phone' => $request->phone ?? '',
|
||||
]);
|
||||
|
||||
return redirect()->route('login')->with('sucess', '完成註冊,請登入');
|
||||
if (isset($newUser->email)) {
|
||||
|
||||
return redirect()->route('member.index')->with('sucess', '完成註冊');
|
||||
|
||||
} else {
|
||||
|
||||
return redirect()->route('member.profile')->with('sucess', '完成註冊,請完善你得資料');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -125,7 +131,7 @@ public function resetPassword(Request $request)
|
||||
|
||||
} else {
|
||||
|
||||
return redirect()->route('login')->with('error', '驗證密碼token 失敗');
|
||||
return redirect()->route('front.login.view')->with('error', '驗證密碼token 失敗');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Models\Promocode;
|
||||
@ -7,109 +6,31 @@
|
||||
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)
|
||||
{
|
||||
if ($this->from == 'cafeg') {
|
||||
// 打印每一行數據(這是從 Excel 讀取的行)
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
|
||||
if ($data[3] != '提货码') { // 跳過標題行
|
||||
$code = $data[3];
|
||||
Log::info('Row data: ', ['value' => $row->toArray()[3]]);
|
||||
|
||||
$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 {
|
||||
// 不存在就新增
|
||||
if ($row->toArray()[3] != '提货码') // 跳過第一行
|
||||
{
|
||||
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',
|
||||
'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, // 默認啟用
|
||||
]);
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,8 +10,7 @@
|
||||
|
||||
class Member extends Authenticatable
|
||||
{
|
||||
use HasApiTokens;
|
||||
use Notifiable;
|
||||
use HasApiTokens, Notifiable;
|
||||
|
||||
protected $table = 'members';
|
||||
/**
|
||||
@ -65,7 +64,7 @@ public function getLevelNameAttribute()
|
||||
|
||||
public function getPromoCode()
|
||||
{
|
||||
return $this->hasMany(Promocode::class, 'giveto_mem_id', 'id');
|
||||
return $this->hasMany(Promocode::class, 'used_count', 'id');
|
||||
}
|
||||
protected function casts(): array
|
||||
{
|
||||
|
||||
@ -8,18 +8,19 @@ class Promocode extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'promocodes';
|
||||
protected $guarded = [];
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'discount',
|
||||
'type',
|
||||
'usage_limit',
|
||||
'used_count',
|
||||
'valid_from',
|
||||
'valid_to',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
public function getMember()
|
||||
{
|
||||
return $this->hasOne(Member::class, 'id', 'used_count');
|
||||
}
|
||||
public function getFromLabelAttribute()
|
||||
{
|
||||
return match ($this->from) {
|
||||
'cafeg' => '朗立臣',
|
||||
'teamaster' => '飲力星球',
|
||||
default => '未知來源',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
};
|
||||
Binary file not shown.
@ -231,17 +231,10 @@
|
||||
</body>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
@if (session('error'))
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
console.log('go there');
|
||||
Swal.fire({
|
||||
title: '失敗'
|
||||
, text: "{{ session('error') }}"
|
||||
@ -252,3 +245,10 @@
|
||||
|
||||
</script>
|
||||
@endif
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
text-overflow: ellipsis;
|
||||
/* 超出用省略號顯示 */
|
||||
}
|
||||
|
||||
.table td{
|
||||
white-space: nowrap;
|
||||
|
||||
@ -32,6 +31,8 @@
|
||||
table {
|
||||
position: static !important;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@ -137,9 +138,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@php
|
||||
$pageTotal = 0;
|
||||
@endphp
|
||||
|
||||
<!-- Users List Table -->
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom">
|
||||
@ -210,16 +209,12 @@ class="rounded-circle">
|
||||
{{ $item->getPromoCode[0]->code }}
|
||||
</span>
|
||||
@endif
|
||||
@php
|
||||
$pageTotal += count($item->getPromoCode) ;
|
||||
@endphp
|
||||
@if (count($item->getPromoCode) > 1)
|
||||
<a class="text-danger" style="font-size:20px" data-bs-toggle="collapse"
|
||||
href="#multiCollapseExample-{{ $item->id }}" role="button"
|
||||
aria-expanded="false" aria-controls="multiCollapseExample1">
|
||||
{{ $item->getPromoCode[0]->code }} ({{ count($item->getPromoCode) }}
|
||||
筆)
|
||||
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@ -278,16 +273,13 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$i=1;
|
||||
$promoCodes = $item->getPromoCode()->paginate(30); // 每頁30筆優惠碼
|
||||
@endphp
|
||||
@foreach ($promoCodes as $val)
|
||||
@php $i = 1 ; @endphp
|
||||
@foreach ($item->getPromoCode as $key => $val)
|
||||
@if ($i == 1)
|
||||
<tr>
|
||||
@endif
|
||||
<td class="text-danger"> {{ $val->code }}</td>
|
||||
<td class="text-info">{{ $val->give_to }}</td>
|
||||
<td>{{ $i }} {{ $val->code }}</td>
|
||||
<td>{{ $val->give_to }}</td>
|
||||
@if ($i == 5)
|
||||
</tr>
|
||||
@php $i = 0 @endphp
|
||||
@ -295,13 +287,6 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
|
||||
@php $i++; @endphp
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<th colspan="10">
|
||||
@if($promoCodes->count()>29)
|
||||
{{ $promoCodes->links() }}
|
||||
@endif
|
||||
</th>
|
||||
</tfoot>
|
||||
</table>
|
||||
{{-- <span class="text-danger " style="font-size:20px">
|
||||
@foreach ($item->getPromoCode as $key => $val)
|
||||
@ -318,16 +303,6 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
|
||||
</tr>
|
||||
@endforeach
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
@ -361,6 +336,7 @@ class="d-grid d-sm-flex p-4 border justify-content-center table-responsive text-
|
||||
});
|
||||
|
||||
function changeLevel(id, lv) {
|
||||
|
||||
Swal.fire({
|
||||
title: "確定",
|
||||
text: "你即將修改此用戶權限!",
|
||||
@ -380,26 +356,37 @@ function changeLevel(id, lv) {
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
|
||||
success: function(response) {
|
||||
if (response.status == 'success') {
|
||||
let name = response.name;
|
||||
let view = '';
|
||||
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;
|
||||
} else if (lv == 1) {
|
||||
}
|
||||
if (lv == 1) {
|
||||
view = '<i class = "ri-user-line ri-22px text-info me-2" ></i>'+ name;
|
||||
} else if (lv == 2) {
|
||||
}
|
||||
if (lv == 2) {
|
||||
view = '<i class = "ri-user-line ri-22px text-sucess me-2" > </i>'+ name;
|
||||
} else if (lv == 9) {
|
||||
}
|
||||
if (lv == 9) {
|
||||
view = '<i class = "ri-user-line ri-22px text-warning me-2" > </i>'+ name;
|
||||
}
|
||||
$("#user-"+id).html(view);
|
||||
Swal.fire("成功", "修改成功", "success");
|
||||
}
|
||||
|
||||
|
||||
Swal.fire("成功", "修改成功", "success");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} else if (result.dismiss === Swal.DismissReason.cancel) {
|
||||
Swal.fire("取消", "使用者取消操作", "error");
|
||||
console.log("使用者取消操作");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,55 +51,26 @@
|
||||
<div class="row">
|
||||
<div class="col-xl">
|
||||
<div class="card mb-12" style="margin-bottom: 20px;">
|
||||
<h5 class="card-header">Excel 匯入</h5>
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- Tab Content -->
|
||||
<div class="tab-content mt-4" id="importTabsContent">
|
||||
|
||||
<!-- 朗立臣 (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
|
||||
|
||||
<h5 class="card-header">輸入檔案</h5>
|
||||
<div class="card-body">
|
||||
<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">
|
||||
<label for="formFile" class="form-label">檔案類型 excels</label>
|
||||
<input class="form-control" name="file" type="file" id="formFile">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">送出</button>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Send</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">
|
||||
@ -107,7 +78,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>
|
||||
@ -118,7 +89,6 @@
|
||||
<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>
|
||||
|
||||
@ -117,7 +117,7 @@
|
||||
<button class="btn btn-primary d-grid w-100" id="confirm">發送連結</button>
|
||||
</form>
|
||||
<div class="text-center">
|
||||
<a href="{{ route('login') }}" class="d-flex align-items-center justify-content-center">
|
||||
<a href="{{ route('front.login.view') }}" class="d-flex align-items-center justify-content-center">
|
||||
<i class="ri-arrow-left-s-line scaleX-n1-rtl ri-20px me-1_5"></i>
|
||||
回到登入
|
||||
</a>
|
||||
|
||||
@ -157,7 +157,7 @@
|
||||
|
||||
<p class="text-center">
|
||||
<span>已經有帳號?</span>
|
||||
<a href="{{ route('login') }}" class="text-body">
|
||||
<a href="{{ route('front.login.view') }}" class="text-body">
|
||||
<span>由此登入</span>
|
||||
</a>
|
||||
</p>
|
||||
@ -388,11 +388,6 @@ function validateEmailField(field) {
|
||||
|
||||
// 如果所有欄位均有效,執行表單提交
|
||||
if (isFormValid && isPhoneValid) {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: "{{ route('member.register.create') }}",
|
||||
type: 'POST',
|
||||
|
||||
@ -102,17 +102,15 @@ 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 id= "tea-tab" type="button" class="nav-link d-flex flex-column gap-1"
|
||||
<button 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"
|
||||
@ -159,38 +157,10 @@ 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>
|
||||
<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
|
||||
|
||||
|
||||
<p class="card-text">施工中 ....</p>
|
||||
{{-- <a href="javascript:void(0)" class="btn btn-secondary">Go somewhere</a> --}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -205,8 +175,7 @@ class="nav-link d-flex flex-column gap-1 active" role="tab"
|
||||
<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="d-flex justify-content-center" id="qrcode" style="padding-top: 3%">
|
||||
</div>
|
||||
<!-- Flexbox居中 -->
|
||||
</div>
|
||||
@ -276,130 +245,76 @@ class='ri-bar-chart-2-line ri-24px text-body me-4'></i>消費紀錄</h5>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
console.log("Document is ready");
|
||||
var id = "{{ Auth::guard('member')->user()->id }}";
|
||||
$("#promocode-show").hide();
|
||||
$("#promocode-show-teamaster").hide();
|
||||
$("#tea-give-to").hide();
|
||||
// 建立 QR Code
|
||||
$("#promocode").hide();
|
||||
// $("#promocode-show").hide();
|
||||
var qrcode = new QRCode(document.getElementById("qrcode"), {
|
||||
text: id,
|
||||
width: 250,
|
||||
height: 250
|
||||
text: id, // 要顯示的內容
|
||||
width: 250, // QR code 的寬度
|
||||
height: 250 // QR code 的高度
|
||||
});
|
||||
});
|
||||
|
||||
// 顯示資料按鈕
|
||||
$("#submit-btn").on('click', function() {
|
||||
var id = "{{ Auth::guard('member')->user()->id }}";
|
||||
$("#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 ?? '' }}";
|
||||
var give_to = "{{ $code->give_to }}";
|
||||
var code ="{{ $code->code }}";
|
||||
|
||||
console.log('code:',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();
|
||||
console.log('id:', id);
|
||||
|
||||
|
||||
});
|
||||
$("#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(res.promocode);
|
||||
},
|
||||
error: function(xhr) {
|
||||
console.log(xhr.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 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();
|
||||
$("#give-to").show();
|
||||
$("#floatingInput3").val("");
|
||||
$("#promocode-show").hide();
|
||||
console.log('id:', id);
|
||||
|
||||
});
|
||||
//給予誰
|
||||
$("#button-addon7").on('click', function() {
|
||||
|
||||
$("#button-addon3").on('click', function(event) {
|
||||
event.preventDefault(); // 阻止表单的默认提交行为
|
||||
|
||||
var id = "{{ Auth::guard('member')->user()->id }}";
|
||||
$("#promocode").show();
|
||||
$("#tea-give-to").show();
|
||||
$("#floatingInput5").val("");
|
||||
$("#promocode-show-teamaster").hide();
|
||||
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); // 顯示錯誤資訊
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
use App\Http\Controllers\LoginController;
|
||||
use App\Http\Middleware\AdminRedirect;
|
||||
use App\Http\Middleware\AdminAuth;
|
||||
use App\Http\Controllers\Admin\RegisterController;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@ -14,20 +13,14 @@
|
||||
Route::get('/phpinfo', function () {
|
||||
return phpinfo();
|
||||
});
|
||||
/** no middleware
|
||||
* ajxa 丟這
|
||||
*/
|
||||
Route::get('register', [RegisterController::class, 'index'])->name('register');
|
||||
Route::post('register/create', [RegisterController::class, 'registerCreate'])->name('register.create');
|
||||
|
||||
/**
|
||||
* has middleware admin 需登入
|
||||
*/
|
||||
Route::
|
||||
namespace('App\Http\Controllers\Admin') // 設置命名空間
|
||||
->middleware([AdminRedirect::class, AdminAuth::class])
|
||||
->group(function () {
|
||||
Route::get('/', 'IndexController@index')->name('index');
|
||||
Route::get('register', 'RegisterController@index')->name('register');
|
||||
Route::post('register/create', 'RegisterController@registerCreate')->name('register.create');
|
||||
Route::get('profile', 'IndexController@profile')->name('profile');
|
||||
Route::get('page-profile', 'IndexController@pageProfile')->name('page.profile');
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
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;
|
||||
|
||||
@ -47,6 +48,9 @@
|
||||
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']) // 使用自定义守卫的中间件
|
||||
|
||||
0
storage/app/.gitignore
vendored
Executable file → Normal file
0
storage/app/.gitignore
vendored
Executable file → Normal file
0
storage/app/public/.gitignore
vendored
Executable file → Normal file
0
storage/app/public/.gitignore
vendored
Executable file → Normal file
0
storage/framework/.gitignore
vendored
Executable file → Normal file
0
storage/framework/.gitignore
vendored
Executable file → Normal file
0
storage/framework/cache/.gitignore
vendored
Executable file → Normal file
0
storage/framework/cache/.gitignore
vendored
Executable file → Normal file
0
storage/framework/cache/data/.gitignore
vendored
Executable file → Normal file
0
storage/framework/cache/data/.gitignore
vendored
Executable file → Normal file
0
storage/framework/sessions/.gitignore
vendored
Executable file → Normal file
0
storage/framework/sessions/.gitignore
vendored
Executable file → Normal file
0
storage/framework/testing/.gitignore
vendored
Executable file → Normal file
0
storage/framework/testing/.gitignore
vendored
Executable file → Normal file
0
storage/framework/views/.gitignore
vendored
Executable file → Normal file
0
storage/framework/views/.gitignore
vendored
Executable file → Normal file
0
storage/logs/.gitignore
vendored
Executable file → Normal file
0
storage/logs/.gitignore
vendored
Executable file → Normal file
Loading…
Reference in New Issue
Block a user