領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.0KB

  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Events\SMS\ConfirmEvent;
  4. use App\Exceptions\AppCommonException;
  5. use App\Logic\SMS\SMSManager;
  6. use App\Models\SMSSendOrder;
  7. class TestMail extends BaseCommand
  8. {
  9. const COMMAND = "sms:poll";
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = self::COMMAND;
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'SMS配信状況を取得/反映する';
  22. static public function getCommand()
  23. {
  24. return self::COMMAND;
  25. }
  26. /**
  27. * Create a new command instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct(private SMSManager $manager)
  32. {
  33. parent::__construct();
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return int
  39. */
  40. public function service(): int
  41. {
  42. $targets = $this->getTargets();
  43. $this->outputInfo(sprintf("対象:%d件", $targets->count()));
  44. if ($targets->isEmpty()) {
  45. return self::RESULTCODE_SUCCESS;
  46. } else {
  47. }
  48. foreach ($targets as $order) {
  49. $this->handleOrder($order);
  50. }
  51. return self::RESULTCODE_SUCCESS;
  52. }
  53. public function getTargets()
  54. {
  55. return SMSSendOrder::whereDone(false)
  56. ->get();
  57. }
  58. public function handleOrder(SMSSendOrder $order)
  59. {
  60. $ret = $this->manager->setOrder($order)
  61. ->poll();
  62. if ($ret) {
  63. $order->save();
  64. $this->outputInfo(sprintf(
  65. "ID:%s 電話番号:%s %s",
  66. $order->id,
  67. $order->phone_number,
  68. $order->done ? "完了" : "未"
  69. ));
  70. // イベント発行
  71. if ($order->done) {
  72. ConfirmEvent::dispatch($order);
  73. }
  74. } else {
  75. $this->outputError(printf("失敗対象:%s", $order->toJson()));
  76. throw new AppCommonException("POLL 失敗");
  77. }
  78. }
  79. }