cafeg/app/Http/Controllers/front/PromoCodeController.php
2025-01-20 16:42:05 +08:00

82 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers\front;
use App\Http\Controllers\Controller;
use App\Models\Promocode;
use Auth;
use Illuminate\Http\Request;
class PromoCodeController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$user_id = Auth::guard('member')->user()->id;
$count = Promocode::where('used_count', $user_id)->count();
if (! $count) {
$row = Promocode::where('used_count', 0)->first();
$row->used_count = $user_id;
$row->save();
return response()->json(['status' => 'success', 'msg' => '已成功取得', 'promocode' => $row->code]);
} else {
$code = Promocode::where('used_count', $user_id)->first();
return response()->json(['status' => 'success', 'msg' => '你已取得過優惠碼', 'promocode' => $code->code]);
}
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(Promocode $promocode)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Promocode $promocode)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Promocode $promocode)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Promocode $promocode)
{
//
}
}