first commit
This commit is contained in:
240
app/Http/Controllers/Admin/EventMetabolismCrudController.php
Normal file
240
app/Http/Controllers/Admin/EventMetabolismCrudController.php
Normal file
@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\EventMetabolismRequest;
|
||||
use Backpack\CRUD\app\Http\Controllers\CrudController;
|
||||
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
|
||||
|
||||
use App\Mail\EventNotifyMail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class EventMetabolismCrudController
|
||||
* @package App\Http\Controllers\Admin
|
||||
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
|
||||
*/
|
||||
class EventMetabolismCrudController extends CrudController
|
||||
{
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
|
||||
//use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
|
||||
//use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
|
||||
//use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation { update as traitUpdate; }
|
||||
|
||||
|
||||
/**
|
||||
* Configure the CrudPanel object. Apply settings to all operations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
CRUD::setModel(\App\Models\EventMetabolism::class);
|
||||
CRUD::setRoute(config('backpack.base.route_prefix') . '/event-metabolism');
|
||||
CRUD::setEntityNameStrings('活動:符合代謝新收案', '活動:符合代謝新收案');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what happens when the List operation is loaded.
|
||||
*
|
||||
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
|
||||
* @return void
|
||||
*/
|
||||
protected function setupListOperation()
|
||||
{
|
||||
$this->crud->addColumns([
|
||||
[
|
||||
'name' => 'created_at',
|
||||
'label' => '登記時間',
|
||||
'type' => 'datetime',
|
||||
'format' => 'YYYY/MM/DD HH:mm:SS'
|
||||
],
|
||||
[
|
||||
'name' => 'check_state',
|
||||
'label' => '審核狀態',
|
||||
'type' => 'select_from_array',
|
||||
'options' => ['1' => '未審核 ', '2' => '通過 〇', '3' => '未通過 ✖'],
|
||||
],
|
||||
[
|
||||
'name' => 'twid',
|
||||
'label' => '身份證',
|
||||
'type' => 'text'
|
||||
],
|
||||
[
|
||||
'name' => 'name',
|
||||
'label' => '姓名',
|
||||
'type' => 'text'
|
||||
],
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what happens when the Create operation is loaded.
|
||||
*
|
||||
* @see https://backpackforlaravel.com/docs/crud-operation-create
|
||||
* @return void
|
||||
*/
|
||||
protected function setupCreateOperation()
|
||||
{
|
||||
CRUD::setValidation(EventMetabolismRequest::class);
|
||||
$this->crud->addFields([
|
||||
[
|
||||
'name' => 'hospital_name',
|
||||
'label' => '就醫院所',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'name',
|
||||
'label' => '姓名',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'twid',
|
||||
'label' => '身份證',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'phone',
|
||||
'label' => '手機號碼',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'email',
|
||||
'label' => 'Email',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'address',
|
||||
'label' => '地址',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'name' => 'check_state',
|
||||
'label' => "審核狀態",
|
||||
'type' => 'select_from_array',
|
||||
'options' => ['1' => '未審核 ', '2' => '通過 〇', '3' => '未通過 ✖'],
|
||||
'allows_null' => false,
|
||||
'default' => '1',
|
||||
],
|
||||
[
|
||||
'name' => 'check_reson',
|
||||
'label' => "審核回應(未通過原因)",
|
||||
'type' => 'text',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what happens when the Update operation is loaded.
|
||||
*
|
||||
* @see https://backpackforlaravel.com/docs/crud-operation-update
|
||||
* @return void
|
||||
*/
|
||||
protected function setupUpdateOperation()
|
||||
{
|
||||
$this->setupCreateOperation();
|
||||
|
||||
CRUD::iframe('record_card_img_src', '記錄小卡', [
|
||||
'url' => function ($crud) {
|
||||
$entry = $crud->getCurrentEntry();
|
||||
$path = str_replace("uploads/", "", $entry->record_card_img_src);
|
||||
return $path ? route('storage.serve', $path) : "about:blank";
|
||||
},
|
||||
'width' => '400px',
|
||||
'height' => '300px',
|
||||
'extra_attributes' => [
|
||||
'sandbox' => 'allow-same-origin allow-scripts allow-popups', // Security: Restrict iframe
|
||||
'allow' => 'fullscreen',
|
||||
],
|
||||
'hint' => '',
|
||||
]);
|
||||
|
||||
CRUD::iframe('twid_front_img_src', '身份證正面', [
|
||||
'url' => function ($crud) {
|
||||
$entry = $crud->getCurrentEntry();
|
||||
$path = str_replace("uploads/", "", $entry->twid_front_img_src);
|
||||
return $path ? route('storage.serve', $path) : "about:blank";
|
||||
},
|
||||
'width' => '400px',
|
||||
'height' => '300px',
|
||||
'extra_attributes' => [
|
||||
'sandbox' => 'allow-same-origin allow-scripts allow-popups', // Security: Restrict iframe
|
||||
'allow' => 'fullscreen',
|
||||
],
|
||||
'hint' => '',
|
||||
]);
|
||||
|
||||
CRUD::iframe('twid_back_img_src', '身份證反面', [
|
||||
'url' => function ($crud) {
|
||||
$entry = $crud->getCurrentEntry();
|
||||
$path = str_replace("uploads/", "", $entry->twid_back_img_src);
|
||||
return $path ? route('storage.serve', $path) : "about:blank";
|
||||
},
|
||||
'width' => '400px',
|
||||
'height' => '300px',
|
||||
'extra_attributes' => [
|
||||
'sandbox' => 'allow-same-origin allow-scripts allow-popups', // Security: Restrict iframe
|
||||
'allow' => 'fullscreen',
|
||||
],
|
||||
'hint' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$entry = $this->crud->getCurrentEntry();
|
||||
$org_check_state = $entry->check_state;
|
||||
|
||||
// do something before validation, before save, before everything
|
||||
$response = $this->traitUpdate();
|
||||
// do something after save
|
||||
$entry = $this->crud->getCurrentEntry();
|
||||
if ($entry->check_state != $org_check_state) {
|
||||
switch($entry->check_state) {
|
||||
case '2': //過通
|
||||
try {
|
||||
Mail::to($entry->email)->send(new EventNotifyMail([
|
||||
"title" => "符合代謝新收案 早鳥報名最划算 審核通過!",
|
||||
"body" => "恭喜您審核通過!"
|
||||
."\n\n登記資料:"
|
||||
."\n就醫院所:".$entry->hospital_name
|
||||
."\n姓名:".$entry->name
|
||||
."\n身份證字號:".substr($entry->twid,0,2)."xxxx".substr($entry->twid,-4)
|
||||
."\n行動電話:".$entry->phone
|
||||
."\n電子信箱:".$entry->email
|
||||
."\n收件地址:".$entry->address
|
||||
,
|
||||
]));
|
||||
} catch (Exception $ex) {
|
||||
|
||||
}
|
||||
break;
|
||||
case '3': //未通過
|
||||
try {
|
||||
Mail::to($entry->email)->send(new EventNotifyMail([
|
||||
"title" => "符合代謝新收案 早鳥報名最划算 未通過審核!",
|
||||
"body" => "抱歉,您的審核未通過!"
|
||||
."\n請依以下理由重新上活動網站登記"
|
||||
."\n理由:".$entry->check_reson
|
||||
."\n\n登記資料:"
|
||||
."\n就醫院所:".$entry->hospital_name
|
||||
."\n姓名:".$entry->name
|
||||
."\n身份證字號:".substr($entry->twid,0,2)."xxxx".substr($entry->twid,-4)
|
||||
."\n行動電話:".$entry->phone
|
||||
."\n電子信箱:".$entry->email
|
||||
."\n收件地址:".$entry->address
|
||||
,
|
||||
]));
|
||||
} catch (Exception $ex) {
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user