萤火科技 1 жил өмнө
parent
commit
743df1d8af

+ 1 - 1
app/api/common.php

@@ -19,7 +19,7 @@ declare (strict_types=1);
 function getPlatform(): ?string
 {
     static $value = null;
-    // 从header中获取 channel
+    // 从header中获取 platform
     empty($value) && $value = request()->header('platform');
     // 调试模式下可通过param中获取
     if (is_debug() && empty($value)) {

+ 28 - 1
app/api/model/PaymentTrade.php

@@ -14,6 +14,7 @@ namespace app\api\model;
 
 use app\common\model\PaymentTrade as PaymentTradeModel;
 use app\common\enum\payment\trade\TradeStatus as TradeStatusEnum;
+use cores\exception\BaseException;
 
 /**
  * 模型类:第三方支付交易记录
@@ -61,8 +62,34 @@ class PaymentTrade extends PaymentTradeModel
             'user_id' => $orderInfo['user_id'],
             'out_trade_no' => $payment['out_trade_no'] ?? '',
             'prepay_id' => $payment['prepay_id'] ?? '',
-            'trade_status' => TradeStatusEnum::NOTPAY,
+            'trade_status' => TradeStatusEnum::UNPAID,
             'store_id' => self::$storeId,
         ]);
     }
+
+    /**
+     * 根据订单ID查询记录
+     * @param int $orderId 订单ID
+     * @param int $orderType 订单类型
+     * @return static|array|\think\Model|null
+     * @throws BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    private function detailByOrderId(int $orderId, string $method, string $client, int $orderType)
+    {
+        $detail = $this->where('order_id', '=', $orderId)
+            ->where('order_type', '=', $orderType)
+            ->where('client', '=', $client)
+            ->where('pay_method', '=', $method)
+            ->find();
+        if (empty($detail)) {
+            return null;
+        }
+        if (\in_array($detail['trade_state'], [TradeStatusEnum::SUCCESS, TradeStatusEnum::REFUND])) {
+            throwError('该支付订单已完成交易');
+        }
+        return $detail;
+    }
 }

+ 6 - 6
app/common/enum/payment/trade/TradeStatus.php

@@ -22,7 +22,7 @@ use app\common\enum\EnumBasics;
 class TradeStatus extends EnumBasics
 {
     // 未支付
-    const NOTPAY = 10;
+    const UNPAID = 10;
 
     // 支付成功
     const SUCCESS = 20;
@@ -40,21 +40,21 @@ class TradeStatus extends EnumBasics
     public static function data(): array
     {
         return [
-            self::NOTPAY => [
+            self::UNPAID => [
                 'name' => '未支付',
-                'value' => self::NOTPAY,
+                'value' => self::UNPAID
             ],
             self::SUCCESS => [
                 'name' => '支付成功',
-                'value' => self::SUCCESS,
+                'value' => self::SUCCESS
             ],
             self::REFUND => [
                 'name' => '转入退款',
-                'value' => self::REFUND,
+                'value' => self::REFUND
             ],
             self::CLOSED => [
                 'name' => '已关闭',
-                'value' => self::CLOSED,
+                'value' => self::CLOSED
             ]
         ];
     }

+ 1 - 27
app/common/model/PaymentTrade.php

@@ -36,7 +36,7 @@ class PaymentTrade extends BaseModel
      */
     public static function detail($where)
     {
-        return self::get($where);
+        return static::get($where);
     }
 
     /**
@@ -77,30 +77,4 @@ class PaymentTrade extends BaseModel
     {
         return static::updateBase(['trade_state' => TradeStatusEnum::REFUND], $tradeId);
     }
-
-    /**
-     * 根据商户订单号查询记录
-     * @param int $orderId 订单ID
-     * @param int $orderType 订单类型
-     * @return \app\api\model\PaymentTrade|array|\think\Model|null
-     * @throws BaseException
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    protected function detailByOrderId(int $orderId, string $method, string $client, int $orderType)
-    {
-        $detail = $this->where('order_id', '=', $orderId)
-            ->where('order_type', '=', $orderType)
-            ->where('client', '=', $client)
-            ->where('pay_method', '=', $method)
-            ->find();
-        if (empty($detail)) {
-            return null;
-        }
-        if (in_array($detail['trade_state'], [TradeStatusEnum::SUCCESS, TradeStatusEnum::REFUND])) {
-            throwError('商户订单号 out_trade_no 已存在');
-        }
-        return $detail;
-    }
 }