瀏覽代碼

采购列表优化

shish 2 月之前
父節點
當前提交
c8b97a816a
共有 2 個文件被更改,包括 33 次插入5 次删除
  1. 11 3
      app-ghs/controllers/GhsController.php
  2. 22 2
      biz-ghs/ghs/classes/GhsClass.php

+ 11 - 3
app-ghs/controllers/GhsController.php

@@ -189,11 +189,15 @@ class GhsController extends BaseController
     {
         $get = Yii::$app->request->get();
         $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
-        $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? $get['delStatus'] : 0;
+        $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? (int)$get['delStatus'] : 0;
         $where = [
             'ownShopId' => $this->shopId,
-            'delStatus' => $delStatus
+            'delStatus' => $delStatus,
         ];
+        $sortType = $get['sortType'] ?? 'all';
+        if (!in_array($sortType, ['all', 'debt', 'expend'], true)) {
+            $sortType = 'all';
+        }
         if (!empty($name)) {
             if (stringUtil::isLetter($name)) {
                 $where['py'] = ['like', $name];
@@ -240,7 +244,11 @@ class GhsController extends BaseController
             }
         }
 
-        $list = GhsClass::getGhsList($where);
+        $list = GhsClass::getGhsList($where, $sortType);
+        $page = isset($get['page']) ? (int)$get['page'] : 1;
+        if ($page <= 1) {
+            $list['tabCounts'] = GhsClass::getSupplierTabCounts($this->shopId);
+        }
         $staff = $this->shopAdmin;
         if (!isset($staff->finance) || $staff->finance == 0) {
             $totalDebtAmount = 0;

+ 22 - 2
biz-ghs/ghs/classes/GhsClass.php

@@ -15,9 +15,15 @@ class GhsClass extends BaseClass
     public static $baseFile = '\bizGhs\ghs\models\Ghs';
 
     //供货商列表 ssh 20221220
-    public static function getGhsList($where)
+    public static function getGhsList($where, $sortType = 'all')
     {
-        $data = self::getList('*', $where, 'debtAmount DESC,inTurn DESC,addTime DESC');
+        $order = 'inTurn DESC,addTime DESC';
+        if ($sortType === 'debt') {
+            $order = 'balance ASC,inTurn DESC,addTime DESC';
+        } elseif ($sortType === 'expend') {
+            $order = 'expendAmount DESC,inTurn DESC,addTime DESC';
+        }
+        $data = self::getList('*', $where, $order);
         $data['list'] = self::groupBaseInfo($data['list']);
         return $data;
     }
@@ -25,6 +31,20 @@ class GhsClass extends BaseClass
     /**
      * 批发店采购:按 xhGhs 净 balance 汇总总待结(balance<0 部分之和,合并后模型)
      */
+    /** 供货商列表 Tab 数量(一次返回,避免前端多次 list 请求) */
+    public static function getSupplierTabCounts($ownShopId)
+    {
+        if (empty($ownShopId)) {
+            return ['all' => 0, 'debtRank' => 0, 'expendRank' => 0];
+        }
+        $base = ['ownShopId' => $ownShopId, 'delStatus' => 0];
+        return [
+            'all' => (int)self::getCount($base),
+            'debtRank' => (int)self::getCount(['and', $base, ['<', 'balance', 0]]),
+            'expendRank' => (int)self::getCount($base),
+        ];
+    }
+
     public static function sumTotalOutstandingDebt($mainId, $delStatus = 0)
     {
         if (empty($mainId)) {