領収証発行サービス
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

71 行
1.5KB

  1. <?php
  2. namespace App\Logic\ReceiptIssuingOrder;
  3. use App\Exceptions\AppCommonException;
  4. use App\Features\LoginUser;
  5. use App\Models\ReceiptIssuingOrder;
  6. use App\Util\DateUtil;
  7. use Illuminate\Support\Str;
  8. use LogicException;
  9. abstract class ReceiptIssuingOrderManager
  10. {
  11. use LoginUser;
  12. protected bool $initialized = false;
  13. public function __construct(
  14. protected ReceiptIssuingOrder $order,
  15. ) {
  16. }
  17. protected function fetch(string $receiptIssuingOrderId)
  18. {
  19. $order = ReceiptIssuingOrder::findOrFail($receiptIssuingOrderId);
  20. if (!$this->loginUser()->checkAuthorization($order)) {
  21. throw new AppCommonException("認可不良");
  22. }
  23. $this->order = $order;
  24. }
  25. protected function refreshToken()
  26. {
  27. $order = $this->order;
  28. $order->access_token = base64_encode(Str::uuid());
  29. $order->access_token_expires_at = DateUtil::now()->adddays(7);
  30. }
  31. protected function checkToken(string $token): bool
  32. {
  33. $order = ReceiptIssuingOrder::whereAccessToken($token)
  34. ->first();
  35. if (!($order instanceof ReceiptIssuingOrder)) {
  36. return false;
  37. }
  38. if ($order->access_token_expires_at === null) {
  39. return false;
  40. }
  41. if ($order->access_token !== $token) {
  42. return false;
  43. }
  44. $now = DateUtil::now();
  45. $ret = $now->lt($this->order->access_token_expires_at);
  46. if (!$ret) {
  47. return false;
  48. }
  49. $this->order = $order;
  50. return true;
  51. }
  52. }