Procházet zdrojové kódy

花材信息获取

林琦海 před 5 roky
rodič
revize
96378783d3

+ 35 - 1
app/ghs/controllers/ItemInfoController.php

@@ -8,18 +8,52 @@ namespace ghs\controllers;
 
 
 use bizGhs\item\classes\ItemClass;
+use bizGhs\item\classes\ItemClassClass;
 use bizGhs\item\classes\ItemInfoClass;
+use bizGhs\item\services\ItemInfoService;
+use bizGhs\item\services\ItemService;
 use common\components\util;
 use Yii;
 class ItemInfoController extends BaseController
 {
 
+
+    //开单时获取所有的分类花材信息
+    public function actionIndex()
+    {
+        $pyName = Yii::$app->request->get('pyName','');
+        //获取所有当前供应商的分类 (全部、常用)
+        //根据分类组装分类下的花材信息
+        $classIds = ItemClassClass::getGhsItemClassAll($this->ghsId);
+        //获取供应商下所有花材ID (itemIds)
+        $itemIdsInfo = ItemService::getGhsItemIds($this->ghsId);
+        $itemIds = array_column($itemIdsInfo,'itemId');
+        if($pyName){
+            $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
+            $itemIds = array_intersect($itemIds,$pyNameItemIds);
+        }
+        $itemInfoData = ItemInfoClass::getItemInfoByItemIds($itemIds);
+        //常用的itemIds
+        $oftenItemIds = ItemInfoClass::getOftenItemIds($this->ghsId);
+
+        //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
+        $data = ItemInfoService::assembleData($classIds,$itemIdsInfo,$itemInfoData,$oftenItemIds);
+
+        util::success($data);
+    }
+
     public function actionList()
     {
         $classId = Yii::$app->request->get('classId',0);
+        $pyName = Yii::$app->request->get('pyName','');
         $itemIds = ItemClass::getItemIdsByClassId($classId);
-        $data = ItemInfoClass::getItemInfoByItemId($itemIds);
+        if($pyName){
+            $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
+            $itemIds = array_intersect($itemIds,$pyNameItemIds);
+        }
+        $data = ItemInfoClass::getItemInfoByItemIds($itemIds);
         util::success($data);
     }
 
+    
 }

+ 26 - 0
biz-ghs/item/classes/ItemClass.php

@@ -9,6 +9,8 @@ namespace bizGhs\item\classes;
 
 use bizGhs\base\classes\BaseClass;
 use common\components\util;
+use common\services\xhItemService;
+
 class ItemClass extends BaseClass
 {
 
@@ -67,4 +69,28 @@ class ItemClass extends BaseClass
         }
         return $data;
     }
+
+    //获取当前供应商下的所有item
+    public static function getGhsItemAll($ghsId,$select="*")
+    {
+        $where = [
+            'ghsId'=>$ghsId
+        ];
+        $data = self::getAllList($select,$where);
+        return $data;
+    }
+
+
+    //根据拼音名称,获取itemIds
+    public static function getItemIdsByPyName($pyName)
+    {
+        //统一转小写
+        $pyName = strtolower($pyName);
+        $where = ['pyName'=>$pyName];
+        $data = xhItemService::getAllByCondition($where,null,'id');
+        if($data){
+            $data= array_column($data,'id');
+        }
+        return $data;
+    }
 }

+ 34 - 3
biz-ghs/item/classes/ItemInfoClass.php

@@ -9,7 +9,7 @@ namespace bizGhs\item\classes;
 
 use bizGhs\base\classes\BaseClass;
 use common\components\business;
-use common\models\xhItem;
+use common\services\xhItemService;
 
 class ItemInfoClass extends BaseClass
 {
@@ -17,7 +17,7 @@ class ItemInfoClass extends BaseClass
     public static $baseFile = '\bizGhs\item\models\ItemInfo';
 
     //根据itemIds获取相应的花材信息
-    public static function getItemInfoByItemId(array $itemIds)
+    public static function getItemInfoByItemIds(array $itemIds)
     {
         $where = ['itemId'=>['in',$itemIds],'delStatus'=>0];
         $data = self::getAllList('*',$where);
@@ -32,7 +32,7 @@ class ItemInfoClass extends BaseClass
         $itemIds = array_column($list,'itemId');
         //获取相应的图片,名称,py
         $where = ['id'=>$itemIds];
-        $data = xhItem::getAllByCondition($where,null,'id,name,pyName,cover,unitNum');
+        $data = xhItemService::getAllByCondition($where,null,'id,name,pyName,cover,unitNum');
         if(!empty($data)){
             $data = array_column($data, NULL, 'id');
             foreach ($list as $k=>$v){
@@ -62,4 +62,35 @@ class ItemInfoClass extends BaseClass
             'stockPiece'=>$stockPiece,
         ];
     }
+
+    //获取常用的itemIds
+    public static function getOftenItemIds($ghsId)
+    {
+        $data = self::getAllList("itemId",['ghsId'=>$ghsId],'actualSold desc');
+        if($data){
+            $data = array_column($data,'itemId');
+        }
+        return $data;
+    }
+
+
+
+    //加库存
+    public static function addStock()
+    {
+
+    }
+
+    //减库存
+    public static function decreaseStock()
+    {
+
+    }
+
+
+    public static function computedPrice()
+    {
+
+    }
+
 }

+ 59 - 1
biz-ghs/item/services/ItemInfoService.php

@@ -12,7 +12,65 @@ use bizGhs\base\services\BaseService;
 class ItemInfoService extends BaseService
 {
 
-    //
+    //组装分类花材数据
+    public static function assembleData($classIds,$itemIdsInfo,$itemInfoData,$oftenItemIds)
+    {
+        $oftenItemInfoData = [];
+        if($itemInfoData){
+            foreach ($itemInfoData as $v){
+                if(in_array($v['itemId'],$oftenItemIds)){
+                    $oftenItemInfoData[] = $v;
+                }
+            }
+        }
+        //classId=>itemId
+        $classMapItem = [];
+        if($itemIdsInfo){
+            foreach ($itemIdsInfo as $v){
+                $classMapItem[$v['classId']][] = $v['itemId'];
+            }
+        }
+        //全部, 常用, 各个分类
+        $allData = [
+            [
+                'classId'=> -1,
+                'className'=>'全部',
+                'child'=>$itemInfoData,
+            ]
+        ];
+        //常用
+        $oftenData = [
+            [
+                'classId'=> -2,
+                'className'=>'常用',
+                'child'=>$oftenItemInfoData,
+            ]
+        ];
+        $classData = [];
+        foreach ($classIds as $v){
+            $classId = $v['id'];
+            if($classId > 0 ){
+                $tmp =[];
+                $tmp['classId'] = $classId;
+                $tmp['className'] = $v['name'];
+                $items = $classMapItem[$classId]??[];
+                if($items){
+                    foreach ($itemInfoData as $v){
+                        if(in_array($v['itemId'],$items)){
+                            $tmp['child'][] = $v;
+                        }
+                    }
+                }else{
+                    $tmp['child'] = [];
+                }
+                $classData[] = $tmp;
+            }
+
+        }
+        $data = array_merge($oftenData,$allData,$classData);
+
+        return $data;
+    }
 
 
 }

+ 7 - 0
biz-ghs/item/services/ItemService.php

@@ -116,4 +116,11 @@ class ItemService extends BaseService
             util::fail("操作失败");
         }
     }
+
+    //获取所有的花材ID
+    public static function getGhsItemIds($ghsId)
+    {
+        $data = ItemClass::getGhsItemAll($ghsId,'classId,itemId');
+        return $data;
+    }
 }

+ 20 - 0
common/services/xhItemService.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/1/16 13:39
+ */
+
+namespace common\services;
+
+
+use common\models\xhItem;
+
+class xhItemService
+{
+
+    public static function getAllByCondition($condition, $order = null, $field = '*')
+    {
+        return xhItem::getAllByCondition($condition, $order,$field);
+    }
+
+}