shish 4 anos atrás
pai
commit
5c70069e45
1 arquivos alterados com 62 adições e 48 exclusões
  1. 62 48
      console/controllers/CustomController.php

+ 62 - 48
console/controllers/CustomController.php

@@ -3,6 +3,7 @@
 namespace console\controllers;
 
 use biz\ghs\classes\GhsClass;
+use biz\shop\classes\ShopClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\models\Custom;
 use bizGhs\order\classes\OrderClass;
@@ -35,79 +36,92 @@ class CustomController extends Controller
     //欠款信息不一致跟踪 shish 20220307 ./yii custom/adjust-debt
     public function actionAdjustDebt()
     {
-        $query = new \yii\db\Query();
+        $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
+        if (empty($shopList)) {
+            return false;
+        }
+        foreach ($shopList as $key => $shop) {
 
-        $query->from(Custom::tableName());
+            $shopId = $shop->id ?? 0;
+            $shopName = $shop->shopName ?? '';
+            echo "门店的客户 {$shopName} \n";
+            $query = new \yii\db\Query();
 
-        $query->orderBy('addTime ASC');
+            $query->from(Custom::tableName());
 
-        foreach ($query->batch(50) as $customList) {
-            if (!empty($customList)) {
-                foreach ($customList as $custom) {
+            $query->where(['ownShopId' => $shopId]);
+            $query->orderBy('addTime ASC');
 
-                    $customId = $custom['id'] ?? 0;
-                    $where = ['customId' => $customId, 'debt' => 1];
-                    $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*');
-                    $ghsOrderDebtAmount = 0;
-                    if (!empty($orderList)) {
-                        foreach ($orderList as $order) {
-                            $actPrice = $order['actPrice'] ?? 0;
-                            $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2);
+            foreach ($query->batch(50) as $customList) {
+                if (!empty($customList)) {
+                    foreach ($customList as $custom) {
+                        $customName = $custom['name'] ?? '';
+                        echo $customName . "\n";
+                        continue;
+                        $customId = $custom['id'] ?? 0;
+                        $where = ['customId' => $customId, 'debt' => 1];
+                        $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*');
+                        $ghsOrderDebtAmount = 0;
+                        if (!empty($orderList)) {
+                            foreach ($orderList as $order) {
+                                $actPrice = $order['actPrice'] ?? 0;
+                                $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2);
+                            }
                         }
-                    }
 
 
-                    $ghsId = $custom['ghsId'] ?? 0;
+                        $ghsId = $custom['ghsId'] ?? 0;
 
-                    $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId);
+                        $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId);
 
-                    $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES];
-                    $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*');
-                    $hdCgOrderDebtAmount = 0;
-                    if (!empty($cgList)) {
-                        foreach ($cgList as $cg) {
-                            $actPrice = $cg['actPrice'] ?? 0;
-                            $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2);
+                        $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES];
+                        $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*');
+                        $hdCgOrderDebtAmount = 0;
+                        if (!empty($cgList)) {
+                            foreach ($cgList as $cg) {
+                                $actPrice = $cg['actPrice'] ?? 0;
+                                $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2);
+                            }
                         }
-                    }
-                    if($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0 ){
-                        //noticeUtil::push("!!!!!!!供应商 {$ghsId}  客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347');
-                        echo "@@@@@@@@@@@@@供应商 {$ghsId}  客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n";
-                    }
-                    $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount);
-                    $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount);
+                        if ($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0) {
+                            //noticeUtil::push("!!!!!!!供应商 {$ghsId}  客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347');
+                            echo "@@@@@@@@@@@@@供应商 {$ghsId}  客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n";
+                        }
+                        $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount);
+                        $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount);
 
-                    if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) {
-                        //noticeUtil::push("!!!!!!!供应商 {$ghsId}  客户id {$customId} 二边欠款单总金额不一致", '15280215347');
-                        echo "---------供应商 {$ghsId}  客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n";
-                        continue;
-                    }
+                        if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) {
+                            //noticeUtil::push("!!!!!!!供应商 {$ghsId}  客户id {$customId} 二边欠款单总金额不一致", '15280215347');
+                            echo "---------供应商 {$ghsId}  客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n";
+                            continue;
+                        }
 
-                    $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0;
-                    $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0;
+                        $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0;
+                        $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0;
 
-                    if ($customSaveDebtAmount != $ghsOrderDebtAmount) {
-                        echo "*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n";
+                        if ($customSaveDebtAmount != $ghsOrderDebtAmount) {
+                            echo "*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n";
 
-                        //noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347');
+                            //noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347');
 
 //                        echo "已更:".$hdCgOrderDebtAmount.' '.$ghsOrderDebtAmount."\n";
 //                        \bizHd\ghs\classes\GhsClass::updateById($ghsId, ['debtAmount' => $hdCgOrderDebtAmount]);
 //                        CustomClass::updateById($customId, ['debtAmount' => $ghsOrderDebtAmount]);
-                        continue;
-                    }
+                            continue;
+                        }
 
-                    if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) {
-                        echo "#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n";
+                        if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) {
+                            echo "#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n";
 
-                        //noticeUtil::push("#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347');
+                            //noticeUtil::push("#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347');
 
 //                        echo "已更:".$hdCgOrderDebtAmount.' '.$ghsOrderDebtAmount."\n";
 //                        \bizHd\ghs\classes\GhsClass::updateById($ghsId, ['debtAmount' => $hdCgOrderDebtAmount]);
 //                        CustomClass::updateById($customId, ['debtAmount' => $ghsOrderDebtAmount]);
-                        continue;
-                    }
+                            continue;
+                        }
 
+                    }
                 }
             }
         }