|
- <?php
-
- namespace App\Console\Commands\PoolTransfer;
-
- use App\Console\Commands\BaseCommand;
- use App\Exceptions\SkipException;
- use App\Kintone\KintoneRecordQueryOperator;
- use App\Kintone\Models\BankCheckResult;
- use App\Kintone\Models\DropDown\SmbcPayment\SmbcPaymentStatus;
- use App\Kintone\Models\SmbcAccountTransferResult;
- use App\Kintone\Models\SmbcPayment;
- use App\Kintone\Models\YuchoPaymentResult;
- use App\Logic\PoolTransferManager;
- use App\Util\CollectionUtil;
- use App\Util\DateUtil;
- use Illuminate\Support\Collection;
-
- class MoveToPool extends BaseCommand
- {
-
- const COMMAND = "pool-transfer:move-to-pool";
-
-
- /**
- * 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;
- }
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function service(): int
-
-
- {
- $targets = $this->getTargets();
-
-
- $this->outputInfo(sprintf("総件数:%d件", $targets->count()));
-
- foreach ($targets as $target) {
-
- try {
- $this->handleData($target);
- } catch (SkipException $e) {
- $this->outputWarn($e->getMessage());
- }
- }
-
-
- return self::RESULTCODE_SUCCESS;
- }
-
- public function handleData(YuchoPaymentResult|SmbcPayment|SmbcAccountTransferResult|BankCheckResult $payment)
- {
-
- $manager = new PoolTransferManager();
- $manager->moveToPool($payment);
- }
-
- /**
- * @return Collection<int ,YuchoPaymentResult|SmbcPayment|SmbcAccountTransferResult|BankCheckResult>
- */
- public function getTargets()
- {
- /**
- * @var Collection<int ,YuchoPaymentResult|SmbcPayment|SmbcAccountTransferResult|BankCheckResult>
- */
- $ret = collect();
-
- // ゆうちょ振込
- $query = YuchoPaymentResult::getQuery()->whereNotIn(YuchoPaymentResult::FIELD_POOL_DONE, ["済"])
- ->whereNotNull(YuchoPaymentResult::FIELD_CUSTOMER_CODE)
- ->where(YuchoPaymentResult::FIELD_PAYMENT_AMOUNT, 0, KintoneRecordQueryOperator::GT);
-
- $targets = YuchoPaymentResult::getAccess()->all($query);
- $ret->concat($targets);
- CollectionUtil::pushAll($ret, $targets);
- $this->outputInfo(sprintf("ゆうちょ件数:%d件", $targets->count()));
-
- // コンビニ支払
- $query = SmbcPayment::getQuery()->whereNotIn(SmbcPayment::FIELD_POOL_DONE, ["済"])
- ->whereNotNull(SmbcPayment::FIELD_CUSTOMER_CODE)
- ->where(SmbcPayment::FIELD_PAYMENT_AMOUNT, 0, KintoneRecordQueryOperator::GT)
- ->whereIn(SmbcPayment::FIELD_STATUS, [SmbcPaymentStatus::S002_決済結果待ち]);
- $targets = SmbcPayment::getAccess()->all($query);
- CollectionUtil::pushAll($ret, $targets);
- $this->outputInfo(sprintf("コンビニ支払:%d件", $targets->count()));
-
- // 口座振替
- $query = SmbcAccountTransferResult::getQuery()->whereNotIn(SmbcAccountTransferResult::FIELD_POOL_DONE, ["済"])
- ->whereNotNull(SmbcAccountTransferResult::FIELD_CUSTOMER_CODE)
- ->where(SmbcAccountTransferResult::FIELD_PAYMENT_AMOUNT, 0, KintoneRecordQueryOperator::GT);
- $targets = SmbcAccountTransferResult::getAccess()->all($query);
- CollectionUtil::pushAll($ret, $targets);
- $this->outputInfo(sprintf("口座振替:%d件", $targets->count()));
-
- // バンクチェック
- $query = BankCheckResult::getQuery()->whereNotIn(BankCheckResult::FIELD_POOL_DONE, ["済"])
- ->whereNotNull(BankCheckResult::FIELD_CUSTOMER_CODE)
- ->where(BankCheckResult::FIELD_REMAINING_AMOUNT, 0, KintoneRecordQueryOperator::LE);
- $targets = BankCheckResult::getAccess()->all($query);
- CollectionUtil::pushAll($ret, $targets);
- $this->outputInfo(sprintf("バンクチェック 支払完了:%d件", $targets->count()));
-
- $query = BankCheckResult::getQuery()->whereNotIn(BankCheckResult::FIELD_POOL_DONE, ["済"])
- ->whereNotNull(BankCheckResult::FIELD_CUSTOMER_CODE)
- ->where(BankCheckResult::FIELD_REMAINING_AMOUNT, 0, KintoneRecordQueryOperator::NEQ)
- ->whereDate(BankCheckResult::FIELD_PAYMENT_EXPIRES_DATE, DateUtil::now(), KintoneRecordQueryOperator::LT);
- $targets = BankCheckResult::getAccess()->all($query);
- CollectionUtil::pushAll($ret, $targets);
- $this->outputInfo(sprintf("バンクチェック 支払期限切れ:%d件", $targets->count()));
-
- return $ret;
- }
- }
|