| @@ -0,0 +1,108 @@ | |||||
| <?php | |||||
| namespace App\Console\Commands; | |||||
| use App\Email\Members\TerminateOrderComplete; | |||||
| use App\Kintone\Models\SeasonTicketContract; | |||||
| use App\Logic\EmailManager; | |||||
| use App\Util\DateUtil; | |||||
| use App\Util\DBUtil; | |||||
| use Exception; | |||||
| use Illuminate\Support\Collection; | |||||
| class SeasonTicketContractTerminateComplete extends BaseCommand | |||||
| { | |||||
| const COMMAND = "season-ticket-contract:terminate-complete"; | |||||
| /** | |||||
| * 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; | |||||
| } | |||||
| /** | |||||
| * @var Collection<int, EmailManager> | |||||
| */ | |||||
| private Collection $managers; | |||||
| /** | |||||
| * 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); | |||||
| } | |||||
| // コミット | |||||
| $this->commit(); | |||||
| $db->commit(); | |||||
| } catch (Exception $e) { | |||||
| $db->rollBack(); | |||||
| throw $e; | |||||
| } | |||||
| return self::RESULTCODE_SUCCESS; | |||||
| } | |||||
| private function getTargets() | |||||
| { | |||||
| $access = SeasonTicketContract::getAccess(); | |||||
| $query = SeasonTicketContract::getQuery() | |||||
| ->where(SeasonTicketContract::FIELD_CONTRACT_END_DATE, DateUtil::now()->setTime(0, 0)); | |||||
| return $access->all($query); | |||||
| } | |||||
| private function handleData(SeasonTicketContract $data) | |||||
| { | |||||
| $email = new TerminateOrderComplete($data); | |||||
| $manager = new EmailManager($email); | |||||
| $this->managers->push($manager); | |||||
| } | |||||
| private function commit() | |||||
| { | |||||
| foreach ($this->managers as $manager) { | |||||
| $manager->confirm(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -17,6 +17,7 @@ class Kernel extends ConsoleKernel | |||||
| Schedules\BankAccountRegisterRemaind::register($schedule); | Schedules\BankAccountRegisterRemaind::register($schedule); | ||||
| Schedules\SeasonTikcetContractSelectionFillCandidates::register($schedule); | Schedules\SeasonTikcetContractSelectionFillCandidates::register($schedule); | ||||
| Schedules\SeasonTikcetContractSelectionSetResult::register($schedule); | Schedules\SeasonTikcetContractSelectionSetResult::register($schedule); | ||||
| Schedules\SeasonTicketContractTerminateComplete::register($schedule); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,17 @@ | |||||
| <?php | |||||
| namespace App\Console\Schedules; | |||||
| use App\Console\Commands\SeasonTicketContractTerminateComplete as Command; | |||||
| use Illuminate\Console\Scheduling\Schedule; | |||||
| class SeasonTicketContractTerminateComplete extends BaseSchedule | |||||
| { | |||||
| static public function register(Schedule $schedule) | |||||
| { | |||||
| $schedule->command(Command::class) | |||||
| ->at("00:05") | |||||
| ->description("解約完了通知"); | |||||
| } | |||||
| } | |||||
| @@ -11,11 +11,10 @@ class TerminateOrderComplete extends Members | |||||
| public function __construct( | public function __construct( | ||||
| private SeasonTicketContract $seasonTicketContract, | private SeasonTicketContract $seasonTicketContract, | ||||
| private TerminateApplication $app, | |||||
| ?Customer $customer = null, | ?Customer $customer = null, | ||||
| ) { | ) { | ||||
| if ($customer === null) { | if ($customer === null) { | ||||
| $customer = $app->getCustomer(); | |||||
| $customer = $seasonTicketContract->getCustomer(); | |||||
| } | } | ||||
| parent::__construct($customer); | parent::__construct($customer); | ||||
| } | } | ||||
| @@ -33,9 +32,9 @@ class TerminateOrderComplete extends Members | |||||
| public function getMemberParams(): array | public function getMemberParams(): array | ||||
| { | { | ||||
| return [ | return [ | ||||
| 'parking_name' => $this->app->parkingName, | |||||
| 'parking_name' => $this->seasonTicketContract->parkingName, | |||||
| 'vehicle_no' => $this->seasonTicketContract->vehicleNo, | 'vehicle_no' => $this->seasonTicketContract->vehicleNo, | ||||
| 'terminate_date' => $this->app->terminateDate->format('Y/m/d'), | |||||
| 'terminate_date' => $this->seasonTicketContract->contractEndDate->format('Y/m/d'), | |||||
| ]; | ]; | ||||
| } | } | ||||
| } | } | ||||