Browse Source

充值、扫码付款订单确认收货回调

ouyang 1 day ago
parent
commit
1731a8a934
1 changed files with 71 additions and 0 deletions
  1. 71 0
      biz/shop/classes/ShopClass.php

+ 71 - 0
biz/shop/classes/ShopClass.php

@@ -570,6 +570,77 @@ class ShopClass extends BaseClass
         //PtAssetClass::customKdAddBalance($shop, $amount, $order, $capitalType, $tx);
     }
 
+    /**
+     * mallApp 微信支付成功:只加 wxFreezeBalance,不改 balance/txBalance。
+     * 微信实际仍冻款,此时入账会导致店铺提前提现。
+     * app-pt 结算/退款解冻依赖本方法,需与 hhb 保持一致。
+     */
+    public static function wxPayFreezeBalance($main, $shop, $amount, $order, $capitalType, $event)
+    {
+        $amount = bcadd((string)$amount, '0', 2);
+        if (bccomp($amount, '0', 2) <= 0) {
+            return;
+        }
+        if (is_array($capitalType)) {
+            $capitalType = (int)($capitalType['id'] ?? 0);
+        }
+        $currentFreeze = bcadd((string)($main->wxFreezeBalance ?? '0'), $amount, 2);
+        $main->wxFreezeBalance = $currentFreeze;
+        $main->save();
+
+        $relateId = (int)($order->id ?? 0);
+        WxFreezeChangeClass::addChange([
+            'capitalType' => (int)$capitalType,
+            'relateId' => $relateId,
+            'orderSn' => (string)($order->orderSn ?? ''),
+            'io' => 1,
+            'amount' => $amount,
+            'wxFreezeBalance' => $currentFreeze,
+            'event' => mb_substr((string)$event, 0, 200),
+            'mainId' => (int)($shop->mainId ?? 0),
+            'shopId' => (int)($shop->id ?? 0),
+            'sjId' => (int)($shop->sjId ?? 0),
+            'addTime' => date('Y-m-d H:i:s'),
+        ]);
+    }
+
+    /**
+     * 未入账售后退款/结算入账前:只减 wxFreezeBalance,写解冻明细,不减 balance。
+     * 冻结不足说明支付冻结未落或已被结算,调用方应改走扣余额。
+     */
+    public static function wxPayUnfreezeBalance($main, $shop, $amount, $refund, $capitalType, $event, $orderSn)
+    {
+        $amount = bcadd((string)$amount, '0', 2);
+        if (bccomp($amount, '0', 2) <= 0) {
+            return;
+        }
+        if (is_array($capitalType)) {
+            $capitalType = (int)($capitalType['id'] ?? 0);
+        }
+        $currentFreeze = bcadd((string)($main->wxFreezeBalance ?? '0'), '0', 2);
+        if (bccomp($amount, $currentFreeze, 2) === 1) {
+            util::fail('微信待结算冻结不足');
+        }
+        $currentFreeze = bcsub($currentFreeze, $amount, 2);
+        $main->wxFreezeBalance = $currentFreeze;
+        $main->save();
+
+        $relateId = (int)(is_object($refund) ? ($refund->id ?? 0) : ($refund['id'] ?? 0));
+        WxFreezeChangeClass::addChange([
+            'capitalType' => (int)$capitalType,
+            'relateId' => $relateId,
+            'orderSn' => (string)$orderSn,
+            'io' => 0,
+            'amount' => $amount,
+            'wxFreezeBalance' => $currentFreeze,
+            'event' => mb_substr((string)$event, 0, 200),
+            'mainId' => (int)($shop->mainId ?? 0),
+            'shopId' => (int)($shop->id ?? 0),
+            'sjId' => (int)($shop->sjId ?? 0),
+            'addTime' => date('Y-m-d H:i:s'),
+        ]);
+    }
+
     public static function customScanPayAddBalance($main, $shop, $amount, $order, $capitalType)
     {
         //门店余额增加