moonsflyer пре 4 месеци
родитељ
комит
2a9f893ad8
2 измењених фајлова са 31 додато и 10 уклоњено
  1. 1 1
      app/common/logic/PayNotifyLogic.php
  2. 30 9
      app/common/service/pay/MixedPayService.php

+ 1 - 1
app/common/logic/PayNotifyLogic.php

@@ -132,7 +132,7 @@ class PayNotifyLogic extends BaseLogic
             // 记录余额流水
             AccountLogLogic::add(
                 $order['user_id'],
-                AccountLogEnum::BNW_DEC_ORDER,
+                AccountLogEnum::BNW_INC_CANCEL_ORDER,
                 AccountLogEnum::DEC,
                 $order['balance_amount'],
                 $order['sn'],

+ 30 - 9
app/common/service/pay/MixedPayService.php

@@ -25,6 +25,7 @@ use app\common\enum\AfterSaleEnum;
 use app\common\enum\AfterSaleLogEnum;
 use app\common\enum\NoticeEnum;
 use app\common\model\AfterSale;
+use app\common\model\Refund;
 use app\common\service\after_sale\AfterSaleService;
 use app\common\logic\AccountLogLogic;
 use app\common\model\User;
@@ -267,18 +268,38 @@ class MixedPayService extends BasePayService
 
             // 处理微信退款
             if ($refundWechatAmount > 0) {
-                $refundData = [
-                    'transaction_id' => $order['transaction_id'],
-                    'refund_sn' => 'mixed_refund_' . $order['sn'] . '_' . time(),
-                    'total_fee' => $wechatAmount,
-                    'refund_fee' => $refundWechatAmount,
-                ];
-
-                $result = $this->wechatPayService->refund($refundData);
+
+                $pay = new WeChatPayService($order['order_terminal']);
+                $result = $pay->refund([
+                    'transaction_id'    => $order['transaction_id'],
+                    'refund_sn'         => 'mixed_refund_' . $order['sn'] . '_' . time(),
+                    'total_fee'         => $wechatAmount,
+                    'refund_fee'        => $refundWechatAmount,
+                ]);
+
                 if ($result !== true) {
-                    throw new \Exception('微信退款失败:' . $this->wechatPayService->getError());
+                    throw new \Exception($pay->realPay()->getMessage());
                 }
 
+//                //更新退款日志记录
+//                Refund::update([
+//                    'wechat_refund_id'  => 0,
+//                    'refund_status'     => 1,
+//                    'refund_msg'        => json_encode([], JSON_UNESCAPED_UNICODE),
+//                ], ['id' => self::$refund['id']]);
+
+//                $refundData = [
+//                    'transaction_id' => $order['transaction_id'],
+//                    'refund_sn' => 'mixed_refund_' . $order['sn'] . '_' . time(),
+//                    'total_fee' => $wechatAmount,
+//                    'refund_fee' => $refundWechatAmount,
+//                ];
+//
+//                $result = $this->wechatPayService->refund($refundData);
+//                if ($result !== true) {
+//                    throw new \Exception('微信退款失败:' . $this->wechatPayService->getError());
+//                }
+
                 file_put_contents(
                     runtime_path() . 'log' . DIRECTORY_SEPARATOR . 'mixed_refund_debug_' . date('Y-m-d') . '.log',
                     "[" . date('Y-m-d H:i:s') . "] 微信退款完成: {$refundWechatAmount}" . PHP_EOL,