浏览代码

定期選考 全般

master
sosuke.iwabuchi 2 年前
父节点
当前提交
6a87b0b8a9
共有 27 个文件被更改,包括 778 次插入23 次删除
  1. +4
    -8
      app/Console/Commands/RouteListCsv.php
  2. +1
    -1
      app/Console/Commands/SeasonTikcetContractSelectionFillCandidates.php
  3. +94
    -0
      app/Console/Commands/SeasonTikcetContractSelectionSetResult.php
  4. +2
    -0
      app/Console/Kernel.php
  5. +17
    -0
      app/Console/Schedules/SeasonTikcetContractSelectionFillCandidates.php
  6. +17
    -0
      app/Console/Schedules/SeasonTikcetContractSelectionSetResult.php
  7. +13
    -5
      app/Email/BaseEmailer.php
  8. +45
    -0
      app/Email/Members/SelectionNotice.php
  9. +41
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Entry/CancelController.php
  10. +20
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Entry/CancelParams.php
  11. +42
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Entry/EntryInfoController.php
  12. +20
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Entry/EntryInfoParams.php
  13. +53
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Selection/EntryController.php
  14. +28
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Selection/EntryParams.php
  15. +37
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Selection/NoticeToCandidatesController.php
  16. +18
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Selection/NoticeToCandidatesParams.php
  17. +49
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Selection/SelectionInfoController.php
  18. +22
    -0
      app/Http/Controllers/Web/SeasonTicketContract/Selection/SelectionInfoParams.php
  19. +15
    -2
      app/Jobs/BaseJob.php
  20. +38
    -0
      app/Jobs/SeasonTicketContract/Selection/NoticeToCandidates.php
  21. +62
    -0
      app/Jobs/SeasonTicketContract/Selection/SetResult.php
  22. +1
    -0
      app/Kintone/Models/DropDown/SeasonTicketContractEntry/Status.php
  23. +11
    -0
      app/Kintone/Models/SeasonTicketContractEntry.php
  24. +51
    -0
      app/Logic/SeasonTicketContractEntryManager.php
  25. +42
    -5
      app/Logic/SeasonTicketContractSelectionManager.php
  26. +2
    -2
      app/Providers/RouteServiceProvider.php
  27. +33
    -0
      app/Rules/SimpleRegEx.php

+ 4
- 8
app/Console/Commands/RouteListCsv.php 查看文件

@@ -103,11 +103,8 @@ class RouteListCsv extends BaseCommand
"説明",
"メソッド",
"URI",
"S",
"C",
"A",
"L",
"N",
"NONE",
"NORMAL",
"コントローラー",
], $this->separator);
}
@@ -127,9 +124,8 @@ class RouteListCsv extends BaseCommand
$this->getControllerDescription($controller),
$this->getMethods($route),
$route->uri(),
$this->getRoleAuth($controller, UserRole::NORMAL_ADMIN),
$this->getRoleAuth($controller, UserRole::CONTRACT_ADMIN),
$this->getRoleAuth($controller, UserRole::SUPER_ADMIN),
$this->getRoleAuth($controller, UserRole::NONE),
$this->getRoleAuth($controller, UserRole::NORMAL),
$controller::class,
], $this->separator);



+ 1
- 1
app/Console/Commands/SeasonTikcetContractSelectionFillCandidates.php 查看文件

@@ -55,7 +55,7 @@ class SeasonTikcetContractSelectionFillCandidates extends BaseCommand
$db = DBUtil::instance();
$db->beginTransaction();

$this->getName();
$targets = $this->getTargets();

$this->outputInfo(sprintf("取得対象 %d件", $targets->count()));


+ 94
- 0
app/Console/Commands/SeasonTikcetContractSelectionSetResult.php 查看文件

@@ -0,0 +1,94 @@
<?php

namespace App\Console\Commands;

use App\Jobs\SeasonTicketContract\Selection\SetResult;
use App\Kintone\KintoneRecordQueryOperator;
use App\Kintone\Models\DropDown\SeasonTicketContractSelection\SelectionStatus;
use App\Kintone\Models\SeasonTicketContractSelection;
use App\Util\DateUtil;
use App\Util\DBUtil;
use Exception;

class SeasonTikcetContractSelectionSetResult extends BaseCommand
{

const COMMAND = "season-ticket-contract-selection:set-result";


/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = self::COMMAND;

/**
* The console command description.
*
* @var string
*/
protected $description = '定期選考の選考者設定のジョブを登録する';

static public function getCommand()
{
return self::COMMAND;
}

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->managers = collect();
}

/**
* Execute the console command.
*
* @return int
*/
public function service(): int
{
try {
$db = DBUtil::instance();
$db->beginTransaction();


$targets = $this->getTargets();

$this->outputInfo(sprintf("取得対象 %d件", $targets->count()));

// データハンドリング
foreach ($targets as $data) {
$this->handleData($data);
}

$db->commit();
} catch (Exception $e) {
$db->rollBack();
throw $e;
}

return self::RESULTCODE_SUCCESS;
}

private function getTargets()
{
$today = DateUtil::now();
$access = SeasonTicketContractSelection::getAccess();
$query = SeasonTicketContractSelection::getQuery()
->whereIn(SeasonTicketContractSelection::FIELD_STATUS, [SelectionStatus::ENTRY_ACCEPTING])
->whereDate(SeasonTicketContractSelection::FIELD_SELECTION_FINAL_DATE, $today, KintoneRecordQueryOperator::LT);
return $access->all($query);
}


private function handleData(SeasonTicketContractSelection $data)
{
SetResult::dispatch($data->getRecordId());
}
}

+ 2
- 0
app/Console/Kernel.php 查看文件

@@ -15,6 +15,8 @@ class Kernel extends ConsoleKernel
Schedules\HeartBeat::register($schedule);
Schedules\SMBCPoll::register($schedule);
Schedules\BankAccountRegisterRemaind::register($schedule);
Schedules\SeasonTikcetContractSelectionFillCandidates::register($schedule);
Schedules\SeasonTikcetContractSelectionSetResult::register($schedule);
}

/**


+ 17
- 0
app/Console/Schedules/SeasonTikcetContractSelectionFillCandidates.php 查看文件

@@ -0,0 +1,17 @@
<?php

namespace App\Console\Schedules;

use App\Console\Commands\SeasonTikcetContractSelectionFillCandidates as Command;
use Illuminate\Console\Scheduling\Schedule;

class SeasonTikcetContractSelectionFillCandidates extends BaseSchedule
{

static public function register(Schedule $schedule)
{
$schedule->command(Command::class)
->everyFiveMinutes()
->description("定期選考申込者一覧設定");
}
}

+ 17
- 0
app/Console/Schedules/SeasonTikcetContractSelectionSetResult.php 查看文件

@@ -0,0 +1,17 @@
<?php

namespace App\Console\Schedules;

use App\Console\Commands\SeasonTikcetContractSelectionSetResult as Command;
use Illuminate\Console\Scheduling\Schedule;

class SeasonTikcetContractSelectionSetResult extends BaseSchedule
{

static public function register(Schedule $schedule)
{
$schedule->command(Command::class)
->at("00:05")
->description("定期選考結果設定");
}
}

+ 13
- 5
app/Email/BaseEmailer.php 查看文件

@@ -178,7 +178,7 @@ abstract class BaseEmailer extends Mailable
* @param array|string $path
* @return string
*/
protected function getAppUrl(array|string $path): string
protected function getAppUrl(array|string $path, array $query = []): string
{
$elements = [config("app.url")];
if (is_array($path)) {
@@ -187,9 +187,17 @@ abstract class BaseEmailer extends Mailable
$elements[] = $path;
}

return implode(
"/",
$elements,
);
$url = implode("/", $elements);

if (!!$query) {
$url .= "?";
$queryStrList = [];
foreach ($query as $key => $value) {
$queryStrList[] = sprintf("%s=%s", $key, $value);
}
$url .= implode("&", $queryStrList);
}

return $url;
}
}

+ 45
- 0
app/Email/Members/SelectionNotice.php 查看文件

@@ -0,0 +1,45 @@
<?php

namespace App\Email\Members;

use App\Kintone\Models\SeasonTicketContractEntry;
use App\Kintone\Models\SeasonTicketContractSelection;
use App\Logic\SeasonTicketContractSelectionManager;

class SelectionNotice extends Members
{

public function __construct(
private SeasonTicketContractSelection $selection,
private SeasonTicketContractEntry $entry,
) {
parent::__construct(null);
}

public function getTemplateName(): string
{
return 'emails.members.selection_notice';
}

public function getSubject(): string
{
return "##TODO## 選考通知";
}

public function getMemberParams(): array
{
$manager = new SeasonTicketContractSelectionManager($this->selection);

return [
'customer_name' => $this->entry->customerName,
'parking_name' => $this->entry->parkingName,
'url' => $this->getAppUrl([
'season-ticket-contract',
'selection', 'entry',
$this->selection->getRecordId(),
$this->entry->getRecordId(),
$manager->getHash($this->entry->getRecordId())
]),
];
}
}

+ 41
- 0
app/Http/Controllers/Web/SeasonTicketContract/Entry/CancelController.php 查看文件

@@ -0,0 +1,41 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Entry;

use App\Http\Controllers\Web\WebController;
use App\Logic\SeasonTicketContractEntryManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class EntryInfoController extends WebController
{
public function name(): string
{
return "申込キャンセル";
}

public function description(): string
{
return "申込をキャンセルする";
}

public function __construct(protected CancelParams $param)
{
parent::__construct();
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

$manager = new SeasonTicketContractEntryManager($param->recordNo);

if (!$manager->checkHash($param->fs)) {
return $this->failedResponse();
}

$entry = $manager->getEntry();

return $this->successResponse($entry->toArray());
}
}

+ 20
- 0
app/Http/Controllers/Web/SeasonTicketContract/Entry/CancelParams.php 查看文件

@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Entry;

use App\Http\Controllers\Web\BaseParam;

/**
* @property int $recordNo
* @property string $fs
*/
class CancelParams extends BaseParam
{
public function rules(): array
{
return [
'record_no' => $this->numeric(),
'fs' => $this->str(),
];
}
}

+ 42
- 0
app/Http/Controllers/Web/SeasonTicketContract/Entry/EntryInfoController.php 查看文件

@@ -0,0 +1,42 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Entry;

use App\Http\Controllers\Web\WebController;
use App\Logic\SeasonTicketContractEntryManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CancelController extends WebController
{

public function name(): string
{
return "申込内容取得";
}

public function description(): string
{
return "申込内容を取得する";
}

public function __construct(protected EntryInfoParams $param)
{
parent::__construct();
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

$manager = new SeasonTicketContractEntryManager($param->recordNo);

if (!$manager->checkHash($param->fs)) {
return $this->failedResponse();
}

$entry = $manager->getEntry();

return $this->successResponse($entry->toArray());
}
}

+ 20
- 0
app/Http/Controllers/Web/SeasonTicketContract/Entry/EntryInfoParams.php 查看文件

@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Entry;

use App\Http\Controllers\Web\BaseParam;

/**
* @property int $recordNo
* @property string $fs
*/
class EntryInfoParams extends BaseParam
{
public function rules(): array
{
return [
'record_no' => $this->numeric(),
'fs' => $this->str(),
];
}
}

+ 53
- 0
app/Http/Controllers/Web/SeasonTicketContract/Selection/EntryController.php 查看文件

@@ -0,0 +1,53 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Selection;

use App\Http\Controllers\Web\WebController;
use App\Logic\SeasonTicketContractEntryManager;
use App\Logic\SeasonTicketContractSelectionManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class EntryController extends WebController
{

public function name(): string
{
return "定期選考申込";
}

public function description(): string
{
return "定期選考に申込する";
}


public function __construct(protected EntryParams $param)
{
parent::__construct();
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

$manager = new SeasonTicketContractSelectionManager($param->selectionRecordNo);

if (!$manager->checkHash($param->entryRecordNo, $param->fs)) {
return $this->failedResponse();
}

$manager->entry($param->entryRecordNo, $param->fs);

$entryManager = new SeasonTicketContractEntryManager($param->entryRecordNo);

$entry = $entryManager->getEntry();
$entry->address = $param->address;
$entry->phoneNo = $param->phoneNo;

$entryManager->save();
$manager->save();

return $this->successResponse();
}
}

+ 28
- 0
app/Http/Controllers/Web/SeasonTicketContract/Selection/EntryParams.php 查看文件

@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Selection;

use App\Http\Controllers\Web\BaseParam;
use App\Rules\PhoneNumber;
use App\Rules\SimpleRegEx;

/**
* @property int selectionRecordNo
* @property int entryRecordNo
* @property string fs
* @property string address
* @property string phoneNo
*/
class EntryParams extends BaseParam
{
public function rules(): array
{
return [
'selection_record_no' => $this->numeric(),
'entry_record_no' => $this->numeric(),
'fs' => $this->str(),
'address' => $this->str(),
'phone_no' => $this->str([new SimpleRegEx("/[^0-9-]+/", "不正な文字が含まれています", true)]),
];
}
}

+ 37
- 0
app/Http/Controllers/Web/SeasonTicketContract/Selection/NoticeToCandidatesController.php 查看文件

@@ -0,0 +1,37 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Selection;

use App\Http\Controllers\Web\FromKintoneController;
use App\Jobs\SeasonTicketContract\Selection\NoticeToCandidates;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class NoticeToCandidatesController extends FromKintoneController
{

public function name(): string
{
return "定期選考メール一斉通知依頼";
}

public function description(): string
{
return "定期選考メール一斉通知を依頼する";
}


public function __construct(protected NoticeToCandidatesParams $param)
{
parent::__construct();
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

NoticeToCandidates::dispatch($param->recordNo)->delay(5);

return $this->successResponse();
}
}

+ 18
- 0
app/Http/Controllers/Web/SeasonTicketContract/Selection/NoticeToCandidatesParams.php 查看文件

@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Selection;

use App\Http\Controllers\Web\BaseParam;

/**
* @property int $recordNo
*/
class NoticeToCandidatesParams extends BaseParam
{
public function rules(): array
{
return [
'record_no' => $this->numeric(),
];
}
}

+ 49
- 0
app/Http/Controllers/Web/SeasonTicketContract/Selection/SelectionInfoController.php 查看文件

@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Selection;

use App\Exceptions\GeneralErrorMessageException;
use App\Http\Controllers\Web\WebController;
use App\Kintone\Models\DropDown\SeasonTicketContractSelection\SelectionStatus;
use App\Logic\SeasonTicketContractSelectionManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class SelectionInfoController extends WebController
{

public function name(): string
{
return "申込内容取得";
}

public function description(): string
{
return "申込内容を取得する";
}


public function __construct(protected SelectionInfoParams $param)
{
parent::__construct();
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

$manager = new SeasonTicketContractSelectionManager($param->selectionRecordNo);

if (!$manager->checkHash($param->entryRecordNo, $param->fs)) {
return $this->failedResponse();
}

if ($manager->getSelection()->status !== SelectionStatus::ENTRY_ACCEPTING) {
throw new GeneralErrorMessageException("募集期間が終了しています");
}

$entry = $manager->getEntry($param->entryRecordNo);

return $this->successResponse($entry->toArray());
}
}

+ 22
- 0
app/Http/Controllers/Web/SeasonTicketContract/Selection/SelectionInfoParams.php 查看文件

@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\Web\SeasonTicketContract\Selection;

use App\Http\Controllers\Web\BaseParam;

/**
* @property int selectionRecordNo
* @property int entryRecordNo
* @property string fs
*/
class SelectionInfoParams extends BaseParam
{
public function rules(): array
{
return [
'selection_record_no' => $this->numeric(),
'entry_record_no' => $this->numeric(),
'fs' => $this->str(),
];
}
}

+ 15
- 2
app/Jobs/BaseJob.php 查看文件

@@ -2,6 +2,7 @@

namespace App\Jobs;

use App\Util\DBUtil;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@@ -13,10 +14,22 @@ abstract class BaseJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected DBUtil $db;

public function handle()
{
$this->logConfig();
$this->handleJob();
$this->db = DBUtil::instance();
try {
$this->db->beginTransaction();

$this->logConfig();
$this->handleJob();

$this->db->commit();
} catch (Exception $e) {
$this->db->rollBack();
throw $e;
}
}

/**


+ 38
- 0
app/Jobs/SeasonTicketContract/Selection/NoticeToCandidates.php 查看文件

@@ -0,0 +1,38 @@
<?php

namespace App\Jobs\SeasonTicketContract\Selection;

use App\Codes\QueueName;
use App\Jobs\BaseJob;
use App\Logic\SeasonTicketContractSelectionManager;
use App\Util\LoggingUtil;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class NoticeToCandidates extends BaseJob
{

/**
* Create a new job instance.
*
* @return void
*/
public function __construct(
private int $recordNo
) {
$this->onQueue(QueueName::JOB->value);
}

protected function handleJob()
{
try {
$manager = new SeasonTicketContractSelectionManager($this->recordNo);
$manager->sendNotice()
->save();
} catch (ModelNotFoundException $e) {
LoggingUtil::errorException($e, sprintf("データ存在なし削除 %s", self::class));
} catch (Exception $e) {
LoggingUtil::errorException($e, sprintf("ジョブ失敗->削除 %s", self::class));
}
}
}

+ 62
- 0
app/Jobs/SeasonTicketContract/Selection/SetResult.php 查看文件

@@ -0,0 +1,62 @@
<?php

namespace App\Jobs\SeasonTicketContract\Selection;

use App\Codes\QueueName;
use App\Jobs\BaseJob;
use App\Kintone\Models\DropDown\SeasonTicketContractSelection\SelectionStatus;
use App\Logic\SeasonTicketContractSelectionManager;
use App\Util\LoggingUtil;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class SetResult extends BaseJob
{

/**
* Create a new job instance.
*
* @return void
*/
public function __construct(
private int $recordNo
) {
$this->onQueue(QueueName::JOB->value);
}

protected function handleJob()
{
try {
$manager = new SeasonTicketContractSelectionManager($this->recordNo);
$manager->makeResult()
->save();

$selection = $manager->getSelection();

// 以下ログ出力処理
if ($selection->status === SelectionStatus::RESULT_DECISION) {
foreach ($selection->resultList as $result) {
info(sprintf(
"選考結果設定 駐車場:%s 選考レコード番号:%d 締日:%s 氏名:%s 申込番号:%s",
$selection->parkingName,
$selection->getRecordId(),
$selection->selectionFinalDate ? $selection->selectionFinalDate->format('Y/m/d') : "-",
$result->name,
$result->entryNo,
));
}
} else if ($selection->status === SelectionStatus::FAILED) {
info(sprintf(
"選考不調 駐車場:%s 選考レコード番号:%d 締日:%s",
$selection->parkingName,
$selection->getRecordId(),
$selection->selectionFinalDate ? $selection->selectionFinalDate->format('Y/m/d') : "-",
));
}
} catch (ModelNotFoundException $e) {
LoggingUtil::errorException($e, sprintf("データ存在なし削除 %s", self::class));
} catch (Exception $e) {
LoggingUtil::errorException($e, sprintf("ジョブ失敗->削除 %s", self::class));
}
}
}

+ 1
- 0
app/Kintone/Models/DropDown/SeasonTicketContractEntry/Status.php 查看文件

@@ -6,4 +6,5 @@ abstract class Status
{
const RESERVE = "予約";
const WAIT_EMPTY = "空き待ち";
const CANCEL = "キャンセル";
}

+ 11
- 0
app/Kintone/Models/SeasonTicketContractEntry.php 查看文件

@@ -18,6 +18,7 @@ use Illuminate\Support\Carbon;
* @property int carAmount
* @property string paymentMethod
* @property Carbon entryDatetime
* @property string planName
*/
class SeasonTicketContractEntry extends KintoneModel
{
@@ -35,6 +36,7 @@ class SeasonTicketContractEntry extends KintoneModel
const FIELD_CAR_AMOUNT = "台数";
const FIELD_PAYMENT_METHOD = "支払方法";
const FIELD_ENTRY_DATETIME = "受付日時";
const FIELD_PLAN_NAME = "ParkingNaviプラン";

protected const FIELDS = [
...parent::FIELDS,
@@ -48,12 +50,21 @@ class SeasonTicketContractEntry extends KintoneModel
self::FIELD_VEHICLE_NO => FieldType::SINGLE_LINE_TEXT,
self::FIELD_PAYMENT_METHOD => FieldType::DROP_DOWN,
self::FIELD_ENTRY_DATETIME => FieldType::DATETIME,
self::FIELD_PLAN_NAME => FieldType::SINGLE_LINE_TEXT,
];

protected const FIELD_NAMES = [
...parent::FIELD_NAMES,
self::FIELD_PARKING_NAME => 'parking_name',
self::FIELD_CUSTOMER_NAME => 'customer_name',
self::FIELD_PLAN_NAME => 'plan_name',
self::FIELD_ENTRY_DATETIME => 'entry_datetime',
self::FIELD_PHONE_NO => 'phone_no',
self::FIELD_ADDRESS => 'address',
self::FIELD_CAR_AMOUNT => 'car_amount',
];


public function getParking(): Parking
{
return Parking::findByParkingName($this->parkingName);


+ 51
- 0
app/Logic/SeasonTicketContractEntryManager.php 查看文件

@@ -0,0 +1,51 @@
<?php

namespace App\Logic;

use App\Kintone\Models\DropDown\SeasonTicketContractEntry\Status;
use App\Kintone\Models\SeasonTicketContractEntry;

class SeasonTicketContractEntryManager
{
private SeasonTicketContractEntry $entry;

public function __construct(int|SeasonTicketContractEntry $recordNo = null)
{
if (is_int($recordNo)) {
$this->entry = SeasonTicketContractEntry::find($recordNo);
return;
} else if ($recordNo instanceof SeasonTicketContractEntry) {
$this->entry = $recordNo;
return;
}
}

public function getEntry()
{
return $this->entry;
}

public function cancel()
{
$this->entry->status = Status::CANCEL;
return $this;
}

public function save()
{
$this->entry->save();
return $this;
}

public function getHash()
{
$source = sprintf("%010d-%s", $this->entry->getRecordId(), $this->entry->entryDatetime->format("YmdHi"));
return hash('sha256', $source);
}

public function checkHash(string $hash): bool
{
$expect = $this->getHash();
return $expect === $hash;
}
}

+ 42
- 5
app/Logic/SeasonTicketContractSelectionManager.php 查看文件

@@ -2,7 +2,9 @@

namespace App\Logic;

use App\Email\Members\SelectionNotice;
use App\Exceptions\AppCommonException;
use App\Exceptions\GeneralErrorMessageException;
use App\Kintone\KintoneRecordQuery;
use App\Kintone\KintoneRecordQueryOperator;
use App\Kintone\Models\DropDown\SeasonTicketContractEntry\Status;
@@ -10,6 +12,7 @@ use App\Kintone\Models\SeasonTicketContractEntry as EntryModel;
use App\Kintone\Models\SeasonTicketContractSelection as SelectionModel;
use App\Kintone\Models\SubTable\SeasonTicketContractSelection\Entry;
use App\Kintone\Models\DropDown\SeasonTicketContractSelection\SelectionStatus;
use App\Kintone\Models\SeasonTicketContractEntry;
use App\Kintone\Models\SubTable\SeasonTicketContractSelection\Candidate;
use App\Kintone\Models\SubTable\SeasonTicketContractSelection\Result;
use App\Kintone\Models\SubTable\SeasonTicketContractSelection\TargetRoom;
@@ -21,10 +24,12 @@ class SeasonTicketContractSelectionManager

private SelectionModel $selection;

public function __construct(?int $recordNo = null)
public function __construct(int|SelectionModel|null $recordNo = null)
{
if ($recordNo) {
if (is_int($recordNo)) {
$this->selection = SelectionModel::find($recordNo);
} else if ($recordNo instanceof SelectionModel) {
$this->selection = $recordNo;
} else {
$this->selection = new SelectionModel();
$this->selection->status = SelectionStatus::START;
@@ -84,9 +89,26 @@ class SeasonTicketContractSelectionManager
return $this;
}

public function sendNotine()
public function sendNotice()
{
// メール送信
foreach ($this->selection->candidateList as $candidate) {
if ($candidate->emailSendTarget) {
$entry = SeasonTicketContractEntry::find($candidate->entryRecordNo);

if (!in_array($entry->status, [Status::RESERVE, Status::WAIT_EMPTY])) {
continue;
}
if (!$entry->email) {
continue;
}

$email = new SelectionNotice($this->selection, $entry);
(new EmailManager($email->setEmail($entry->email)))->confirm();
}
}

$this->selection->status = SelectionStatus::ENTRY_ACCEPTING;

return $this;
}
@@ -114,6 +136,10 @@ class SeasonTicketContractSelectionManager
throw new AppCommonException("認証エラー");
}

if ($this->selection->status !== SelectionStatus::ENTRY_ACCEPTING) {
throw new GeneralErrorMessageException("募集期間が終了しています");
}

$list = $this->selection->entryList;

if ($this->hasAlreadyEnterd($recordNo)) {
@@ -144,13 +170,22 @@ class SeasonTicketContractSelectionManager
return $this->selection;
}

public function getEntry(int $entryRecordNo)
{
return SeasonTicketContractEntry::find($entryRecordNo);
}

/**
* @param integer $recordNo 申込レコード番号
* @return string
*/
public function getHash(int $recordNo): string
{
$source = sprintf("%010d-%010d", $recordNo, intval($this->selection->getRecordId()));
return hash('sha256', $source);
}

private function checkHash(int $recordNo, string $hash): bool
public function checkHash(int $recordNo, string $hash): bool
{
$expect = $this->getHash($recordNo);
return $expect === $hash;
@@ -192,6 +227,8 @@ class SeasonTicketContractSelectionManager
$result = new Result();
$result->entryRecordNo = $entry->entryRecordNo;
$result->roomRecordNo = $room->roomRecordNo;
$result->name = $entry->name;
$result->entryNo = $entry->entryNo;
$totalRoomAmount += $entry->carAmount;
$resultList->push($result);
}
@@ -203,7 +240,7 @@ class SeasonTicketContractSelectionManager


$this->selection->status = $resultList->isNotEmpty() ?
SelectionStatus::COMPLETE : SelectionStatus::FAILED;
SelectionStatus::RESULT_DECISION : SelectionStatus::FAILED;

$this->selection->resultList = $resultList;



+ 2
- 2
app/Providers/RouteServiceProvider.php 查看文件

@@ -31,8 +31,8 @@ class RouteServiceProvider extends ServiceProvider
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('api')
->prefix('api-email')
->group(base_path('routes/api_email.php'));
->prefix('api-from-kintone')
->group(base_path('routes/apiFromKintone.php'));

Route::middleware('web')
->group(base_path('routes/web.php'));


+ 33
- 0
app/Rules/SimpleRegEx.php 查看文件

@@ -0,0 +1,33 @@
<?php

namespace App\Rules;

class SimpleRegEx extends BaseRule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct(private $pattern, private $message, private $notMatch = false)
{
//
}


public function check($value): bool
{
$match = preg_match($this->pattern, $value);
return $this->notMatch ? $match === 0 : $match !== 0;
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return $this->message;
}
}

正在加载...
取消
保存