領収証発行サービス
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

92 lines
2.0KB

  1. <?php
  2. namespace App\Logic\SMS;
  3. use App\Codes\SMSProviderName;
  4. use App\Codes\SMSSendPurpose;
  5. use App\Events\SMS\ConfirmEvent;
  6. use App\Models\ReceiptIssuingOrder;
  7. use App\Models\SMSProvider;
  8. use App\Models\SMSSendOrder;
  9. use App\Util\DateUtil;
  10. class LogManager implements SMSManager
  11. {
  12. public static function makeSMSSendOrder(ReceiptIssuingOrder $receiptIssuingOrder, SMSSendPurpose $purpose, string $contents): SMSSendOrder
  13. {
  14. $order = new SMSSendOrder();
  15. $order->receipt_issuing_order_id = $receiptIssuingOrder->id;
  16. $order->contract_id = $receiptIssuingOrder->contract_id;
  17. $order->phone_number = $receiptIssuingOrder->sms_phone_number;
  18. $order->summary_key1 = $receiptIssuingOrder->summary_key1;
  19. $order->summary_key2 = $receiptIssuingOrder->summary_key2;
  20. $order->purpose = $purpose;
  21. $order->content = $contents;
  22. $order->sms_provider_id = static::getMst()->id;
  23. return $order;
  24. }
  25. public function __construct(
  26. private SMSSendOrder $order,
  27. ) {
  28. }
  29. public function loadOrder(string $id): static
  30. {
  31. $this->order = SMSSendOrder::findOrFail($id);
  32. return $this;
  33. }
  34. public function setOrder(SMSSendOrder $order): static
  35. {
  36. $this->order = $order;
  37. return $this;
  38. }
  39. public function getOrder()
  40. {
  41. return $this->order;
  42. }
  43. public function send(): bool
  44. {
  45. $this->order->send_datetime = DateUtil::now();
  46. $this->order->done = true;
  47. $this->order->save();
  48. info(sprintf("SMS送信ダミー:<<%s>>", $this->order->content));
  49. return true;
  50. }
  51. public function poll(): bool
  52. {
  53. return true;
  54. }
  55. public function cancel(): bool
  56. {
  57. return true;
  58. }
  59. private static function getMst(): SMSProvider
  60. {
  61. static $provider = null;
  62. if ($provider === null) {
  63. $provider = SMSProvider::whereProviderName(SMSProviderName::LOG->value)
  64. ->firstOrFail();
  65. }
  66. return $provider;
  67. }
  68. }