|
|
|
@@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |