您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

143 行
4.8KB

  1. <?php
  2. namespace App\Console\Commands\PoolTransfer;
  3. use App\Console\Commands\BaseCommand;
  4. use App\Exceptions\SkipException;
  5. use App\Kintone\KintoneRecordQueryOperator;
  6. use App\Kintone\Models\BankCheckResult;
  7. use App\Kintone\Models\DropDown\SmbcPayment\SmbcPaymentStatus;
  8. use App\Kintone\Models\SmbcAccountTransferResult;
  9. use App\Kintone\Models\SmbcPayment;
  10. use App\Kintone\Models\YuchoPaymentResult;
  11. use App\Logic\PoolTransferManager;
  12. use App\Util\CollectionUtil;
  13. use App\Util\DateUtil;
  14. use Illuminate\Support\Collection;
  15. class MoveToPool extends BaseCommand
  16. {
  17. const COMMAND = "pool-transfer:move-to-pool";
  18. /**
  19. * The name and signature of the console command.
  20. *
  21. * @var string
  22. */
  23. protected $signature = self::COMMAND;
  24. /**
  25. * The console command description.
  26. *
  27. * @var string
  28. */
  29. protected $description = '入金プールへ異動する';
  30. static public function getCommand()
  31. {
  32. return self::COMMAND;
  33. }
  34. /**
  35. * Create a new command instance.
  36. *
  37. * @return void
  38. */
  39. public function __construct()
  40. {
  41. parent::__construct();
  42. }
  43. /**
  44. * Execute the console command.
  45. *
  46. * @return int
  47. */
  48. public function service(): int
  49. {
  50. $targets = $this->getTargets();
  51. $this->outputInfo(sprintf("総件数:%d件", $targets->count()));
  52. foreach ($targets as $target) {
  53. try {
  54. $this->handleData($target);
  55. } catch (SkipException $e) {
  56. $this->outputWarn($e->getMessage());
  57. }
  58. }
  59. return self::RESULTCODE_SUCCESS;
  60. }
  61. public function handleData(YuchoPaymentResult|SmbcPayment|SmbcAccountTransferResult|BankCheckResult $payment)
  62. {
  63. $manager = new PoolTransferManager();
  64. $manager->moveToPool($payment);
  65. }
  66. /**
  67. * @return Collection<int ,YuchoPaymentResult|SmbcPayment|SmbcAccountTransferResult|BankCheckResult>
  68. */
  69. public function getTargets()
  70. {
  71. /**
  72. * @var Collection<int ,YuchoPaymentResult|SmbcPayment|SmbcAccountTransferResult|BankCheckResult>
  73. */
  74. $ret = collect();
  75. // ゆうちょ振込
  76. $query = YuchoPaymentResult::getQuery()->whereNotIn(YuchoPaymentResult::FIELD_POOL_DONE, ["済"])
  77. ->whereNotNull(YuchoPaymentResult::FIELD_CUSTOMER_CODE)
  78. ->where(YuchoPaymentResult::FIELD_PAYMENT_AMOUNT, 0, KintoneRecordQueryOperator::GT);
  79. $targets = YuchoPaymentResult::getAccess()->all($query);
  80. $ret->concat($targets);
  81. CollectionUtil::pushAll($ret, $targets);
  82. $this->outputInfo(sprintf("ゆうちょ件数:%d件", $targets->count()));
  83. // コンビニ支払
  84. $query = SmbcPayment::getQuery()->whereNotIn(SmbcPayment::FIELD_POOL_DONE, ["済"])
  85. ->whereNotNull(SmbcPayment::FIELD_CUSTOMER_CODE)
  86. ->where(SmbcPayment::FIELD_PAYMENT_AMOUNT, 0, KintoneRecordQueryOperator::GT)
  87. ->whereIn(SmbcPayment::FIELD_STATUS, [SmbcPaymentStatus::S002_決済結果待ち]);
  88. $targets = SmbcPayment::getAccess()->all($query);
  89. CollectionUtil::pushAll($ret, $targets);
  90. $this->outputInfo(sprintf("コンビニ支払:%d件", $targets->count()));
  91. // 口座振替
  92. $query = SmbcAccountTransferResult::getQuery()->whereNotIn(SmbcAccountTransferResult::FIELD_POOL_DONE, ["済"])
  93. ->whereNotNull(SmbcAccountTransferResult::FIELD_CUSTOMER_CODE)
  94. ->where(SmbcAccountTransferResult::FIELD_PAYMENT_AMOUNT, 0, KintoneRecordQueryOperator::GT);
  95. $targets = SmbcAccountTransferResult::getAccess()->all($query);
  96. CollectionUtil::pushAll($ret, $targets);
  97. $this->outputInfo(sprintf("口座振替:%d件", $targets->count()));
  98. // バンクチェック
  99. $query = BankCheckResult::getQuery()->whereNotIn(BankCheckResult::FIELD_POOL_DONE, ["済"])
  100. ->whereNotNull(BankCheckResult::FIELD_CUSTOMER_CODE)
  101. ->where(BankCheckResult::FIELD_REMAINING_AMOUNT, 0, KintoneRecordQueryOperator::LE);
  102. $targets = BankCheckResult::getAccess()->all($query);
  103. CollectionUtil::pushAll($ret, $targets);
  104. $this->outputInfo(sprintf("バンクチェック 支払完了:%d件", $targets->count()));
  105. $query = BankCheckResult::getQuery()->whereNotIn(BankCheckResult::FIELD_POOL_DONE, ["済"])
  106. ->whereNotNull(BankCheckResult::FIELD_CUSTOMER_CODE)
  107. ->where(BankCheckResult::FIELD_REMAINING_AMOUNT, 0, KintoneRecordQueryOperator::NEQ)
  108. ->whereDate(BankCheckResult::FIELD_PAYMENT_EXPIRES_DATE, DateUtil::now(), KintoneRecordQueryOperator::LT);
  109. $targets = BankCheckResult::getAccess()->all($query);
  110. CollectionUtil::pushAll($ret, $targets);
  111. $this->outputInfo(sprintf("バンクチェック 支払期限切れ:%d件", $targets->count()));
  112. return $ret;
  113. }
  114. }