Просмотр исходного кода

Merge branch 'master' into dev

shish 2 месяцев назад
Родитель
Сommit
080b550a09

+ 2 - 1
app-ghs/controllers/TestController.php

@@ -497,7 +497,8 @@ class TestController extends BaseController
             //['name' => '张家口小武鲜花批发', 'merchantNo' => '82213805992007R', 'wx' => [894997028, 894996929], 'zfb' => '2088680439799041'],
             //['name' => '淮北花述语鲜花批发', 'merchantNo' => '82236605992001E', 'wx' => [895627520, 895627914], 'zfb' => '2088680541422679'],
             //['name' => '泉州馨喜鲜花批发', 'merchantNo' => '8223970599200KD', 'wx' => [896099124, 896098673], 'zfb' => '2088680670320387'],
-            ['name' => '东莞石龙我要花', 'merchantNo' => '8226020599200RC', 'wx' => [896365688, 896365294], 'zfb' => '2088680722085035'],
+            //['name' => '东莞石龙我要花', 'merchantNo' => '8226020599200RC', 'wx' => [896365688, 896365294], 'zfb' => '2088680722085035'],
+            ['name' => '昆明花满禾鲜花', 'merchantNo' => '82273105992012G', 'wx' => [898442463, 898442140], 'zfb' => '2088780050977551'],
             //['name' => '厦门纯彩花艺', 'merchantNo' => '8223930599200LD', 'wx' => [894984230, 894983290], 'zfb' => '2088680439152343'],
             //['name' => '东莞我要花鲜花', 'merchantNo' => '8226020599200R8', 'wx' => [894794554, 894794917], 'zfb' => '2088680405463378'],
             //['name' => '镇江花珩鲜花批发', 'merchantNo' => '82231405992003N', 'wx' => [894925711, 894925626], 'zfb' => '2088680426877183'],

+ 197 - 0
console/controllers/BalanceUnmergeController.php

@@ -0,0 +1,197 @@
+<?php
+
+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;
+
+class BalanceUnmergeController extends Controller
+{
+
+
+    public function actionRun()
+    {
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $customBalanceList = CustomBalanceChangeClass::getAllByCondition(['capitalType' => 81], null, '*', null, true);
+            if (!empty($customBalanceList)) {
+                foreach ($customBalanceList as $customBalance) {
+                    $customBalanceId = $customBalance->id ?? 0;
+                    $customId = $customBalance->customId ?? 0;
+                    $custom = CustomClass::getById($customId, true);
+                    if (empty($custom)) {
+                        echo $customId . " 没有客户信息";
+                        exit();
+                    }
+                    $customName = $custom->name ?? '';
+
+                    $before = CustomBalanceChangeClass::getByCondition(['customId' => $customId, 'id<' => $customBalanceId],true,'id desc' );
+
+                    $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)) {
+                        echo $customId . " 客户供货商信息没有";
+                        exit();
+                    }
+                    $ghsName = $ghs->name ?? '';
+                    $ownPtStyle = $ghs->ownPtStyle ?? 1;
+                    if ($ownPtStyle == 1) {
+                        $cgList = PurchaseClass::getAllByCondition(['ghsId' => $ghsId, 'debt' => 1], null, '*', null, true);
+                        $debtAmount = 0;
+                        if (!empty($cgList)) {
+                            foreach ($cgList as $cg) {
+                                $currentDebt = $cg->remainDebtPrice;
+                                $debtAmount = bcadd($debtAmount, $currentDebt, 2);
+                            }
+                        }
+                        $has = CustomBalanceChangeClass::getAllByCondition(['customId' => $customId, 'id>' => $customBalanceId], null, '*', null, true);
+                        $hasCount = count($has);
+                        if ($hasCount > 0) {
+                            echo $customName . "({$ghsName}){$customId} 要恢复欠款:" . $debtAmount . " 余额:" . $beforeBalance . " 合并之后还有余额变动{$hasCount}条" . " ------ \n";
+                        } else {
+                            echo $customName . "({$ghsName}){$customId} 要恢复欠款:" . $debtAmount . " 余额:" . $beforeBalance . " ------ \n";
+                        }
+                    } elseif ($ownPtStyle == 2) {
+                        $cgList = CgClass::getAllByCondition(['ghsId' => $ghsId, 'debt' => 1], null, '*', null, true);
+                        $debtAmount = 0;
+                        if (!empty($cgList)) {
+                            foreach ($cgList as $cg) {
+                                $currentDebt = $cg->actPrice;
+                                $debtAmount = bcadd($debtAmount, $currentDebt, 2);
+                            }
+                        }
+                        $has = CustomBalanceChangeClass::getAllByCondition(['customId' => $customId, 'id>' => $customBalanceId], null, '*', null, true);
+                        $hasCount = count($has);
+                        if ($hasCount > 0) {
+                            echo $customName . "({$ghsName}){$customId}【供货商端】要恢复欠款:" . $debtAmount . " 余额:" . $beforeBalance . " 合并之后还有余额变动{$hasCount}条" . " $$$$$$$ \n";
+                        } else {
+                            echo $customName . "({$ghsName}){$customId}【供货商端】要恢复欠款:" . $debtAmount . " 余额:" . $beforeBalance . " $$$$$$$ \n";
+                        }
+                    } else {
+                        echo $customId . " 客户ptStyle有问题" . $ownPtStyle;
+                        exit();
+                    }
+
+                    //continue;
+
+                    $custom->debtAmount = $debtAmount;
+                    $custom->balanceMerged = 0;
+                    $custom->balance = $beforeBalance;
+                    $custom->save();
+
+                    $ghs->debtAmount = $debtAmount;
+                    $ghs->balanceMerged = 0;
+                    $ghs->balance = $beforeBalance;
+                    $ghs->save();
+
+                    // 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);
+
+                }
+            }
+
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            $msg = $e->getMessage();
+            echo $msg;
+        }
+
+    }
+
+}