ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } $currentAmount = bcadd($asset->amount, $amount, 2); $asset->amount = $currentAmount; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentTxBalance = $txAsset->amount; $currentTxBalance = bcadd($currentTxBalance, $amount, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); $id = $order->id; $mainId = $shop->mainId ?? 0; $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单购买 {$amount}元 订单号:{$order->orderSn}"; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } //客户充值增加余额 ssh 20240508 public static function customRechargeAddBalance($shop, $order, $capitalType, $tx) { $amount = $order->amount ?? 0; $ptStyle = $shop->ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } $currentAmount = bcadd($asset->amount, $amount, 2); $asset->amount = $currentAmount; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentTxBalance = $txAsset->amount; if ($tx == dict::getDict('yeTx', 'can')) { $currentTxBalance = bcadd($currentTxBalance, $amount, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } $sjName = $shop->merchantName ?? ''; if (isset($shop->default) == false || $shop->default != 1 || $shop->shopName != '首店') { $sjName .= ' ' . $shop->shopName; } $id = $order->id; $event = "客户向商家-{$sjName}充值,单号:{$order->orderSn}"; $mainId = $shop->mainId ?? 0; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'sjId' => $order->sjId ?? 0, 'shopId' => $order->shopId ?? 0, 'mainId' => $order->mainId ?? 0, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, 'mainId' => $mainId, ]; PtYeChangeClass::addChange($change, true); } //客户结帐增加加余额 ssh 20210729 public static function customClearAddBalance($shop, $order, $capitalType, $tx) { $amount = $order->actPrice ?? 0; $ptStyle = $shop->ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } $currentAmount = bcadd($asset->amount, $amount, 2); $asset->amount = $currentAmount; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentTxBalance = $txAsset->amount; if ($tx == dict::getDict('yeTx', 'can')) { $currentTxBalance = bcadd($currentTxBalance, $amount, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } $sjName = $shop->merchantName ?? ''; if (isset($shop->default) == false || $shop->default != 1 || $shop->shopName != '首店') { $sjName .= ' ' . $shop->shopName; } $id = $order->id; $event = "客户结帐给商家-{$sjName}(单号:{$order->orderSn})"; $mainId = $shop->mainId ?? 0; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'sjId' => $order->sjId, 'shopId' => $order->shopId, 'mainId' => $order->mainId ?? 0, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, 'mainId' => $mainId, ]; PtYeChangeClass::addChange($change, true); } //客户使用优惠券增加余额 ssh 20210601 public static function customKdUseCouponAddBalance($shop, $order, $capitalType, $tx) { $amount = $order->discountAmount; $ptStyle = $shop->ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } $currentAmount = bcadd($asset->amount, $amount, 2); $asset->amount = $currentAmount; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentTxBalance = $txAsset->amount; $currentTxBalance = bcadd($currentTxBalance, $amount, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); $id = $order->id; $mainId = $shop->mainId ?? 0; $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单(使用平台优惠券{$amount}元) 订单号:{$order->orderSn}"; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } //平台余额增加 ssh 20210519 public static function rechargeAddBalance($shop, $amount, $order, $capitalType, $tx) { $ptStyle = $shop->ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } $currentAmount = bcadd($asset->amount, $amount, 2); $asset->amount = $currentAmount; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentTxBalance = $txAsset->amount; if ($tx == dict::getDict('yeTx', 'can')) { $currentTxBalance = bcadd($currentTxBalance, $amount, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } $id = $order->id; $mainId = $shop->mainId ?? 0; $event = "【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}"; if ($order->shopAdminId == 0) { $event = "系统为【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}"; } $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'sjId' => $order->sjId, 'shopId' => $order->shopId, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } //平台余额减少 ssh 20210519 public static function reduceBalance($shop, $amount, $order, $capitalType, $tx) { $ptStyle = $shop->ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } if (bccomp($amount, $asset->amount, 2) == 1) { //util::fail('平台余额不足哦'); } $currentAmount = bcsub($asset->amount, $amount, 2); $asset->amount = $currentAmount; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentTxBalance = $txAsset->amount; if ($tx == dict::getDict('yeTx', 'can')) { if (!empty($currentTxBalance)) { $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance; $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } } $id = $order->id; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 0, 'payWay' => $order->payWay, 'event' => "【{$shop->merchantName} {$shop->shopName}】 {$amount}元 订单号:{$order->orderSn}", 'sjId' => $order->sjId, 'shopId' => $order->shopId, 'mainId' => $order->mainId ?? 0, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } //供货商预订被多付了退款减少余额 ssh 20220324 public static function ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice) { $ptStyle = $shop->ptStyle; $asset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } if (bccomp($refundPrice, $asset->amount, 2) == 1) { //util::fail('平台余额不足!'); } $currentAmount = bcsub($asset->amount, $refundPrice, 2); $asset->amount = $currentAmount; $asset->save(); $txAsset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $tx = dict::getDict('yeTx', 'can'); $currentTxBalance = $txAsset->amount; if (!empty($currentTxBalance)) { $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance; $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } $merchantName = $shop->merchantName ?? ''; if ($shop->default != 1 || $shop->shopName != '首店') { $shopName = $shop->shopName ?? ''; $merchantName = $merchantName . '-' . $shopName; } $event = "{$merchantName} 预订单被多付退还(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})"; $relateOrderSn = $refund->relateOrderSn ?? ''; if (!empty($relateOrderSn)) { $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true); $customName = $relateOrder->customName ?? ''; if (!empty($customName)) { $event = "{$merchantName} 的预订单被{$customName}多付退还(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})"; } } $id = $refund->id; $currentType = dict::getDict('capitalType', 'ghsBookRefund'); $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 0, 'payWay' => 0, 'event' => $event, 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } public static function hdSaleRefundReduceBalance($shop, $refund, $refundPrice) { $ptStyle = $shop->ptStyle; $asset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } if (bccomp($refundPrice, $asset->amount, 2) == 1) { //util::fail('平台余额不足呢'); } $currentAmount = bcsub($asset->amount, $refundPrice, 2); $asset->amount = $currentAmount; $asset->save(); $txAsset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $tx = dict::getDict('yeTx', 'can'); $currentTxBalance = $txAsset->amount; if (!empty($currentTxBalance)) { $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance; $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } $id = $refund->id; $currentType = dict::getDict('capitalType', 'hdOrderRefund'); $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 0, 'payWay' => 0, 'event' => "【{$shop->merchantName} {$shop->shopName}】的销售单发起退款", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } public static function saleRefundReduceBalance($shop, $refund, $refundPrice) { $ptStyle = $shop->ptStyle; $asset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = self::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = self::getGhsBalance(); } else { util::fail('没有找到平台'); } if (bccomp($refundPrice, $asset->amount, 2) == 1) { //util::fail('平台余额不足哈'); } $currentAmount = bcsub($asset->amount, $refundPrice, 2); $asset->amount = $currentAmount; $asset->save(); $txAsset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = self::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = self::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $tx = dict::getDict('yeTx', 'can'); $currentTxBalance = $txAsset->amount; if (!empty($currentTxBalance)) { $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance; $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2); $txAsset->amount = $currentTxBalance; $txAsset->save(); } $id = $refund->id; $currentType = dict::getDict('capitalType', 'saleRefund'); $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentAmount, 'txBalance' => $currentTxBalance, 'io' => 0, 'payWay' => 0, 'event' => "【{$shop->merchantName} {$shop->shopName}】 的销售单发起退款", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } //零售平台余额对象 ssh 20210519 public static function getHdBalance() { $hd = dict::getDict('ptAsset', 'hdBalance'); $id = $hd['id']; $name = $hd['name']; $asset = self::getLockById($id); if (empty($asset)) { $data = ['id' => $id, 'name' => $name, 'amount' => 0.00]; self::add($data); $asset = self::getLockById($id); if (empty($asset)) { util::fail('没有找到零售平台余额,请先创建'); } } return $asset; } //供货商平台余额对象 ssh 20210519 public static function getGhsBalance() { $ghs = dict::getDict('ptAsset', 'ghsBalance'); $id = $ghs['id']; $name = $ghs['name']; $asset = self::getLockById($id); if (empty($asset)) { $data = ['id' => $id, 'name' => $name, 'amount' => 0.00]; self::add($data); $asset = self::getLockById($id); if (empty($asset)) { util::fail('没有找到供货商平台余额,请先创建'); } } return $asset; } //零售平台余额对象 ssh 20210519 public static function getHdTxBalance() { $txHd = dict::getDict('ptAsset', 'hdTxBalance'); $id = $txHd['id']; $name = $txHd['name']; $asset = self::getLockById($id); if (empty($asset)) { $data = ['id' => $id, 'name' => $name, 'amount' => 0.00]; self::add($data); $asset = self::getLockById($id); if (empty($asset)) { util::fail('没有找到零售平台可提现余额,请先创建'); } } return $asset; } //供货商平台余额对象 ssh 20210519 public static function getGhsTxBalance() { $txGhs = dict::getDict('ptAsset', 'ghsTxBalance'); $id = $txGhs['id']; $name = $txGhs['name']; $asset = self::getLockById($id); if (empty($asset)) { $data = ['id' => $id, 'name' => $name, 'amount' => 0.00]; self::add($data); $asset = self::getLockById($id); if (empty($asset)) { util::fail('没有找到供货商平台可提现余额,请先创建'); } } return $asset; } //零售采购退款 public static function cgRefundAddBalance($shop, $refundPrice, $cgRefund, $currentType, $tx) { $ptStyle = $shop->ptStyle; $asset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = PtAssetClass::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = PtAssetClass::getGhsBalance(); } else { util::fail('没有找到平台'); } $currentPtBalance = bcadd($asset->amount, $refundPrice, 2); $asset->amount = $currentPtBalance; $asset->save(); $txAsset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = PtAssetClass::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = PtAssetClass::getGhsTxBalance(); } else { util::fail('没有找到平台'); } $currentPtTxBalance = $txAsset->amount; $id = $cgRefund->id; $sjId = $shop->sjId; $shopId = $shop->id; $mainId = $shop->mainId ?? 0; $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentPtBalance, 'txBalance' => $currentPtTxBalance, 'io' => 1, 'payWay' => 0, 'event' => "【{$shop->merchantName} {$shop->shopName}】的采购被退款", 'sjId' => $sjId, 'shopId' => $shopId, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } }