parentShopId ?? 0; //没有上级代理不需要分佣 if (empty($agentShopId)) { return false; } $agentShop = ShopClass::getLockById($agentShopId); if (empty($agentShop)) { util::fail('没有找到代理人门店'); } $capitalType = dict::getDict('capitalType', 'brokerage', 'id'); //代理分佣获得余额收入 ShopClass::brokerageAddBalance($agentShop, $cash, $capitalType); } //获取提现费率 ssh 20210623 public static function getRate($main) { $rate = $main->rate ?? 6; $rateVal = bcdiv($rate, 1000, 4); $rateVal = floatval($rateVal); return $rateVal; } //提现记录 ssh 2021.2.21 public static function getCashList($where) { $data = self::getList('*', $where, 'addTime DESC'); return $data; } //申请提现 public static function addApply($params) { $sjId = $params['sjId'] ?? 0; $shopId = $params['shopId'] ?? 0; $shop = ShopClass::getById($shopId, true); if (empty($shopId)) { util::fail('没有找到门店1'); } $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有找到商家'); } $cashList = self::getByCondition(['mainId' => $mainId, 'status' => 1], true); if (!empty($cashList)) { util::fail('已有提现审核待审核'); } $txBalance = $main->txBalance ?? 0.00; if ($txBalance <= 0) { util::fail('可提现余额不足'); } if (bccomp($txBalance, $main->balance) == 1) { util::fail('余额有问题,总余额比可提现余额还少'); } //可提现余额减少,总余额减少,冻结金额增加 $currentTxBalance = bcsub($main->txBalance, $txBalance, 2); $main->txBalance = $currentTxBalance; $main->freezeBalance = bcadd($main->freezeBalance, $txBalance, 2); $currentBalance = bcsub($main->balance, $txBalance, 2); $main->balance = $currentBalance; $main->save(); //应转金额 $ptStyle = $shop->ptStyle; $rate = CashClass::getRate($main); $tip = bcmul($txBalance, $rate, 2); $beAmount = bcsub($txBalance, $tip, 2); $shopName = $shop->shopName ?? ''; $sjName = $shop->merchantName ?? ''; $orderSn = orderSn::getCashSn(); $params['orderSn'] = $orderSn; $params['event'] = '申请提现'; $params['sjName'] = $sjName; $params['shopName'] = $shopName; $params['amount'] = $txBalance; $params['beAmount'] = $beAmount; $params['mainId'] = $mainId; $return = self::add($params, true); $tx = dict::getDict('yeTx', 'can'); $capitalType = dict::getDict('capitalType', 'xhDrawCash', 'id'); //余额减少记录 $id = $return->id; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $txBalance, 'balance' => $currentBalance, 'txBalance' => $currentTxBalance, 'io' => 0, 'payWay' => 0, 'event' => "提现", 'sjId' => $sjId, 'shopId' => $shopId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'mainId' => $mainId ]; ShopYeChangeClass::addChange($change, true); // $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; // $currentPtTxBalance = bcsub($currentPtTxBalance, $txBalance, 2); // $txAsset->amount = $currentPtTxBalance; // $txAsset->save(); // $asset = null; // if ($ptStyle == dict::getDict('ptStyle', 'hd')) { // $asset = PtAssetClass::getHdBalance(); // } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { // $asset = PtAssetClass::getGhsBalance(); // } else { // util::fail('没有找到平台'); // } // if (bccomp($txBalance, $asset->amount, 2) == 1) { // //util::fail('平台余额不足..'); // //noticeUtil::push('商家提现,平台余额不足。商家提现:' . $txBalance . ',平台余额:' . $asset->amount, '15280215347'); // } // $currentPtBalance = bcsub($asset->amount, $txBalance, 2); // $asset->amount = $currentPtBalance; // $asset->save(); // $change = [ // 'relateId' => $id, // 'capitalType' => $capitalType, // 'amount' => $txBalance, // 'balance' => $currentPtBalance, // 'txBalance' => $currentPtTxBalance, // 'io' => 0, // 'payWay' => 0, // 'event' => "【{$shop->merchantName} {$shop->shopName}】提现", // 'sjId' => $sjId, // 'shopId' => $shopId, // 'tx' => $tx, // 'ptStyle' => $ptStyle, // 'shopName' => $shop->shopName, // 'sjName' => $shop->merchantName, // 'mainId' => $mainId // ]; // PtYeChangeClass::addChange($change, true); //noticeUtil::push("客户:{$sjName} {$shopName}申请提现,金额:{$txBalance}元", '15280215347'); return $return; } public static function rollback($cash, $shop, $transaction, $cashAmount, $remark) { $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息1'); } $cash->remark = $remark; $cash->status = self::STATUS_CHECK_NO; $cash->save(); //冻结金额回滚 $main->freezeBalance = bcsub($main->freezeBalance, $cashAmount, 2); $currentBalance = bcadd($main->balance, $cashAmount, 2); $main->balance = $currentBalance; $currentTxBalance = bcadd($main->txBalance, $cashAmount, 2); $main->txBalance = $currentTxBalance; $main->save(); $sjId = $shop->sjId; $shopId = $shop->id; $tx = dict::getDict('yeTx', 'can'); $ptStyle = $shop->ptStyle ?? dict::getDict('ptStyle', 'hd'); $capitalType = dict::getDict('capitalType', 'xhDrawCash', 'id'); //余额增加记录 $id = $cash->id; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $cashAmount, 'balance' => $currentBalance, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => 0, 'event' => "提现回滚", 'sjId' => $sjId, 'shopId' => $shopId, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, ]; ShopYeChangeClass::addChange($change, true); $txAsset = null; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = PtAssetClass::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = PtAssetClass::getGhsTxBalance(); } else { CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark); util::fail('没有找到平台'); } $currentPtTxBalance = $txAsset->amount; $currentPtTxBalance = bcadd($currentPtTxBalance, $cashAmount, 2); $txAsset->amount = $currentPtTxBalance; $txAsset->save(); $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, $cashAmount, 2); $asset->amount = $currentPtBalance; $asset->save(); $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $cashAmount, 'balance' => $currentPtBalance, 'txBalance' => $currentPtTxBalance, 'io' => 1, 'payWay' => 0, 'event' => "【{$shop->merchantName} {$shop->shopName}】提现回滚", 'sjId' => $sjId, 'shopId' => $shopId, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); $transaction->commit(); } }