林琦海 5 лет назад
Родитель
Сommit
cc3e0c8477

+ 32 - 22
app-ghs/controllers/ProductController.php

@@ -13,6 +13,7 @@ use bizGhs\item\classes\ItemClassClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\product\services\ProductService;
 use bizGhs\item\services\ItemService;
+use common\components\noticeUtil;
 use common\components\util;
 use Yii;
 
@@ -35,14 +36,10 @@ class ProductController extends BaseController
         //根据分类组装分类下的花材信息
         $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
 
-        //获取供应商下所有花材ID (itemIds)
-        $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
-
-        $itemIds = array_column($itemIdsInfo, 'itemId');
-
+        $where['merchantId'] = $this->sjId;
         if ($py) {
-            $pyNameItemIds = ItemClass::getItemIdsByPyName($py);
-            $itemIds = array_intersect($itemIds, $pyNameItemIds);
+            $pyName = strtolower($py);
+            $where['py'] = $pyName;
         }
         $shopId = $this->shopId;
         //兼容客户根据门店下单
@@ -56,46 +53,59 @@ class ProductController extends BaseController
             if (!$shopId) {
                 $shopId = $this->shopId;
             }
-
-            $waringItemIds = ProductClass::getItemIdsWarning($this->sjId, $shopId);
-            $itemIds = array_intersect($itemIds, $waringItemIds);
         }
+        $where['shopId'] = $shopId;
 
-
-        $itemInfoData = ProductClass::getProductInfoByItemIds($itemIds, $shopId);
-
+        $itemInfoData = ProductClass::getAllByCondition($where,null,"*");
+        $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
         //常用的itemIds
         $oftenItemIds = ProductClass::getOftenItemIds($shopId);
+        //获取供应商下所有花材ID (itemIds)
+        $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
 
+        //dd($itemInfoData);
         //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
-        $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
+        $data = ProductService::assembleData($classIds, $itemIdsInfo,$itemInfoData, $oftenItemIds, $type);
 
         util::success($data);
     }
 
 
-    //弃用
+    //当前门店所有花材分类
     public function actionList()
     {
         //$classId = Yii::$app->request->get('classId',0);
         $pyName = Yii::$app->request->get('py', '');
-        $itemInfo = ItemClass::getGhsItemAll($this->sjId);
-        $itemIds = array_column($itemInfo, 'itemId');
+//        $itemInfo = ItemClass::getGhsItemAll($this->sjId);
+//        $itemIds = array_column($itemInfo, 'itemId');
+        $where['merchantId'] = $this->sjId;
+
         if ($pyName) {
-            $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
-            $itemIds = array_intersect($itemIds, $pyNameItemIds);
+//            $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
+//            $itemIds = array_intersect($itemIds, $pyNameItemIds);
+            $pyName = strtolower($pyName);
+            $where['py'] = $pyName;
         }
         $shopId = Yii::$app->request->get('shopId', 0);
         if (!$shopId) {
             $shopId = $this->shopId;
         }
+        $where['shopId'] = $shopId;
+
         $type = Yii::$app->request->get('type', '');
+
+        $data = ProductClass::getAllByCondition($where,null,"*");
+        $data = ProductClass::groupProductInfo($data);
         if ($type == 'waring') {
             //库存预警
-            $waringItemIds = ProductClass::getItemIdsWarning($this->sjId, $shopId);
-            $itemIds = array_intersect($itemIds, $waringItemIds);
+            $newData = [];
+            foreach ($data as $v){
+                if($v['stock']  <= $v['stockWarning']) {
+                    $newData[] = $v;
+                }
+            }
+            util::success(['list' => $newData]);
         }
-        $data = ProductClass::getProductInfoByItemIds($itemIds, $shopId);
         util::success(['list' => $data]);
     }
 

+ 0 - 5
biz-ghs/item/classes/ItemClassClass.php

@@ -88,15 +88,10 @@ class ItemClassClass extends BaseClass
             'merchantId'=>$merchantId
         ];
         $data = self::getAllList('id,name',$where,'inTurn desc');
-        $all = [
-            'id'=>-1,
-            'name'=>'全部'
-        ];
         $use = [
             'id'=>-2,
             'name'=>'常用'
         ];
-        array_unshift($data,$all);
         array_unshift($data,$use);
         return $data;
     }

+ 29 - 1
biz-ghs/product/classes/ProductClass.php

@@ -68,6 +68,34 @@ class ProductClass extends BaseClass
 		return $list;
 	}
 
+	//花材图片,名称,大小单位,小单位价格
+    public static function groupProductInfo($list)
+    {
+        foreach ($list as $k => $v) {
+            if($v['cover']){
+                $cover = self::groupImg($v['cover']);
+            }else{
+                $cover = imgUtil::getPrefix() . '/hhb_small.png';
+            }
+            $ratio = $v['ratio'];
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['cover'] = $cover;
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+            $list[$k]['itemName'] = $v['name'] ?? '';
+            //换算大小单位对应价格
+            $list[$k]['bigPrice'] = $v['price']; //大单位价格就是product表存的价格
+            $smallPrice = 0;
+            if ($ratio) {
+                $smallPrice = bcdiv($v['price'], $ratio, 2);
+            }
+            $list[$k]['smallPrice'] = $smallPrice;
+            $list[$k]['bigUnit'] = xhItemService::getUnitName($v['bigUnit']);
+            $list[$k]['smallUnit'] = xhItemService::getUnitName($v['smallUnit']);
+        }
+        return $list;
+    }
+
 
 	//根据花材ID,库存=》  计算出多少扎,多少支
 	public static function formatStockByItemId($itemId, $stock)
@@ -135,7 +163,7 @@ class ProductClass extends BaseClass
 	//获取常用的itemIds
 	public static function getOftenItemIds($shopId)
 	{
-		$data = self::getAllList("itemId", ['shopId' => $shopId], 'actualSold desc');
+		$data = self::getLimitList("itemId", ['shopId' => $shopId], 10,'actualSold desc');
 		if ($data) {
 			$data = array_column($data, 'itemId');
 		}

+ 1 - 1
biz-ghs/product/services/ProductService.php

@@ -26,9 +26,9 @@ class ProductService extends BaseService
                     $oftenItemInfoData[] = $v;
                 }
                 $v['classId'] = self::ALL_CLASS_ID;
-                $allData[] = $v;
             }
         }
+
         //classId=>itemId
         $classMapItem = [];
         if($itemIdsInfo){