Parcourir la source

refactor: 统一代码风格

runphp il y a 2 semaines
Parent
commit
20d1e23554

+ 2 - 1
config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 // 支付方式选项解析函数
@@ -47,4 +48,4 @@ $paymentConfig = [
     ],
 ];
 
-return $paymentConfig;
+return $paymentConfig;

+ 1 - 0
info.php

@@ -1,4 +1,5 @@
 <?php
+
 return [
     'id' => 'payment',
     'name' => '支付模块',

+ 1 - 0
route/admin.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 

+ 3 - 1
route/api.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 
@@ -9,7 +10,8 @@ use SixShop\Payment\Controller\{
 use think\facade\Route;
 
 Route::resource('', PaymentController::class)->middleware(
-    'auth', false
+    'auth',
+    false
 );
 
 Route::resource('record', RecordController::class)->middleware([

+ 2 - 1
src/Config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment;
@@ -16,4 +17,4 @@ class Config
     {
         return Extension::EXTENSION_ID;
     }
-}
+}

+ 1 - 1
src/Contracts/PaymentExtensionInterface.php

@@ -8,4 +8,4 @@ interface PaymentExtensionInterface
      * 获取支付方式提供者
      */
     public function getPaymentProvider(): PaymentProviderInterface;
-}
+}

+ 3 - 4
src/Contracts/PaymentNotifyResult.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Contracts;
@@ -7,14 +8,12 @@ use SixShop\Payment\Enum\PaymentStatusEnum;
 
 class PaymentNotifyResult
 {
-
     public function __construct(
         public string            $orderNo,
         public string            $transactionId,
         public float             $amount,
         public PaymentStatusEnum $status,
         public array             $raw
-    )
-    {
+    ) {
     }
-}
+}

+ 1 - 0
src/Contracts/PaymentProviderInterface.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Contracts;

+ 3 - 3
src/Contracts/PaymentQueryResult.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Contracts;
@@ -12,7 +13,6 @@ class PaymentQueryResult
         public PaymentStatusEnum $status,
         public float  $amount,
         public array  $raw
-    )
-    {
+    ) {
     }
-}
+}

+ 4 - 2
src/Contracts/PaymentRefundRequest.php

@@ -1,10 +1,12 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Contracts;
 
 readonly class PaymentRefundRequest
 {
-    public function __construct(private  float $amount, private string $reason, private array $raw = [])
+    public function __construct(private float $amount, private string $reason, private array $raw = [])
     {
     }
 
@@ -22,4 +24,4 @@ readonly class PaymentRefundRequest
     {
         return $this->raw;
     }
-}
+}

+ 2 - 1
src/Contracts/PaymentRefundResult.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Contracts;
@@ -15,4 +16,4 @@ readonly class PaymentRefundResult
     {
         return $this->refund;
     }
-}
+}

+ 2 - 1
src/Contracts/PaymentResponse.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Contracts;
@@ -17,4 +18,4 @@ class PaymentResponse implements \JsonSerializable
             'raw' => $this->raw,
         ];
     }
-}
+}

+ 3 - 3
src/Controller/PaymentController.php

@@ -1,14 +1,14 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Controller;
 
-use SixShop\Core\Helper;
 use SixShop\Core\Request;
 use SixShop\Payment\Config;
 use SixShop\Payment\PaymentManager;
 use think\Response;
-use think\response\Json;
+
 use function SixShop\Core\success_response;
 
 class PaymentController
@@ -25,4 +25,4 @@ class PaymentController
         }
         return success_response($result);
     }
-}
+}

+ 4 - 1
src/Controller/RecordController.php

@@ -1,10 +1,13 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Controller;
 
 use SixShop\Payment\Entity\ExtensionPaymentEntity;
 use SixShop\Payment\PaymentManager;
 use think\Response;
+
 use function SixShop\Core\success_response;
 
 class RecordController
@@ -16,4 +19,4 @@ class RecordController
         $paymentManager->query($entity->pay_type, $entity->id);
         return success_response($entity);
     }
-}
+}

+ 4 - 2
src/Entity/ExtensionPaymentEntity.php

@@ -1,10 +1,13 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Entity;
 
 use SixShop\Core\Entity\BaseEntity;
 use SixShop\Payment\Model\ExtensionPaymentModel;
 use think\Model;
+
 use function SixShop\Core\throw_logic_exception;
 
 /**
@@ -12,7 +15,6 @@ use function SixShop\Core\throw_logic_exception;
  */
 class ExtensionPaymentEntity extends BaseEntity
 {
-
     public function __construct(?Model $model = null)
     {
         parent::__construct($model);
@@ -26,4 +28,4 @@ class ExtensionPaymentEntity extends BaseEntity
         }
         return $entity;
     }
-}
+}

+ 3 - 2
src/Entity/ExtensionRefundEntity.php

@@ -1,10 +1,11 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Entity;
 
 use SixShop\Core\Entity\BaseEntity;
 
 class ExtensionRefundEntity extends BaseEntity
 {
-
-}
+}

+ 2 - 2
src/Enum/NumberBizEnum.php

@@ -1,9 +1,9 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Enum;
 
-
 enum NumberBizEnum: int
 {
     case ORDER_NO = 1;
@@ -34,4 +34,4 @@ enum NumberBizEnum: int
             PaymentBizEnum::VIP_PAY => self::VIP_PAY,
         };
     }
-}
+}

+ 3 - 1
src/Enum/PaymentBizEnum.php

@@ -1,8 +1,10 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Enum;
 
-enum PaymentBizEnum:int
+enum PaymentBizEnum: int
 {
     case ORDER_PAY = 1;
     case VIP_PAY = 2;

+ 3 - 1
src/Enum/PaymentStatusEnum.php

@@ -1,8 +1,10 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Enum;
 
-enum PaymentStatusEnum:int
+enum PaymentStatusEnum: int
 {
     case PENDING = 0;
     case PAYING = 1;

+ 3 - 1
src/Enum/RefundStatusEnum.php

@@ -1,8 +1,10 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Enum;
 
-enum RefundStatusEnum:int
+enum RefundStatusEnum: int
 {
     case PENDING = 0;
     case REFUNDING = 1;

+ 3 - 1
src/Event/BeforePayEvent.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Event;
 
 use SixShop\Payment\Enum\PaymentBizEnum;
@@ -24,4 +26,4 @@ class BeforePayEvent
     {
         return $this->bizType;
     }
-}
+}

+ 3 - 1
src/Event/GatheringPaymentEvent.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Event;
 
 use SixShop\Core\Request;
@@ -9,4 +11,4 @@ class GatheringPaymentEvent
     public function __construct(public Request $request)
     {
     }
-}
+}

+ 3 - 1
src/Event/PaymentSuccessEvent.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Event;
 
 use SixShop\Payment\Enum\PaymentBizEnum;
@@ -13,4 +15,4 @@ class PaymentSuccessEvent
         public PaymentBizEnum $bizType,
     ) {
     }
-}
+}

+ 3 - 1
src/Event/RefundSuccessEvent.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Event;
 
 use SixShop\Payment\Contracts\PaymentRefundRequest;
@@ -25,4 +27,4 @@ readonly class RefundSuccessEvent
     {
         return $this->paymentRefundRequest;
     }
-}
+}

+ 1 - 0
src/Extension.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment;

+ 2 - 1
src/Hook/ConfigHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Hook;
@@ -70,4 +71,4 @@ class ConfigHook
                 '_fc_drag_tag' => 'elCard'
             ];
     }
-}
+}

+ 2 - 2
src/Hook/OrderHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Hook;
@@ -10,7 +11,6 @@ use SixShop\Payment\Event\PaymentSuccessEvent;
 
 class OrderHook
 {
-
     #[Hook(PaymentSuccessEvent::class)]
     public function onPaymentSuccess(PaymentSuccessEvent $event): void
     {
@@ -24,4 +24,4 @@ class OrderHook
             'order_status' => 20, //待发货
         ]);
     }
-}
+}

+ 3 - 1
src/Model/ExtensionPaymentModel.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment\Model;
 
 use SixShop\Payment\Enum\NumberBizEnum;
@@ -52,4 +54,4 @@ class ExtensionPaymentModel extends Model
             'readonly' => ['order_id', 'order_sn', 'out_trade_no', 'biz_type', 'pay_type', 'amount'],
         ];
     }
-}
+}

+ 2 - 1
src/Model/ExtensionRefundModel.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Payment\Model;
@@ -34,4 +35,4 @@ class ExtensionRefundModel extends Model
     {
         return $this->belongsTo(ExtensionPaymentModel::class, 'payment_id', 'id');
     }
-}
+}

+ 3 - 1
src/PaymentInfo.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment;
 
 use SixShop\System\Enum\ExtensionStatusEnum;
@@ -17,4 +19,4 @@ class PaymentInfo
     ) {
 
     }
-}
+}

+ 13 - 15
src/PaymentManager.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Payment;
 
 use SixShop\Payment\Contracts\PaymentProviderInterface;
@@ -7,8 +9,6 @@ use SixShop\Payment\Contracts\PaymentQueryResult;
 use SixShop\Payment\Contracts\PaymentRefundRequest;
 use SixShop\Payment\Contracts\PaymentRefundResult;
 use SixShop\Payment\Contracts\PaymentResponse;
-use SixShop\Payment\Entity\ExtensionPaymentEntity;
-use SixShop\Payment\Entity\ExtensionRefundEntity;
 use SixShop\Payment\Enum\PaymentBizEnum;
 use SixShop\Payment\Event\BeforePayEvent;
 use SixShop\Payment\Event\GatheringPaymentEvent;
@@ -18,11 +18,9 @@ use think\facade\Event;
 
 readonly class PaymentManager
 {
-
     public function __construct(
         private ExtensionManager $extensionManager,
-    )
-    {
+    ) {
     }
 
     /**
@@ -30,13 +28,13 @@ readonly class PaymentManager
      *
      * @return PaymentInfo[]
      */
-    public function getAllPayment():array
+    public function getAllPayment(): array
     {
         /* @var PaymentInfo[] $paymentList */
         $paymentList = Event::trigger(GatheringPaymentEvent::class);
         $paymentIDs = array_column($paymentList, 'id');
         $statusMap = ExtensionModel::whereIn('id', $paymentIDs)->column(['status','id'], 'id', true);
-        $payTypeList = extension_config('payment', 'pay_type')??[];
+        $payTypeList = extension_config('payment', 'pay_type') ?? [];
         foreach ($paymentList as $payment) {
             $payment->status = $statusMap[$payment->id]['status'];
             $payment->enabled = in_array($payment->id, $payTypeList, true);
@@ -47,12 +45,12 @@ readonly class PaymentManager
     /**
      *  创建支付订单
      */
-    public function create(string $paymentID,  array $order, PaymentBizEnum $bizType = PaymentBizEnum::ORDER_PAY):  PaymentResponse
+    public function create(string $paymentID, array $order, PaymentBizEnum $bizType = PaymentBizEnum::ORDER_PAY): PaymentResponse
     {
         Event::trigger(new BeforePayEvent($order, $paymentID, $bizType));
         return $this->getPaymentProvider($paymentID)->create($order, $bizType);
     }
-    
+
     /**
      * 查询支付订单
      */
@@ -68,7 +66,7 @@ readonly class PaymentManager
     {
         return $this->getPaymentProvider($paymentID)->refund($recordID, $param);
     }
-    
+
     /**
      * 查询退款
      */
@@ -76,11 +74,11 @@ readonly class PaymentManager
     {
         return $this->getPaymentProvider($paymentID)->refundQuery($refundID);
     }
-    
+
     /**
      * 获取指定支付方式
      */
-    public function getPayment($paymentID):array
+    public function getPayment($paymentID): array
     {
         return [
             // todo
@@ -90,7 +88,7 @@ readonly class PaymentManager
     /**
      * 开启支付方式
      */
-    public function enablePayment($paymentID):bool
+    public function enablePayment($paymentID): bool
     {
         // todo
         return true;
@@ -99,7 +97,7 @@ readonly class PaymentManager
     /**
      * 关闭支付方式
      */
-    public function disablePayment($paymentID):bool
+    public function disablePayment($paymentID): bool
     {
         // todo
         return true;
@@ -111,4 +109,4 @@ readonly class PaymentManager
         return $extension->getPaymentProvider();
     }
 
-}
+}

+ 2 - 1
src/helper.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 
@@ -63,4 +64,4 @@ if (!function_exists('validate_order_number')) {
         }
         return ((10 - ($sum % 10)) % 10) == $check;
     }
-}
+}