shish 1 maand geleden
bovenliggende
commit
c2512b27d3

+ 33 - 0
app-ghs/controllers/GhsBalanceChangeController.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace ghs\controllers;
+
+use bizGhs\ghs\classes\GhsBalanceChangeClass;
+use bizGhs\ghs\classes\GhsClass;
+use common\components\util;
+use Yii;
+
+class GhsBalanceChangeController extends BaseController
+{
+
+    /** 批发店查看供货商(内部采购)余额变动明细 */
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $ghsId = $get['ghsId'] ?? 0;
+        if (empty($ghsId)) {
+            util::success([]);
+        }
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::success([]);
+        }
+        if ($ghs->ownMainId != $this->mainId) {
+            util::fail('不是你的供货商');
+        }
+        $where = ['ghsId' => $ghsId];
+        $list = GhsBalanceChangeClass::getChangeList($where);
+        util::success($list);
+    }
+
+}

+ 15 - 0
biz-ghs/custom/classes/AccountMoneyClass.php

@@ -379,4 +379,19 @@ class AccountMoneyClass
             self::ensureCustomMoneyReady($custom, true);
         }
     }
+
+    /**
+     * 【用途】供货商列表分页时,对 xhGhs 仍有 debtAmount 未合并的单行触发懒合并(读路径补刀)。
+     * 【调用时机】bizGhs\ghs\classes\GhsClass::groupBaseInfo。
+     */
+    public static function mergeGhsRowFromListIfNeeded($ghsId)
+    {
+        if (empty($ghsId)) {
+            return;
+        }
+        $ghs = BizGhsClass::getLockById($ghsId);
+        if (!empty($ghs)) {
+            self::ensureGhsMoneyReady($ghs, true);
+        }
+    }
 }

+ 6 - 0
biz-ghs/ghs/classes/GhsBalanceChangeClass.php

@@ -12,4 +12,10 @@ class GhsBalanceChangeClass extends BaseClass
 
     public static $baseFile = '\bizGhs\ghs\models\GhsBalanceChange';
 
+    /** 批发店供货商余额变动列表(xhGhsBalanceChange,按 ghsId) */
+    public static function getChangeList($where)
+    {
+        return self::getList('*', $where, 'addTime DESC,id DESC');
+    }
+
 }

+ 13 - 0
biz-ghs/ghs/classes/GhsClass.php

@@ -3,6 +3,7 @@
 namespace bizGhs\ghs\classes;
 
 use bizGhs\base\classes\BaseClass;
+use bizGhs\custom\classes\AccountMoneyClass;
 use bizGhs\order\classes\PurchaseOrderClass;
 use bizGhs\shop\classes\ShopClass;
 use common\components\imgUtil;
@@ -30,6 +31,18 @@ class GhsClass extends BaseClass
         $ids = array_column($list, 'shopId');
         $shopInfo = ShopClass::getByIds($ids, null, 'id');
         foreach ($list as $key => $val) {
+            // 列表读:xhGhs 未合并的挂账先懒合并(待结订单笔数/金额仍用采购单统计,见下方)
+            $ghsId = $val['id'] ?? 0;
+            if (!empty($ghsId) && bccomp($val['debtAmount'] ?? '0', '0', 2) != 0 && empty($val['balanceMerged'])) {
+                AccountMoneyClass::mergeGhsRowFromListIfNeeded($ghsId);
+                $fresh = self::getById($ghsId);
+                if (!empty($fresh)) {
+                    $freshAttrs = is_array($fresh) ? $fresh : $fresh->getAttributes();
+                    $list[$key] = array_merge($list[$key], $freshAttrs);
+                    $val = $list[$key];
+                }
+            }
+
             $avatar = $val['avatar'] ?? '';
             $list[$key]['shortAvatar'] = $avatar;
             $list[$key]['avatar'] = imgUtil::groupImg($avatar);