diff --git a/app/Console/Commands/BankAccountRegisterRemaind.php b/app/Console/Commands/BankAccountRegisterRemaind.php new file mode 100644 index 0000000..33b68a9 --- /dev/null +++ b/app/Console/Commands/BankAccountRegisterRemaind.php @@ -0,0 +1,151 @@ + + */ + 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); + } +} diff --git a/app/Console/Commands/SMBCPoll.php b/app/Console/Commands/SMBCPoll.php index 1423551..ac4a01a 100644 --- a/app/Console/Commands/SMBCPoll.php +++ b/app/Console/Commands/SMBCPoll.php @@ -2,7 +2,7 @@ namespace App\Console\Commands; -use App\Email\Members\FailedRegisterBankAccountNotice; +use App\Email\Members\BankAccountRegisterFailedNotice; use App\Http\API\SMBC\PollResultRecord; use App\Http\API\SMBC\SMBC; use App\Http\API\SMBC\SMBCStatus; @@ -166,7 +166,7 @@ class SMBCPoll extends BaseCommand // エラーメール送信 $customer = Customer::findByCustomerCode($data->getCustomerCode()); $this->outputWarn(sprintf("申請失敗のためエラーメール送信 受付番号%s 顧客コード:%d 氏名:%s", $data->acceptNo, $customer->customerCode, $customer->customerName)); - $email = new FailedRegisterBankAccountNotice($customer); + $email = new BankAccountRegisterFailedNotice($customer); $emailMmanager = new EmailManager($email); $emailMmanager->confirm(); return; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fc3232b..a94c279 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel { Schedules\HeartBeat::register($schedule); Schedules\SMBCPoll::register($schedule); + Schedules\BankAccountRegisterRemaind::register($schedule); } /** diff --git a/app/Console/Schedules/BankAccountRegisterRemaind.php b/app/Console/Schedules/BankAccountRegisterRemaind.php new file mode 100644 index 0000000..ad27113 --- /dev/null +++ b/app/Console/Schedules/BankAccountRegisterRemaind.php @@ -0,0 +1,17 @@ +command(CommandsBankAccountRegisterRemaind::class) + ->hourly() + ->description("口座登録催促通知"); + } +} diff --git a/app/Email/Members/BankAccountRegisterFailed.php b/app/Email/Members/BankAccountRegisterFailedNotice.php similarity index 50% rename from app/Email/Members/BankAccountRegisterFailed.php rename to app/Email/Members/BankAccountRegisterFailedNotice.php index a747f46..c76b7dc 100644 --- a/app/Email/Members/BankAccountRegisterFailed.php +++ b/app/Email/Members/BankAccountRegisterFailedNotice.php @@ -4,27 +4,29 @@ namespace App\Email\Members; use App\Kintone\Models\Customer; -class BankAccountRegisterFailed extends Members +class BankAccountRegisterFailedNotice extends Members { public function __construct( - Customer $customer, + Customer $customer ) { parent::__construct($customer); } public function getTemplateName(): string { - return 'emails.members.bank_account_register_failed'; + return 'emails.members.bank_account_register_failed_notice'; } public function getSubject(): string { - return "###TODO## 口座登録失敗"; + return "振替口座登録失敗のお知らせ"; } public function getMemberParams(): array { - return []; + return [ + 'url' => $this->getAppUrl(['dashboard', 'update', 'user', 'back-register']), + ]; } } diff --git a/app/Email/Members/BankAccountRegisterRemaind.php b/app/Email/Members/BankAccountRegisterRemaind.php index 360d997..d670709 100644 --- a/app/Email/Members/BankAccountRegisterRemaind.php +++ b/app/Email/Members/BankAccountRegisterRemaind.php @@ -8,7 +8,7 @@ class BankAccountRegisterRemaind extends Members { public function __construct( - Customer $customer, + Customer $customer ) { parent::__construct($customer); } @@ -20,11 +20,13 @@ class BankAccountRegisterRemaind extends Members public function getSubject(): string { - return "###TODO## 口座登録催促"; + return "振替口座登録のお願い"; } public function getMemberParams(): array { - return []; + return [ + 'url' => $this->getAppUrl(['dashboard', 'update', 'user', 'back-register']), + ]; } } diff --git a/app/Kintone/KintoneAccess.php b/app/Kintone/KintoneAccess.php index 40a37b2..0cc1be6 100644 --- a/app/Kintone/KintoneAccess.php +++ b/app/Kintone/KintoneAccess.php @@ -260,6 +260,7 @@ class KintoneAccess $e = $response->toException(); if ($e instanceof Exception) { Log::error($e->getMessage(), ['data' => $data]); + Log::error($response->body()); throw $e; } } diff --git a/app/Kintone/KintoneRecordQuery.php b/app/Kintone/KintoneRecordQuery.php index ae3a65c..e93053e 100644 --- a/app/Kintone/KintoneRecordQuery.php +++ b/app/Kintone/KintoneRecordQuery.php @@ -28,7 +28,7 @@ class KintoneRecordQuery $ret .= " "; } $ret .= $this->order; - // logger(sprintf("QUERY[%s]:%s", $this->appName, $ret)); + logger(sprintf("QUERY[%s]:%s", $this->appName, $ret)); return $ret; } @@ -36,7 +36,7 @@ class KintoneRecordQuery { return $this->whereQuery("and", $operator->value, $column, $condition); } - public function notWhere(string|Closure $column, string|int|null $condition = null, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::EQ) + public function notWhere(string|Closure $column, string|int|null $condition = null, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::NEQ) { return $this->whereQuery("and", $operator->value, $column, $condition); } @@ -46,7 +46,7 @@ class KintoneRecordQuery $this->whereQuery("or", $operator->value, $column, $condition); return $this; } - public function notOrWhere(string|Closure $column, string|int|null $condition = null, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::EQ) + public function notOrWhere(string|Closure $column, string|int|null $condition = null, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::NEQ) { return $this->whereQuery("or", $operator->value, $column, $condition); } @@ -64,19 +64,35 @@ class KintoneRecordQuery } public function whereDate(string $column, Carbon $date, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::EQ) { - return $this->whereQuery("and", $operator->value, $column, $date->format('Y-m-d')); + return $this->whereNotNull($column)->whereQuery("and", $operator->value, $column, $date->format('Y-m-d')); } public function whereDateTime(string $column, Carbon $date, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::EQ) { - return $this->whereQuery("and", $operator->value, $column, $date->toIso8601ZuluString()); + return $this->whereNotNull($column)->whereQuery("and", $operator->value, $column, $date->toIso8601ZuluString()); } public function orWhereDate(string $column, Carbon $date, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::EQ) { - return $this->whereQuery("or", $operator->value, $column, $date->format('Y-m-d')); + return $this->whereNotNull($column)->whereQuery("or", $operator->value, $column, $date->format('Y-m-d')); } public function orWhereDateTime(string $column, Carbon $date, KintoneRecordQueryOperator $operator = KintoneRecordQueryOperator::EQ) { - return $this->whereQuery("or", $operator->value, $column, $date->toIso8601ZuluString()); + return $this->whereNotNull($column)->whereQuery("or", $operator->value, $column, $date->toIso8601ZuluString()); + } + public function whereNull(string $column) + { + return $this->where($column, ""); + } + public function owWhereNull(string $column) + { + return $this->orWhere($column, ""); + } + public function whereNotNull(string $column) + { + return $this->notWhere($column, ""); + } + public function owWhereNotNull(string $column) + { + return $this->notOrWhere($column, ""); } public function orderByAsc(string $column) diff --git a/app/Kintone/Models/Customer.php b/app/Kintone/Models/Customer.php index 6bef8b4..7347018 100644 --- a/app/Kintone/Models/Customer.php +++ b/app/Kintone/Models/Customer.php @@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Auth; * @property string zipCode * @property string address * @property string bankBranchId + * @property ?Carbon bankAccountRegisterRemaindDatetime */ class Customer extends KintoneModel { @@ -27,6 +28,7 @@ class Customer extends KintoneModel const FIELD_ZIP_CODE = "契約者_郵便番号"; const FIELD_ADDRESS = "住所"; const FIELD_BANK_BRANCH_ID = "ChargedBankBranchCode"; + const FIELD_BANK_ACCOUNT_REGISTER_REMAIND_DATETIME = "口座登録催促予定日時"; protected const FIELDS = [ ...parent::FIELDS, @@ -38,6 +40,7 @@ class Customer extends KintoneModel self::FIELD_ZIP_CODE => FieldType::SINGLE_LINE_TEXT, self::FIELD_ADDRESS => FieldType::SINGLE_LINE_TEXT, self::FIELD_BANK_BRANCH_ID => FieldType::SINGLE_LINE_TEXT, + self::FIELD_BANK_ACCOUNT_REGISTER_REMAIND_DATETIME => FieldType::DATETIME, ]; protected const FIELD_NAMES = [ diff --git a/app/Kintone/Models/KintoneModel.php b/app/Kintone/Models/KintoneModel.php index 7f97dc2..9f675ed 100644 --- a/app/Kintone/Models/KintoneModel.php +++ b/app/Kintone/Models/KintoneModel.php @@ -182,18 +182,6 @@ abstract class KintoneModel data_set($this->data, $path, $value); return $this; - // if ( - // $type === FieldType::STRING || - // $type === FieldType::ARRAY - // ) { - // data_set($this->data, $path, $value); - // // logger([$path, $value]); - // return $this; - // } - // if ($type === FieldType::DATETIME) { - // data_set($this->data, $path, DateUtil::parse($value)); - // return $this; - // } } public function setDataFromRecordResponse(array $data): bool @@ -289,14 +277,17 @@ abstract class KintoneModel $data = $this->getDate($fieldCode); if ($data) { data_set($ret, $path, $data->toIso8601ZuluString()); + } else { + data_set($ret, $path, ""); } continue; } if ($type === FieldType::DATE) { $data = $this->getDate($fieldCode); if ($data) { - data_set($ret, $path, $data->format("Y-m-d")); data_set($ret, $path, $data->toDateString()); + } else { + data_set($ret, $path, ""); } continue; } diff --git a/resources/views/emails/members/bank_account_register_failed.blade.php b/resources/views/emails/members/bank_account_register_failed.blade.php deleted file mode 100644 index 5edd99a..0000000 --- a/resources/views/emails/members/bank_account_register_failed.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -@extends('emails.layouts.members') - -@section('contents') -口座登録失敗しました -@endsection \ No newline at end of file diff --git a/resources/views/emails/members/failed_register_bank_account_notice.blade.php b/resources/views/emails/members/bank_account_register_failed_notice.blade.php similarity index 100% rename from resources/views/emails/members/failed_register_bank_account_notice.blade.php rename to resources/views/emails/members/bank_account_register_failed_notice.blade.php diff --git a/resources/views/emails/members/bank_account_register_remaind.blade.php b/resources/views/emails/members/bank_account_register_remaind.blade.php index 663a99b..3930bbc 100644 --- a/resources/views/emails/members/bank_account_register_remaind.blade.php +++ b/resources/views/emails/members/bank_account_register_remaind.blade.php @@ -1,5 +1,7 @@ -@extends('emails.layouts.members') +@extends('emails.layouts.member') @section('contents') -口座登録してください +下記URLから振替口座の登録を行ってください。 + +{{ $url }} @endsection \ No newline at end of file