372 lines
15 KiB
PHP
372 lines
15 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Http\Requests\EventHealthAllowanceRequest;
|
||
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 EventHealthAllowanceCrudController
|
||
* @package App\Http\Controllers\Admin
|
||
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
|
||
*/
|
||
class EventHealthAllowanceCrudController 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; }
|
||
use \RedSquirrelStudio\LaravelBackpackExportOperation\ExportOperation;
|
||
|
||
|
||
/**
|
||
* Configure the CrudPanel object. Apply settings to all operations.
|
||
*
|
||
* @return void
|
||
*/
|
||
public function setup()
|
||
{
|
||
CRUD::setModel(\App\Models\EventHealthAllowance::class);
|
||
CRUD::setRoute(config('backpack.base.route_prefix') . '/event-health-allowance');
|
||
CRUD::setEntityNameStrings('活動:反轉代謝新人生', '活動:反轉代謝新人生');
|
||
}
|
||
|
||
protected function setupExportOperation()
|
||
{
|
||
CRUD::addColumns([
|
||
[
|
||
'name' => 'id',
|
||
'label' => 'ID',
|
||
'type' => 'text',
|
||
'prefix' => 'A-'
|
||
],
|
||
[
|
||
'name' => 'check_state',
|
||
'label' => '審核狀態',
|
||
'type' => 'select_from_array',
|
||
'options' => ['1' => '未審核 ', '2' => '通過 〇', '3' => '未通過 ✖', '4' => '重覆資料(僅標記)'],
|
||
],
|
||
[
|
||
'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' => 'textarea',
|
||
],
|
||
]);
|
||
|
||
$this->setupListOperation();
|
||
$this->disableUserConfiguration();
|
||
}
|
||
|
||
/**
|
||
* Define what happens when the List operation is loaded.
|
||
*
|
||
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
|
||
* @return void
|
||
*/
|
||
protected function setupListOperation()
|
||
{
|
||
CRUD::filter('審核狀態')
|
||
->type('dropdown')
|
||
->values([
|
||
1 => '未審核',
|
||
2 => '通過 〇',
|
||
3 => '未通過 ✖'
|
||
|
||
])
|
||
->whenActive(function($value) {
|
||
CRUD::addClause('where', 'check_state', $value);
|
||
});
|
||
CRUD::filter('ID')
|
||
->type('text')
|
||
->whenActive(function($value) {
|
||
CRUD::addClause('where', 'id', $value);
|
||
});
|
||
CRUD::filter('就醫院所')
|
||
->type('text')
|
||
->whenActive(function($value) {
|
||
CRUD::addClause('where', 'hospital_name', 'LIKE', "%$value%");
|
||
});
|
||
CRUD::filter('姓名')
|
||
->type('text')
|
||
->whenActive(function($value) {
|
||
CRUD::addClause('where', 'name', 'LIKE', "%$value%");
|
||
});
|
||
|
||
$this->crud->addColumns([
|
||
[
|
||
'name' => 'id',
|
||
'label' => '報名流水號',
|
||
'type' => 'text',
|
||
'value' => function($entry) {
|
||
return 'C-'. str_pad($entry->id, 6, '0', STR_PAD_LEFT);
|
||
}
|
||
],
|
||
[
|
||
'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' => '未通過 ✖', '4' => '重覆資料(僅標記)'],
|
||
],
|
||
[
|
||
'name' => 'twid',
|
||
'label' => '身份證',
|
||
'type' => 'text'
|
||
],
|
||
[
|
||
'name' => 'name',
|
||
'label' => '姓名',
|
||
'type' => 'text'
|
||
],
|
||
[
|
||
'name' => 'hospital_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(EventHealthAllowanceRequest::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' => '未通過 ✖', '4' => '重覆資料(僅標記)'],
|
||
'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) : "";
|
||
},
|
||
'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) : "";
|
||
},
|
||
'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) : "";
|
||
},
|
||
'width' => '400px',
|
||
'height' => '300px',
|
||
'extra_attributes' => [
|
||
'sandbox' => 'allow-same-origin allow-scripts allow-popups', // Security: Restrict iframe
|
||
'allow' => 'fullscreen',
|
||
],
|
||
'hint' => '',
|
||
]);
|
||
|
||
CRUD::iframe('exam_1st_img_src', '檢驗檢查報告1', [
|
||
'url' => function ($crud) {
|
||
$entry = $crud->getCurrentEntry();
|
||
$path = str_replace("uploads/", "", $entry->exam_1st_img_src);
|
||
return $path ? route('storage.serve', $path) : "";
|
||
},
|
||
'width' => '400px',
|
||
'height' => '300px',
|
||
'extra_attributes' => [
|
||
'sandbox' => 'allow-same-origin allow-scripts allow-popups', // Security: Restrict iframe
|
||
'allow' => 'fullscreen',
|
||
],
|
||
'hint' => '',
|
||
]);
|
||
|
||
CRUD::iframe('exam_2nd_img_src', '檢驗檢查報告2', [
|
||
'url' => function ($crud) {
|
||
$entry = $crud->getCurrentEntry();
|
||
$path = str_replace("uploads/", "", $entry->exam_2nd_img_src);
|
||
return $path ? route('storage.serve', $path) : "";
|
||
},
|
||
'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(
|
||
'桃園市政府衛生局114年桃園市健康管理計畫「翻轉代謝新人生,皮蛇疫苗加碼補」審核通過信件。',
|
||
[
|
||
"title" => "翻轉代謝新人生,皮蛇疫苗加碼補 審核通過!",
|
||
"body" => "一、登記資料:"
|
||
."\n流水號: A-".str_pad($entry->id, 6, '0', STR_PAD_LEFT)
|
||
."\n就醫院所:".$entry->hospital_name
|
||
."\n姓名:".(mb_strlen($entry->name) > 2 ? mb_substr($entry->name,0,1)."*".mb_substr($entry->name,-1) : mb_substr($entry->name,0,1)."*")
|
||
."\n身份證字號:".substr($entry->twid,0,2)."****".substr($entry->twid,-4)
|
||
."\n電話號碼:".substr($entry->phone,0,2)."****".substr($entry->phone,-4)
|
||
."\n\n二、補助通知:"
|
||
."\n感謝您參與「114年桃園市健康管理計畫-翻轉代謝新人生 皮蛇疫苗加碼補」。"
|
||
."\n請至本局指定醫療院所完成疫苗接種,並備妥以下資料申請經費補助:"
|
||
."\n1.活動審核通過通知信"
|
||
."\n2.帶狀皰疹疫苗接種收據或紀錄"
|
||
."\n3.本人帳戶影本(如非臺灣銀行帳戶,將扣除30元匯費)"
|
||
."\n4.切結書"
|
||
."\n\n三、為確保資源分配公平,提醒您「翻轉代謝新人生 皮蛇疫苗加碼補」活動與「114年桃園市帶狀疱疹疫苗接種補助計畫」不可重複申請,應擇一參加。如經查證您已參加「114年桃園市帶狀疱疹疫苗接種補助計畫」,本活動所接受之經費補助將不予補助,並需退還已補助之費用5,000元。"
|
||
."\n\n四、備妥以上資料於114年12月5日前以掛號方式寄至桃園市政府衛生局健康促進科(桃園市桃園區縣府路55號),信封註明114年桃園市健康管理計畫帶狀疱疹疫苗補助。"
|
||
."\n\n敬請配合,以利後續作業。"
|
||
,
|
||
]));
|
||
|
||
} catch (Exception $ex) {
|
||
|
||
}
|
||
break;
|
||
case '3': //未通過
|
||
try {
|
||
Mail::to($entry->email)->send(new EventNotifyMail(
|
||
'桃園市政府衛生局114年桃園市健康管理計畫「翻轉代謝新人生,皮蛇疫苗加碼補」審核未通過信件。',
|
||
[
|
||
"title" => "翻轉代謝新人生,皮蛇疫苗加碼補 審核未通過!",
|
||
"body" => "抱歉,您的審核未通過!請依以下理由重新上活動網站登記。"
|
||
."\n理由:".$entry->check_reson
|
||
."\n\n登記資料:"
|
||
."\n流水號: A-".str_pad($entry->id, 6, '0', STR_PAD_LEFT)
|
||
."\n就醫院所:".$entry->hospital_name
|
||
."\n姓名:".(mb_strlen($entry->name) > 2 ? mb_substr($entry->name,0,1)."*".mb_substr($entry->name,-1) : mb_substr($entry->name,0,1)."*")
|
||
."\n身份證字號:".substr($entry->twid,0,2)."****".substr($entry->twid,-4)
|
||
."\n電話號碼:".substr($entry->phone,0,2)."****".substr($entry->phone,-4)
|
||
,
|
||
]));
|
||
} catch (Exception $ex) {
|
||
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
return $response;
|
||
}
|
||
}
|