Procházet zdrojové kódy

2024/3/31 23:09:30

萤火科技 před 1 rokem
rodič
revize
fda2578699

+ 1 - 0
app/api/model/Order.php

@@ -18,6 +18,7 @@ use app\common\model\Order as OrderModel;
 use app\common\service\{Order as OrderService, order\Complete as OrderCompleteService};
 use app\common\enum\{
     Setting as SettingEnum,
+    payment\Method as PaymentMethodEnum,
     order\PayStatus as PayStatusEnum,
     order\OrderStatus as OrderStatusEnum,
     order\DeliveryType as DeliveryTypeEnum,

+ 1 - 1
app/api/service/Recharge.php

@@ -76,7 +76,7 @@ class Recharge extends BaseService
         $planList = $PlanModel->getList();
         // 根据指定客户端获取可用的支付方式
         $PaymentModel = new PaymentModel;
-        $methods = $PaymentModel->getMethodsByClient($client, false);
+        $methods = $PaymentModel->getMethodsByClient($client, true);
         // 充值设置
         $setting = SettingModel::getRecharge();
         // 返回数据

+ 8 - 2
app/api/service/cashier/Payment.php

@@ -171,8 +171,14 @@ class Payment extends BaseService
      */
     private function recordPaymentTrade(array $payment): void
     {
-        if ($this->method != PaymentMethodEnum::BALANCE) {
-            PaymentTradeModel::record($this->orderInfo, $this->method, $this->client, OrderTypeEnum::ORDER, $payment);
+        if (!in_array($this->method, [PaymentMethodEnum::BALANCE])) {
+            PaymentTradeModel::record(
+                $this->orderInfo,
+                $this->method,
+                $this->client,
+                OrderTypeEnum::ORDER,
+                $payment
+            );
         }
     }
 

+ 2 - 2
app/api/service/order/PaySuccess.php

@@ -222,7 +222,7 @@ class PaySuccess extends BaseService
         // 当前订单信息
         $orderInfo = $this->getOrderInfo();
         // 余额支付直接返回错误信息
-        if ($this->method == PaymentMethodEnum::BALANCE) {
+        if (in_array($this->method, [PaymentMethodEnum::BALANCE])) {
             throwError('当前订单已支付,无需重复支付');
         }
         // 第三方支付判断是否为重复下单 (因异步回调可能存在网络延迟的原因,在并发的情况下会出现同时付款两次,这里需要容错)
@@ -245,7 +245,7 @@ class PaySuccess extends BaseService
         // 当前订单信息
         $orderInfo = $this->getOrderInfo();
         // 余额支付无需退款 (因为是同步执行)
-        if ($this->method === PaymentMethodEnum::BALANCE) {
+        if (in_array($this->method, [PaymentMethodEnum::BALANCE])) {
             return;
         }
         // 执行第三方支付原路退款

+ 1 - 1
app/api/service/recharge/Payment.php

@@ -151,7 +151,7 @@ class Payment extends BaseService
      */
     private function recordPaymentTrade(array $payment): void
     {
-        if ($this->method != PaymentMethodEnum::BALANCE) {
+        if (!in_array($this->method, [PaymentMethodEnum::BALANCE])) {
             PaymentTradeModel::record(
                 $this->orderInfo,
                 $this->method,

+ 1 - 0
app/common/model/Order.php

@@ -15,6 +15,7 @@ namespace app\common\model;
 use cores\BaseModel;
 use app\common\service\Order as OrderService;
 use app\common\enum\order\PayStatus as PayStatusEnum;
+use app\common\enum\payment\Method as PaymentMethodEnum;
 use app\common\enum\order\OrderStatus as OrderStatusEnum;
 use app\common\enum\order\ReceiptStatus as ReceiptStatusEnum;
 use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;

+ 9 - 5
app/common/model/Payment.php

@@ -242,7 +242,7 @@ class Payment extends BaseModel
             $defaultMethods["{$client}-{$method}"] = array_merge($record, [
                 'key' => $key + 1,
                 'method' => $method,
-                'is_must_template' => $method != PaymentMethodEnum::BALANCE,
+                'is_must_template' => !\in_array($method, [PaymentMethodEnum::BALANCE]),
                 'is_enable' => $method == PaymentMethodEnum::BALANCE,
             ]);
         }
@@ -269,7 +269,7 @@ class Payment extends BaseModel
     /**
      * 根据指定客户端获取可用的支付方式
      * @param string $client 客户端来源
-     * @param bool $balance 是否支持余额支付
+     * @param bool $isRecharge 是否用于余额充值
      * @param int|null $storeId 商城ID
      * @return array
      * @throws \think\db\exception\DataNotFoundException
@@ -277,13 +277,17 @@ class Payment extends BaseModel
      * @throws \think\db\exception\ModelNotFoundException
      * @throws BaseException
      */
-    public function getMethodsByClient(string $client, bool $balance = true, int $storeId = null): array
+    public function getMethodsByClient(string $client, bool $isRecharge = false, int $storeId = null): array
     {
         $storeId = $storeId ?: self::$storeId;
         $group = static::getItem($client, $storeId);
         $methods = [];
         foreach ($group['methods'] as $method) {
-            if ($method['is_enable'] && ($balance || $method['method'] !== PaymentMethodEnum::BALANCE)) {
+            if ($method['is_enable']) {
+                // 条件: 余额充值时余额支付和线下支付不可用
+                if ($isRecharge && \in_array($method['method'], [PaymentMethodEnum::BALANCE])) {
+                    continue;
+                }
                 $methods[] = $method;
             }
         }
@@ -337,7 +341,7 @@ class Payment extends BaseModel
      */
     private function getCurrentMethod(string $method, string $client, int $storeId = null)
     {
-        $methods = $this->getMethodsByClient($client, true, $storeId);
+        $methods = $this->getMethodsByClient($client, false, $storeId);
         $method = helper::arraySearch($methods, 'method', $method);
         if (empty($method)) {
             throwError('很抱歉,当前未找到指定的支付方式');