|
|
@@ -673,6 +673,85 @@ class CustomClass extends BaseClass
|
|
|
self::assertPairBalanceEqual($custom, $ghs);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 花店采购余额付售后:成对账户原路退回(与 payToChangeBalance 对称)。
|
|
|
+ * 调用方须已 lockAccountPair;同时写客户余额明细与 xhGhs 余额明细(hdApp 可查)。
|
|
|
+ */
|
|
|
+ public static function refundBalancePayToPair($custom, $ghs, $refund, $order)
|
|
|
+ {
|
|
|
+ AccountMoneyClass::ensureCustomMoneyReady($custom, true);
|
|
|
+ if (!empty($ghs)) {
|
|
|
+ AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
|
|
|
+ self::assertPairBalanceEqual($custom, $ghs);
|
|
|
+ }
|
|
|
+ $refundPrice = bcadd((string)($refund->refundPrice ?? '0'), '0', 2);
|
|
|
+ if (bccomp($refundPrice, '0', 2) <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $newBalance = bcadd((string)($custom->balance ?? '0'), $refundPrice, 2);
|
|
|
+ self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
|
|
|
+
|
|
|
+ $relateId = $refund->id ?? 0;
|
|
|
+ $customId = $custom->id ?? 0;
|
|
|
+ $customName = $custom->name ?? '';
|
|
|
+ $saleOrderSn = $order->orderSn ?? '';
|
|
|
+ $capitalType = dict::getDict('capitalType', 'saleRefund', 'id');
|
|
|
+ $payTime = $order->payTime ?? '';
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $relateId,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'customName' => $customName,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $refundPrice,
|
|
|
+ 'balance' => $newBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => dict::getDict('payWay', 'balancePay'),
|
|
|
+ 'event' => "订单售后退款,单号:{$saleOrderSn}",
|
|
|
+ 'sjId' => $refund->sjId ?? 0,
|
|
|
+ 'shopId' => $refund->shopId ?? 0,
|
|
|
+ 'mainId' => $order->mainId ?? 0,
|
|
|
+ 'payTime' => $payTime,
|
|
|
+ 'staffId' => 0,
|
|
|
+ 'staffName' => '',
|
|
|
+ 'side' => 0,
|
|
|
+ 'fromType' => dict::getDict('fromType', 'shop'),
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ CustomBalanceChangeClass::add($change, true);
|
|
|
+ self::addGhsRefundBalanceChange($custom, $ghs, $refund, $order, $refundPrice, $newBalance);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 花店采购余额退款:记 xhGhs 余额变动(与 addGhsOrderBalanceChange 对称,hdApp 余额明细展示) */
|
|
|
+ protected static function addGhsRefundBalanceChange($custom, $ghs, $refund, $order, $amount, $newBalance)
|
|
|
+ {
|
|
|
+ if (empty($ghs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $orderSn = $order->orderSn ?? '';
|
|
|
+ $customShopId = $custom->shopId ?? 0;
|
|
|
+ $customShop = ShopClass::getById($customShopId, true);
|
|
|
+ $gbData = [
|
|
|
+ 'ghsId' => $ghs->id ?? 0,
|
|
|
+ 'relateId' => $refund->id ?? 0,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => dict::getDict('capitalType', 'saleRefund', 'id'),
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $newBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'side' => 0,
|
|
|
+ 'onlinePay' => 1,
|
|
|
+ 'payWay' => dict::getDict('payWay', 'balancePay'),
|
|
|
+ 'fromType' => dict::getDict('fromType', 'shop'),
|
|
|
+ 'event' => "订单售后退款,单号:{$orderSn}",
|
|
|
+ 'sjId' => $customShop->sjId ?? ($custom->sjId ?? 0),
|
|
|
+ 'mainId' => $customShop->mainId ?? 0,
|
|
|
+ 'shopId' => $customShopId,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ GhsBalanceChangeClass::add($gbData, true);
|
|
|
+ }
|
|
|
+
|
|
|
protected static function addGhsOrderBalanceChange($custom, $ghs, $order, $amount, $newBalance, $bookOrder = false)
|
|
|
{
|
|
|
if (empty($ghs)) {
|