| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <?php
- namespace biz\sj\classes;
- use biz\pt\classes\PtAssetClass;
- use biz\pt\classes\PtYeChangeClass;
- use biz\shop\classes\MainClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopYeChangeClass;
- use bizHd\base\classes\BaseClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\util;
- class CashClass extends BaseClass
- {
- public static $baseFile = '\biz\sj\models\Cash';
- const STATUS_UN_CHECK = 1;
- const STATUS_CHECK_YES = 2;
- const STATUS_CHECK_NO = 3;
- //给代理发放佣金
- public static function sendBrokerage($shop, $cash)
- {
- $agentShopId = $shop->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();
- }
- }
|