No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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