shish пре 1 година
родитељ
комит
8aa72f2531

+ 10 - 0
app-ghs/controllers/CustomController.php

@@ -1043,4 +1043,14 @@ class CustomController extends BaseController
         util::success($info);
     }
 
+    //总赊账和总余额汇总 ssh 20250620
+    public function actionShowTotalBalance()
+    {
+        $pfShop = $this->shop;
+        $lsShopId = $pfShop->lsShopId;
+        $pfShopId = $this->shopId;
+        $respond = CustomClass::showTotalBalance($pfShopId, $lsShopId);
+        util::success($respond);
+    }
+
 }

+ 10 - 0
app-hd/controllers/CustomController.php

@@ -560,4 +560,14 @@ class CustomController extends BaseController
         util::success($user);
     }
 
+    //总赊账和总余额汇总 ssh 20250620
+    public function actionShowTotalBalance()
+    {
+        $lsShop = $this->shop;
+        $lsShopId = $this->shopId;
+        $pfShopId = $lsShop->pfShopId;
+        $respond = \bizGhs\custom\classes\CustomClass::showTotalBalance($pfShopId, $lsShopId);
+        util::success($respond);
+    }
+
 }

+ 46 - 0
biz-ghs/custom/classes/CustomClass.php

@@ -746,4 +746,50 @@ class CustomClass extends BaseClass
         util::success(['file' => $fileUrl, 'shortFile' => $file]);
     }
 
+    public static function showTotalBalance($pfShopId = 0, $lsShopId = 0)
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $arr['pf'] = ['debt' => 0, 'balance' => 0];
+        $arr['ls'] = ['debt' => 0, 'balance' => 0];
+        if (!empty($pfShopId)) {
+            $custom = CustomClass::getAllByCondition(['ownShopId' => $pfShopId], null, '*', null, true);
+            $pfDebt = 0;
+            $pfBalance = 0;
+            if (!empty($custom)) {
+                foreach ($custom as $c) {
+                    $balance = $c->balance ?? 0;
+                    if ($balance > 0) {
+                        $pfBalance = bcadd($pfBalance, $balance, 2);
+                    } else {
+                        $balance = abs($balance);
+                        $pfDebt = bcadd($pfDebt, $balance, 2);
+                    }
+                }
+            }
+            $arr['pf']['debt'] = $pfDebt;
+            $arr['pf']['balance'] = $pfBalance;
+        }
+        if (!empty($lsShop)) {
+            $lsCustom = \bizHd\custom\classes\CustomClass::getAllByCondition(['shopId' => $lsShopId], null, '*', null, true);
+            $lsDebt = 0;
+            $lsBalance = 0;
+            if (!empty($lsCustom)) {
+                foreach ($lsCustom as $lc) {
+                    $balance = $lc->balance ?? 0;
+                    if ($balance > 0) {
+                        $lsBalance = bcadd($lsBalance, $balance, 2);
+                    } else {
+                        $balance = abs($balance);
+                        $lsDebt = bcadd($lsDebt, $balance, 2);
+                    }
+                }
+                $arr['ls']['debt'] = $lsDebt;
+                $arr['ls']['balance'] = $lsBalance;
+            }
+        }
+        return $arr;
+    }
+
 }