Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

154 rindas
5.6KB

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