Browse Source

Merge branch 'master' into dev

shish 2 months ago
parent
commit
aeafb30cd9
2 changed files with 45 additions and 7 deletions
  1. 18 7
      app-ghs/controllers/ItemController.php
  2. 27 0
      biz-ghs/product/classes/ProductClass.php

+ 18 - 7
app-ghs/controllers/ItemController.php

@@ -493,6 +493,18 @@ class ItemController extends BaseController
         } elseif ($requestType == 'part') {
             $where['delStatus'] = 0;
             $where['status'] = 1;
+        } elseif ($requestType == 'warning') {
+            $where['delStatus'] = 0;
+            unset($where['status']);
+            if ($lookStock == 1) {
+                $where['stock>'] = 0;
+            }
+            if ($lookStock == 2) {
+                $where['stock'] = 0;
+            }
+            if ($onStock == 1) {
+                $where['onStock>'] = 0;
+            }
         } else {
             util::fail('没有定义的请求方式');
         }
@@ -558,7 +570,11 @@ class ItemController extends BaseController
         }
 
         $field = '*';
-        $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
+        if ($requestType == 'warning') {
+            $result = ProductClass::warningList($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
+        } else {
+            $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
+        }
         $list = $result['list'] ?? [];
         if ($requestType == 'hasStockList') {
             util::fail('无效方式');
@@ -589,12 +605,7 @@ class ItemController extends BaseController
         } elseif ($requestType == 'cg') {
             $list = ProductClass::cgItemGroup($list, $level);
         } elseif ($requestType == 'warning') {
-            util::fail('无效方式');
-//            $itemInfoData = Product::find()->where("mainId={$this->mainId}")
-//                ->andWhere('`stock`+`onStock`<`stockWarning`')
-//                ->andWhere("delStatus=0")
-//                ->select($field)->asArray()->all();
-//            $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
+            $list = ProductClass::itemListGroup($list, $level);
         } else {
             util::fail('没有数据');
         }

+ 27 - 0
biz-ghs/product/classes/ProductClass.php

@@ -199,6 +199,33 @@ class ProductClass extends BaseClass
         return $list;
     }
 
+    /**
+     * 库存预警分页列表(与 get-item-list 共用 where 条件):stock + onStock < stockWarning
+     */
+    public static function warningList($where, $order = ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC])
+    {
+        $get = Yii::$app->request->get();
+        $page = isset($get['page']) ? intval($get['page']) : 1;
+        $pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? intval($get['pageSize']) : Yii::$app->params['pageSize'];
+        $offset = ($page - 1) * $pageSize;
+
+        $model = self::getModel();
+        $query = $model->conditionQuery($where)->andWhere('(`stock` + `onStock`) < `stockWarning`');
+        $count = (clone $query)->count();
+        $totalPage = $pageSize > 0 ? (int)ceil($count / $pageSize) : 0;
+        if (!empty($order)) {
+            $query->orderBy($order);
+        }
+        $list = $query->offset($offset)->limit($pageSize)->asArray()->all();
+
+        return [
+            'totalNum' => $count,
+            'totalPage' => $totalPage,
+            'moreData' => $totalPage > $page ? 1 : 0,
+            'list' => $list,
+        ];
+    }
+
     //盘点用到的数据组合
     public static function checkItemGroup($list, $level = 0)
     {