*/ private Collection $customers; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); $this->customers = collect(); } /** * Execute the console command. * * @return int */ public function service(): int { try { $db = DBUtil::instance(); $db->beginTransaction(); // 基準日時の設定 $this->targetDatetime = DateUtil::now()->setMinute(0)->setSecond(0); // 次回日時の設定 7日後 $this->nextDatetime = $this->targetDatetime->clone()->addDays(7); // 対象の取得 $targets = $this->getTargets(); // 対象の処理 foreach ($targets as $target) { $this->handleData($target); } // キントーンへ各種申請登録 foreach ($this->customers as $customer) { if ($customer->bankAccountRegisterRemaindDatetime) { $this->outputInfo(sprintf("口座登録催促予定日時更新 顧客コード:%s 氏名:%s", $customer->customerCode, $customer->customerName)); } else { $this->outputInfo(sprintf("口座登録催促予定日時クリアー 顧客コード:%s 氏名:%s", $customer->customerCode, $customer->customerName)); } $customer->save(); } $this->outputInfo(sprintf("登録件数:%d件", $this->customers->count())); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } return self::RESULTCODE_SUCCESS; } /** * @return Collection */ private function getTargets(): Collection { $access = Customer::getAccess(); $query = Customer::getQuery()->whereDateTime( Customer::FIELD_BANK_ACCOUNT_REGISTER_REMAIND_DATETIME, $this->targetDatetime, KintoneRecordQueryOperator::LE ); $ret = $access->all($query); return $ret; } private function handleData(Customer $customer) { if ($customer->bankBranchId) { // 口座登録済みの場合は、口座登録催促予定日時をクリアーする $customer->bankAccountRegisterRemaindDatetime = null; } else { // メール通知し、次回通知日時を更新する $customer->bankAccountRegisterRemaindDatetime = $this->nextDatetime->clone(); // 通知メール送信 $email = new MembersBankAccountRegisterRemaind($customer); $emailMmanager = new EmailManager($email); $emailMmanager->confirm(); } $this->customers->push($customer); } }