first commit
This commit is contained in:
90
app/Http/Controllers/ScreeningLotteryController.php
Normal file
90
app/Http/Controllers/ScreeningLotteryController.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Requests\ScreeningLotteryRequest;
|
||||
use App\Models\ScreeningLottery;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ScreeningLotteryController extends Controller
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
return view('screeningLotteryInfo');
|
||||
}
|
||||
|
||||
public function fillForm()
|
||||
{
|
||||
return view('screeningLotteryFillForm');
|
||||
}
|
||||
|
||||
public function fillFormPost(ScreeningLotteryRequest $request)
|
||||
{
|
||||
try
|
||||
{
|
||||
DB::beginTransaction();
|
||||
$cids = $request->input('screening_lottery_catalog_id');
|
||||
foreach($cids as $cid)
|
||||
{
|
||||
$item = (new ScreeningLottery())->where('id_number','=', $request->input('id_number'));
|
||||
$item = $item->where('screening_lottery_catalog_id', '=', $cid);
|
||||
$item = $item->first();
|
||||
if ($item)
|
||||
{
|
||||
throw new \Exception('您已經登記過這個篩檢項目');
|
||||
}
|
||||
|
||||
ScreeningLottery::insert([
|
||||
'email' => $request->input('email'),
|
||||
'name' => $request->input('name'),
|
||||
'phone' => $request->input('phone'),
|
||||
'id_number' => $request->input('id_number'),
|
||||
'address' => $request->input('address'),
|
||||
'screening_lottery_catalog_id' => $cid,
|
||||
'created_at' => Carbon::now(),
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
DB::rollBack();
|
||||
return redirect()->back()->withErrors([$ex->getMessage()])->withInput(Request()->all());
|
||||
}
|
||||
return redirect()->back()->with('success', '登記成功!');
|
||||
}
|
||||
|
||||
public function regQuery()
|
||||
{
|
||||
return view('screeningLotteryRegQuery');
|
||||
}
|
||||
|
||||
public function regQueryPost(Request $request)
|
||||
{
|
||||
$items = [];
|
||||
try
|
||||
{
|
||||
$items = DB::table('screening_lotteries')->where('id_number','=', $request->input('id_number'));
|
||||
$items = $items->leftJoin('screening_lottery_catalogs', 'screening_lotteries.screening_lottery_catalog_id', '=', 'screening_lottery_catalogs.id');
|
||||
$items = $items->select(['screening_lottery_catalogs.name'])->get()->toArray();
|
||||
if (count($items) < 1)
|
||||
{
|
||||
throw new \Exception('您沒有登記過篩檢項目!');
|
||||
}
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
return redirect()->back()->withErrors([$ex->getMessage()]);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', $items);
|
||||
}
|
||||
|
||||
public function winners()
|
||||
{
|
||||
return view('screeningLotteryWinners');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user