|
|
@@ -2,9 +2,13 @@
|
|
|
|
|
|
namespace biz\shop\classes;
|
|
|
|
|
|
+use biz\ghs\classes\GhsClass;
|
|
|
+use biz\pt\classes\PtAssetClass;
|
|
|
+use biz\sj\classes\SjClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
use bizHd\admin\classes\ShopAdminClass;
|
|
|
use biz\sj\classes\MerchantClass;
|
|
|
+use common\components\dict;
|
|
|
use common\components\dirUtil;
|
|
|
use common\components\httpUtil;
|
|
|
use common\components\imgUtil;
|
|
|
@@ -141,16 +145,121 @@ class ShopClass extends BaseClass
|
|
|
return $gatheringCode;
|
|
|
}
|
|
|
|
|
|
- //增加余额 ssh 2021.2.21
|
|
|
- //$fix = false 余额使用时不需要指定在谁那边用
|
|
|
- public static function addBalance($shop, $amount, $fix = false)
|
|
|
+ //门店增加余额 ssh 2021.2.21
|
|
|
+ //$fix = true 余额只能在指定门店使用
|
|
|
+ public static function addBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
|
|
|
{
|
|
|
- $shop->balance += $amount;
|
|
|
+ //门店余额增加
|
|
|
+ $currentBalance = bcadd($shop->balance, $amount, 2);
|
|
|
+ $shop->balance = $currentBalance;
|
|
|
$shop->totalRecharge += $amount;
|
|
|
+ //定向消费余额
|
|
|
if ($fix) {
|
|
|
- $shop->fixBalance += $amount;
|
|
|
+ $currentFix = bcadd($shop->fixBalance, $amount, 2);
|
|
|
+ $shop->fixBalance = $currentFix;
|
|
|
+ }
|
|
|
+ $currentTx = $shop->txBalance;
|
|
|
+ //提现余额
|
|
|
+ if ($tx == dict::getDict('yeTx', 'can')) {
|
|
|
+ $currentTx = bcadd($shop->txBalance, $amount, 2);
|
|
|
+ $shop->txBalance = $currentTx;
|
|
|
+ }
|
|
|
+ $shop->save();
|
|
|
+
|
|
|
+ //增加余额变动记录
|
|
|
+ $id = $order->id;
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $id,
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $currentBalance,
|
|
|
+ 'txBalance' => $currentTx,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => $order->payWay,
|
|
|
+ 'event' => "充值{$amount}元",
|
|
|
+ 'sjId' => $order->sjId,
|
|
|
+ 'shopId' => $order->shopId,
|
|
|
+ 'tx' => $tx,
|
|
|
+ ];
|
|
|
+ ShopYeChangeClass::addChange($change, true);
|
|
|
+
|
|
|
+ //平台余额增加
|
|
|
+ PtAssetClass::addBalance($shop, $amount, $order, $capitalType, $tx);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //采购余额付款,减少余额 shish 20210519
|
|
|
+ public static function purchaseReduceBalance($shop, $amount, $order)
|
|
|
+ {
|
|
|
+ if (bccomp($amount, $shop->balance, 2) == 1) {
|
|
|
+ util::fail('余额不足');
|
|
|
+ }
|
|
|
+ $sjId = $order->sjId;
|
|
|
+ $shopId = $order->shopId;
|
|
|
+
|
|
|
+ //定向消费余额
|
|
|
+ $currentFixBalance = $shop->fixBalance;
|
|
|
+ $ghsId = $order->ghsId;
|
|
|
+ $ghs = GhsClass::getById($ghsId, true);
|
|
|
+ if (empty($ghs)) {
|
|
|
+ util::fail('没有找到供货商');
|
|
|
+ }
|
|
|
+
|
|
|
+ //找出推荐人
|
|
|
+ $ghsSjId = $ghs->sjId;
|
|
|
+ $parentShopId = SjClass::getParentShopId($sjId);
|
|
|
+
|
|
|
+ //指定消费判断
|
|
|
+ if ($ghsSjId != $parentShopId) {
|
|
|
+ //如果不是在自己推荐人那边采购,需确认扣掉定向消费余额后还够不够扣
|
|
|
+ $notFixBalance = bcsub($shop->balance, $currentFixBalance, 2);
|
|
|
+ if (bccomp($amount, $notFixBalance, 2) == 1) {
|
|
|
+ util::fail('充值余额只能在介绍您的门店消费');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //需要扣掉的定向消费余额,不够本次扣时全部扣掉
|
|
|
+ if ($currentFixBalance > 0) {
|
|
|
+ $reduceFix = $currentFixBalance > $amount ? $amount : $currentFixBalance;
|
|
|
+ $shop->fixBalance = bcsub($currentFixBalance, $reduceFix, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $currentBalance = bcsub($shop->balance, $amount, 2);
|
|
|
+ $shop->balance = $currentBalance;
|
|
|
+
|
|
|
+ $tx = dict::getDict('yeTx', 'canNot');
|
|
|
+
|
|
|
+ //还有可提现余额也要先用掉
|
|
|
+ $currentTxBalance = $shop->txBalance;
|
|
|
+ if ($currentTxBalance > 0) {
|
|
|
+ $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
|
|
|
+ $shop->txBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
|
|
|
+ $tx = dict::getDict('yeTx', 'can');
|
|
|
}
|
|
|
$shop->save();
|
|
|
+
|
|
|
+ $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
|
|
|
+
|
|
|
+ //增加余额变动记录
|
|
|
+ $id = $order->id;
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $id,
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $currentBalance,
|
|
|
+ 'txBalance' => $currentTxBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => $order->payWay,
|
|
|
+ 'event' => "余额支付{$amount}元",
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'tx' => $tx,
|
|
|
+ ];
|
|
|
+ ShopYeChangeClass::addChange($change, true);
|
|
|
+
|
|
|
+ //平台余额增加
|
|
|
+ PtAssetClass::reduceBalance($shop, $amount, $order, $capitalType, $tx);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//获取商家所有的门店 ssh 2021.2.26
|