|
|
@@ -5,8 +5,12 @@ namespace console\controllers;
|
|
|
use bizGhs\cg\classes\CgClass;
|
|
|
use bizGhs\custom\classes\CustomBalanceChangeClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
+use bizGhs\custom\classes\CustomDebtChangeClass;
|
|
|
use bizHd\ghs\classes\GhsClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
+use common\components\dict;
|
|
|
+use bizGhs\ghs\classes\GhsBalanceChangeClass;
|
|
|
+use bizHd\ghs\classes\GhsDebtChangeClass;
|
|
|
use yii\console\Controller;
|
|
|
use Yii;
|
|
|
|
|
|
@@ -21,7 +25,7 @@ class BalanceUnmergeController extends Controller
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
|
|
|
- $customBalanceList = CustomBalanceChangeClass::getAllByCondition(['capitalType' => 81, 'id>' => 233058], null, '*', null, true);
|
|
|
+ $customBalanceList = CustomBalanceChangeClass::getAllByCondition(['capitalType' => 81], null, '*', null, true);
|
|
|
if (!empty($customBalanceList)) {
|
|
|
foreach ($customBalanceList as $customBalance) {
|
|
|
$customBalanceId = $customBalance->id ?? 0;
|
|
|
@@ -37,6 +41,11 @@ class BalanceUnmergeController extends Controller
|
|
|
|
|
|
$beforeBalance = $before->balance ?? 0;
|
|
|
|
|
|
+ if($customId == 25695){
|
|
|
+ //小吉要补3000
|
|
|
+ $beforeBalance = bcadd($beforeBalance, 3000, 2);
|
|
|
+ }
|
|
|
+
|
|
|
$ghsId = $custom->ghsId ?? 0;
|
|
|
$ghs = GhsClass::getById($ghsId, true);
|
|
|
if (empty($ghs)) {
|
|
|
@@ -66,7 +75,7 @@ class BalanceUnmergeController extends Controller
|
|
|
$debtAmount = 0;
|
|
|
if (!empty($cgList)) {
|
|
|
foreach ($cgList as $cg) {
|
|
|
- $currentDebt = $cg->remainDebtPrice;
|
|
|
+ $currentDebt = $cg->actPrice;
|
|
|
$debtAmount = bcadd($debtAmount, $currentDebt, 2);
|
|
|
}
|
|
|
}
|
|
|
@@ -82,10 +91,7 @@ class BalanceUnmergeController extends Controller
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
- if($customId == 25695){
|
|
|
- //小吉要补3000
|
|
|
- $beforeBalance = bcadd($beforeBalance, 3000, 2);
|
|
|
- }
|
|
|
+ //continue;
|
|
|
|
|
|
$custom->debtAmount = $debtAmount;
|
|
|
$custom->balanceMerged = 0;
|
|
|
@@ -96,6 +102,89 @@ class BalanceUnmergeController extends Controller
|
|
|
$ghs->balanceMerged = 0;
|
|
|
$ghs->balance = $beforeBalance;
|
|
|
$ghs->save();
|
|
|
+
|
|
|
+ // 增加 余额和欠款金额 变动记录,event说明用:系统升级恢复
|
|
|
+ $capitalType = dict::getDict('capitalType', 'balanceMerge', 'id');
|
|
|
+
|
|
|
+ // 1. 写入客户余额变动明细(CustomBalanceChange)
|
|
|
+ $cbData = [
|
|
|
+ 'customId' => $custom->id ?? 0,
|
|
|
+ 'customName' => $custom->name ?? '',
|
|
|
+ 'relateId' => 0,
|
|
|
+ 'onlinePay' => 0,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => 10,
|
|
|
+ 'amount' => bcsub($beforeBalance, $customBalance->balance ?? 0, 2), // 变化金额 = 恢复后的余额 - 之前的余额
|
|
|
+ 'balance' => $beforeBalance,
|
|
|
+ 'staffId' => 0,
|
|
|
+ 'staffName' => '',
|
|
|
+ 'io' => 1,
|
|
|
+ 'side' => 0,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'fromType' => dict::getDict('fromType', 'shop'),
|
|
|
+ 'event' => '系统升级恢复',
|
|
|
+ 'mainId' => $ghs->mainId ?? 0,
|
|
|
+ 'shopId' => $ghs->shopId ?? 0,
|
|
|
+ 'sjId' => $ghs->sjId ?? 0,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ CustomBalanceChangeClass::add($cbData, true);
|
|
|
+
|
|
|
+ // 2. 写入供货商余额变动明细(GhsBalanceChange)
|
|
|
+ $gbData = [
|
|
|
+ 'ghsId' => $ghs->id ?? 0,
|
|
|
+ 'relateId' => 0,
|
|
|
+ 'ptStyle' => 1,
|
|
|
+ 'capitalType' => 11,
|
|
|
+ 'amount' => bcsub($beforeBalance, $customBalance->balance ?? 0, 2), // 变化金额 = 恢复后的余额 - 之前的余额
|
|
|
+ 'balance' => $beforeBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'side' => 0,
|
|
|
+ 'onlinePay' => 0,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'fromType' => dict::getDict('fromType', 'shop'),
|
|
|
+ 'event' => '系统升级恢复',
|
|
|
+ 'mainId' => $custom->mainId ?? 0,
|
|
|
+ 'shopId' => $custom->shopId ?? 0,
|
|
|
+ 'sjId' => $custom->sjId ?? 0,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ GhsBalanceChangeClass::add($gbData, true);
|
|
|
+
|
|
|
+ // 3. 写入客户欠款挂账变动明细(CustomDebtChangeClass)
|
|
|
+ $cdcData = [
|
|
|
+ 'customId' => $custom->id ?? 0,
|
|
|
+ 'customName' => $custom->name ?? '',
|
|
|
+ 'relateId' => 0,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => 20, // 20 对应 结账/变动
|
|
|
+ 'amount' => $debtAmount,
|
|
|
+ 'balance' => $debtAmount,
|
|
|
+ 'io' => 0, // 0 对应增加欠款
|
|
|
+ 'event' => '系统升级恢复',
|
|
|
+ 'mainId' => $ghs->mainId ?? 0,
|
|
|
+ 'shopId' => $ghs->shopId ?? 0,
|
|
|
+ 'sjId' => $ghs->sjId ?? 0,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ CustomDebtChangeClass::addChange($cdcData);
|
|
|
+
|
|
|
+ // 4. 写入供货商欠款挂账变动明细(GhsDebtChangeClass)
|
|
|
+ $gdcData = [
|
|
|
+ 'ghsId' => $ghs->id ?? 0,
|
|
|
+ 'ptStyle' => 1,
|
|
|
+ 'capitalType' => 20, // 20 对应 结账/变动
|
|
|
+ 'amount' => $debtAmount,
|
|
|
+ 'balance' => $debtAmount,
|
|
|
+ 'io' => 0, // 0 对应增加欠款
|
|
|
+ 'event' => '系统升级恢复',
|
|
|
+ 'mainId' => $custom->mainId ?? 0,
|
|
|
+ 'shopId' => $custom->shopId ?? 0,
|
|
|
+ 'sjId' => $custom->sjId ?? 0,
|
|
|
+ 'remark' => '',
|
|
|
+ ];
|
|
|
+ GhsDebtChangeClass::addChange($gdcData);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|