Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

127 Zeilen
3.1KB

  1. <?php
  2. namespace App\Console\Commands\PoolTransfer;
  3. use App\Console\Commands\BaseCommand;
  4. use App\Email\Members\EntryPaymentComplete;
  5. use App\Exceptions\SkipException;
  6. use App\Kintone\KintoneRecordQueryOperator;
  7. use App\Kintone\Models\PaymentPlan;
  8. use App\Kintone\Models\Pool;
  9. use App\Kintone\Models\SeasonTicketContractEntry;
  10. use App\Logic\EmailManager;
  11. use App\Logic\PoolAttachManager;
  12. class AttachToPaymentPlan extends BaseCommand
  13. {
  14. const COMMAND = "pool-transfer:attach-to-payment-plan";
  15. /**
  16. * The name and signature of the console command.
  17. *
  18. * @var string
  19. */
  20. protected $signature = self::COMMAND;
  21. /**
  22. * The console command description.
  23. *
  24. * @var string
  25. */
  26. protected $description = '入金予定実績へ充当する';
  27. static public function getCommand()
  28. {
  29. return self::COMMAND;
  30. }
  31. /**
  32. * Create a new command instance.
  33. *
  34. * @return void
  35. */
  36. public function __construct()
  37. {
  38. parent::__construct();
  39. }
  40. /**
  41. * Execute the console command.
  42. *
  43. * @return int
  44. */
  45. public function service(): int
  46. {
  47. $targets = $this->getTargets();
  48. $this->outputInfo(sprintf("総件数:%d件", $targets->count()));
  49. foreach ($targets as $index => $target) {
  50. // 100件ごとに経過を出力
  51. if ($index % 100 === 0) {
  52. $this->outputInfo(sprintf("処理中:%d件目", $index + 1));
  53. }
  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(Pool $pool)
  63. {
  64. $manager = new PoolAttachManager();
  65. $manager->attach($pool)
  66. ->save();
  67. // 初回振り込み完了処理
  68. if ($manager->getFirstPaymnetEntryRecordIds()->isNotEmpty()) {
  69. foreach ($manager->getFirstPaymnetEntryRecordIds() as $entryRecordId) {
  70. $this->handleFirstPaymentDone($entryRecordId);
  71. }
  72. }
  73. }
  74. public function handleFirstPaymentDone(int $entryRecordNo)
  75. {
  76. // 未払いチェック
  77. $query = PaymentPlan::getQuery()->where(PaymentPlan::FIELD_FIRST_PAYMENT_ENTRY_RECORD_NO, $entryRecordNo);
  78. $plans = PaymentPlan::getAccess()->all($query);
  79. if ($plans->isEmpty()) {
  80. return;
  81. }
  82. // 未払い検索
  83. $未払い = $plans->first((function (PaymentPlan $plan) {
  84. return !$plan->appropriationDate || $plan->appropriationAmount !== $plan->paymentPlanAmount;
  85. }));
  86. if ($未払い) {
  87. return;
  88. }
  89. // 充当済み処理
  90. $entry = SeasonTicketContractEntry::find($entryRecordNo);
  91. $entry->firstPaymentDone = ["充当済み"];
  92. $entry->save();
  93. }
  94. public function getTargets()
  95. {
  96. $query = Pool::getQuery()->where(Pool::FIELD_POOL_AMOUNT, 0, KintoneRecordQueryOperator::GT);
  97. $ret = Pool::getAccess()->all($query);
  98. return $ret;
  99. }
  100. }