|
|
@@ -3,6 +3,8 @@
|
|
|
namespace bizHd\deduct\classes;
|
|
|
|
|
|
use bizHd\balance\classes\BalanceChangeClass;
|
|
|
+use bizHd\balance\classes\BalanceGiveChangeClass;
|
|
|
+use bizHd\balance\classes\BalancePayChangeClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
@@ -77,6 +79,89 @@ class DeductClass extends BaseClass
|
|
|
'remark' => $remark,
|
|
|
];
|
|
|
BalanceChangeClass::add($change, true);
|
|
|
+
|
|
|
+ // 多处需要同步修改 balance_pay_give
|
|
|
+ if ($hd->balancePay >= $amount) {
|
|
|
+ $payAmount = $amount;
|
|
|
+ $mustUseGiveAmount = 0;
|
|
|
+ } else {
|
|
|
+ $payAmount = $hd->balancePay;
|
|
|
+ $mustUseGiveAmount = bcsub($amount, $payAmount, 2);
|
|
|
+ if ($mustUseGiveAmount > $hd->balanceGive) {
|
|
|
+ util::fail('赠送余额异常,不够扣');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /************************* 使用充值余额 *****************************/
|
|
|
+ $customBalancePay = bcsub($custom->balancePay, $payAmount, 2);
|
|
|
+ $custom->balancePay = $customBalancePay;
|
|
|
+ $custom->save();
|
|
|
+ $hdBalancePay = bcsub($hd->balancePay, $payAmount, 2);
|
|
|
+ $hd->balancePay = $hdBalancePay;
|
|
|
+ $hd->save();
|
|
|
+ $payChange = [
|
|
|
+ 'hdId' => $hdId,
|
|
|
+ 'hdName' => $hdName,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'customName' => $customName,
|
|
|
+ 'relateId' => $relateId,
|
|
|
+ 'onlinePay' => 1,
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $payAmount,
|
|
|
+ 'balance' => $customBalancePay,
|
|
|
+ 'io' => 0,
|
|
|
+ 'side' => 0,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'event' => $event,
|
|
|
+ 'staffId' => $staffId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ BalancePayChangeClass::add($payChange, true);
|
|
|
+
|
|
|
+ /***************************** 使用赠送余额 ******************************/
|
|
|
+ //应用掉的赠送金额
|
|
|
+ if ($mustUseGiveAmount > 0) {
|
|
|
+ $customBalanceGive = bcsub($custom->balanceGive, $mustUseGiveAmount, 2);
|
|
|
+ if ($customBalanceGive < 0) {
|
|
|
+ util::fail('余额异常哈!请联系管理员,编号' . $hdId . ' ' . $custom->balanceGive);
|
|
|
+ }
|
|
|
+ $custom->balanceGive = $customBalanceGive;
|
|
|
+ $custom->save();
|
|
|
+ $hdBalanceGive = bcsub($hd->balanceGive, $mustUseGiveAmount, 2);
|
|
|
+ $hd->balanceGive = $hdBalanceGive;
|
|
|
+ $hd->save();
|
|
|
+ if (floatval($customBalanceGive) != floatval($hdBalanceGive)) {
|
|
|
+ util::fail('余额有问题呢!请联系管理员,编号' . $hdId);
|
|
|
+ }
|
|
|
+ $giveChange = [
|
|
|
+ 'hdId' => $hdId,
|
|
|
+ 'hdName' => $hdName,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'customName' => $customName,
|
|
|
+ 'relateId' => $relateId,
|
|
|
+ 'onlinePay' => 1,
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $mustUseGiveAmount,
|
|
|
+ 'balance' => $customBalanceGive,
|
|
|
+ 'io' => 0,
|
|
|
+ 'side' => 0,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'event' => $event,
|
|
|
+ 'staffId' => $staffId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ BalanceGiveChangeClass::add($giveChange, true);
|
|
|
+ }
|
|
|
+ $addBalance = bcadd($hd->balancePay, $hd->balanceGive, 2);
|
|
|
+ if (floatval($addBalance) != floatval($custom->balance)) {
|
|
|
+ util::fail('账户余额有问题!请检查哈,编号' . $customId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|