| @@ -0,0 +1,151 @@ | |||
| <?php | |||
| namespace App\Console\Commands; | |||
| use App\Email\Members\BankAccountRegisterRemaind as MembersBankAccountRegisterRemaind; | |||
| use App\Kintone\KintoneRecordQueryOperator; | |||
| use App\Kintone\Models\Customer; | |||
| use App\Logic\EmailManager; | |||
| use App\Util\DateUtil; | |||
| use App\Util\DBUtil; | |||
| use Exception; | |||
| use Illuminate\Support\Carbon; | |||
| use Illuminate\Support\Collection; | |||
| class BankAccountRegisterRemaind extends BaseCommand | |||
| { | |||
| const COMMAND = "remaind:bank-account-register"; | |||
| /** | |||
| * 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 Carbon | |||
| */ | |||
| private Carbon $targetDatetime; | |||
| /** | |||
| * 次回対象の日時 | |||
| * | |||
| * @var Carbon | |||
| */ | |||
| private Carbon $nextDatetime; | |||
| /** | |||
| * @var Collection<int, Customer> | |||
| */ | |||
| 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<int, Customer> | |||
| */ | |||
| 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); | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel | |||
| { | |||
| Schedules\HeartBeat::register($schedule); | |||
| Schedules\SMBCPoll::register($schedule); | |||
| Schedules\BankAccountRegisterRemaind::register($schedule); | |||
| } | |||
| /** | |||
| @@ -0,0 +1,17 @@ | |||
| <?php | |||
| namespace App\Console\Schedules; | |||
| use App\Console\Commands\BankAccountRegisterRemaind as CommandsBankAccountRegisterRemaind; | |||
| use Illuminate\Console\Scheduling\Schedule; | |||
| class BankAccountRegisterRemaind extends BaseSchedule | |||
| { | |||
| static public function register(Schedule $schedule) | |||
| { | |||
| $schedule->command(CommandsBankAccountRegisterRemaind::class) | |||
| ->hourly() | |||
| ->description("口座登録催促通知"); | |||
| } | |||
| } | |||
| @@ -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']), | |||
| ]; | |||
| } | |||
| } | |||
| @@ -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']), | |||
| ]; | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -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) | |||
| @@ -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 = [ | |||
| @@ -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; | |||
| } | |||
| @@ -1,5 +0,0 @@ | |||
| @extends('emails.layouts.members') | |||
| @section('contents') | |||
| 口座登録失敗しました | |||
| @endsection | |||
| @@ -1,5 +1,7 @@ | |||
| @extends('emails.layouts.members') | |||
| @extends('emails.layouts.member') | |||
| @section('contents') | |||
| 口座登録してください | |||
| 下記URLから振替口座の登録を行ってください。 | |||
| {{ $url }} | |||
| @endsection | |||