|
|
@@ -5,14 +5,13 @@ namespace bizHd\deduct\classes;
|
|
|
use bizHd\balance\classes\BalanceChangeClass;
|
|
|
use bizHd\balance\classes\BalanceGiveChangeClass;
|
|
|
use bizHd\balance\classes\BalancePayChangeClass;
|
|
|
+use bizHd\custom\classes\CustomClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\util;
|
|
|
-use Yii;
|
|
|
use bizHd\base\classes\BaseClass;
|
|
|
|
|
|
class DeductClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
public static $baseFile = '\bizHd\deduct\models\Deduct';
|
|
|
|
|
|
public static function doDeduct($shop, $custom, $hd, $amount, $params)
|
|
|
@@ -22,10 +21,7 @@ class DeductClass extends BaseClass
|
|
|
util::fail('余额不够扣');
|
|
|
}
|
|
|
$custom->balance = bcsub($custom->balance, $amount, 2);
|
|
|
- $custom->save();
|
|
|
-
|
|
|
$hd->balance = bcsub($hd->balance, $amount, 2);
|
|
|
- $hd->save();
|
|
|
|
|
|
if (floatval($hd->balance) != floatval($custom->balance)) {
|
|
|
util::fail('余额有问题');
|
|
|
@@ -95,10 +91,8 @@ class DeductClass extends BaseClass
|
|
|
/************************* 使用充值余额 *****************************/
|
|
|
$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,
|
|
|
@@ -129,10 +123,8 @@ class DeductClass extends BaseClass
|
|
|
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);
|
|
|
}
|
|
|
@@ -162,6 +154,29 @@ class DeductClass extends BaseClass
|
|
|
if (floatval($addBalance) != floatval($custom->balance)) {
|
|
|
util::fail('账户余额有问题!请检查哈,编号' . $customId);
|
|
|
}
|
|
|
+
|
|
|
+ // 仅对从充值余额(balancePay)扣减的部分扣积分/成长值
|
|
|
+ $changeAmount = $payAmount;
|
|
|
+ if (bccomp($changeAmount, 0, 2) === 1) {
|
|
|
+ $newIntegral = bcsub($custom->integral, $changeAmount, 2);
|
|
|
+ if (bccomp($newIntegral, 0, 2) === -1) {
|
|
|
+ $newIntegral = 0;
|
|
|
+ }
|
|
|
+ $newGrowth = bcsub($custom->growth, $changeAmount, 2);
|
|
|
+ if (bccomp($newGrowth, 0, 2) === -1) {
|
|
|
+ $newGrowth = 0;
|
|
|
+ }
|
|
|
+ $custom->integral = $newIntegral;
|
|
|
+ $custom->growth = $newGrowth;
|
|
|
+ $memberData = CustomClass::getCustomExpenseLevel($custom->growth, $mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
|
|
|
+ CustomClass::updateById($customId, [
|
|
|
+ 'member' => (int) ($memberData['level'] ?? 0),
|
|
|
+ 'memberName' => (string) ($memberData['name'] ?? ''),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $custom->save();
|
|
|
+ $hd->save();
|
|
|
}
|
|
|
|
|
|
}
|