Você não pode selecionar mais de 25 tópicos
Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
|
- <?php
-
- namespace App\Logic\ReceiptIssuingOrder;
-
- use App\Exceptions\AppCommonException;
- use App\Features\LoginUser;
- use App\Models\ReceiptIssuingOrder;
- use App\Util\DateUtil;
- use Illuminate\Support\Str;
- use LogicException;
-
- abstract class ReceiptIssuingOrderManager
- {
- use LoginUser;
-
- protected bool $initialized = false;
-
- protected function __construct(protected ReceiptIssuingOrder $order)
- {
- }
-
- protected function fetch(string $receiptIssuingOrderId)
- {
- $order = ReceiptIssuingOrder::findOrFail($receiptIssuingOrderId);
- if (!$this->loginUser()->checkAuthorization($order)) {
- throw new AppCommonException("認可不良");
- }
- $this->order = $order;
- }
-
- protected function refreshToken()
- {
- $order = $this->order;
-
- $order->access_token = base64_encode(Str::uuid());
- $order->access_token_expires_at = DateUtil::now()->adddays(7);
- }
-
- protected function checkToken(string $token): bool
- {
-
- if ($this->order->isNotSavedModel()) {
- throw new LogicException("初期化不良");
- }
-
- $order = ReceiptIssuingOrder::whereAccessToken($token)
- ->first();
-
- if (!($order instanceof ReceiptIssuingOrder)) {
- return false;
- }
-
- if ($order->access_token_expires_at === null) {
- return false;
- }
-
- if ($order->access_token !== $token) {
- return false;
- }
-
- $now = DateUtil::now();
-
- $ret = $now->lt($this->order->access_token_expires_at);
-
- if (!$ret) {
- return false;
- }
-
- $this->order = $order;
-
- return true;
- }
- }
|