소스 검색

花材列表组合

shish 3 년 전
부모
커밋
0af616f748
2개의 변경된 파일133개의 추가작업 그리고 0개의 파일을 삭제
  1. 56 0
      app-ghs/controllers/ProductController.php
  2. 77 0
      biz-ghs/product/services/ProductService.php

+ 56 - 0
app-ghs/controllers/ProductController.php

@@ -138,6 +138,62 @@ class ProductController extends BaseController
         util::success($data);
     }
 
+    //按分类列出所有花材
+    public function actionShow()
+    {
+        $py = Yii::$app->request->get('py', '');
+        $requestType = Yii::$app->request->get('requestType', 'common');
+        //默认显示上架商品
+        $status = Yii::$app->request->get('status', 1);
+        //默认显示未删除商品
+        $delStatus = Yii::$app->request->get('delStatus', 0);
+        $warning = Yii::$app->request->get('warning', 0);
+
+        //获取所有当前供货商的分类 (全部、常用)
+        //根据分类组装分类下的花材信息
+        //中央ID
+        $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
+
+        $where['mainId'] = $this->mainId;
+        if ($py) {
+            $pyName = strtolower($py);
+            $where['py'] = $pyName;
+        }
+        if ($requestType == 'hasStock') {
+            //改价只显示库存大于0的
+            $where['stock>'] = 0;
+        }
+        if (!empty($status)) {
+            $where['status'] = $status;
+        }
+        $where['delStatus'] = $delStatus;
+
+        //客户等级
+        $customId = Yii::$app->request->get('customId', 0);
+        $level = 1;
+        if (!empty($customId)) {
+            $custom = CustomClass::getById($customId, true);
+            $level = $custom->level ?? 1;
+        }
+
+        if ($warning == 1) {
+            //库存预警
+            $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
+            $itemInfoData = Product::find()->where("mainId={$this->mainId}")
+                ->andWhere('`stock`<`stockWarning`')
+                ->andWhere("delStatus=0")
+                ->select($field)->asArray()->all();
+        } else {
+            $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
+            $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
+        }
+        $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
+
+        $data = ProductService::assembleItemData($classIds, $itemInfoData, true);
+
+        util::success($data);
+    }
+
     //按分类列出所有花材
     public function actionIndex()
     {

+ 77 - 0
biz-ghs/product/services/ProductService.php

@@ -24,6 +24,83 @@ class ProductService extends BaseService
     //预售
     const PRESELL_CLASS_ID = '-3';
 
+    //组装分类花材数据
+    public static function assembleItemData($classIds, $itemInfoData, $showTodayDiscount = false)
+    {
+        $itemGroup = [];
+        $tjItem = [];
+        $preSellItem = [];
+        if ($itemInfoData) {
+            foreach ($itemInfoData as $v) {
+                if (isset($v['presell']) && $v['presell'] == 1) {
+                    $v['classId'] = self::PRESELL_CLASS_ID;
+                    $v['className'] = '预售专区';
+                    $preSellItem[] = $v;
+                    $itemGroup[] = $v;
+                } elseif (isset($v['discountPrice']) && $v['discountPrice'] > 0) {
+                    $v['classId'] = self::TJ_CLASS_ID;
+                    $v['className'] = '今日特价';
+                    $tjItem[] = $v;
+                    $itemGroup[] = $v;
+                }
+            }
+        }
+
+        $classMapItem = [];
+        if ($itemInfoData) {
+            foreach ($itemInfoData as $v) {
+                $classMapItem[$v['classId']][] = $v['itemId'];
+            }
+        }
+
+        $classData = [];
+
+        foreach ($classIds as $classVal) {
+            $classId = $classVal['id'];
+            $className = $classVal['name'] ?? '';
+            $print = $classVal['print'] ?? 1;
+            $cover = imgUtil::groupImg($classVal['cover']) . "?x-oss-process=image/resize,m_fill,h_90,w_90";
+            if ($classId > 0) {
+                $tmp = [];
+                $tmp['classId'] = $classId;
+                $tmp['className'] = $classVal['name'] ?? '';
+                $tmp['classCover'] = $cover;
+                $tmp['print'] = $print;
+                $items = $classMapItem[$classId] ?? [];
+                if ($items) {
+                    if ($itemInfoData) {
+                        foreach ($itemInfoData as $v) {
+                            if (in_array($v['itemId'], $items)) {
+                                //冗余给前端使用 2021.1.31 lqh
+                                $v['classId'] = $classId;
+                                $v['className'] = $className;
+                                $v['print'] = $print;
+                                $tmp['child'][] = $v;
+                                $itemGroup[] = $v;
+                            }
+                        }
+                    } else {
+                        $tmp['child'] = [];
+                    }
+                } else {
+                    $tmp['child'] = [];
+                }
+                $classData[] = $tmp;
+            }
+        }
+        if ($showTodayDiscount && !empty($tjItem)) {
+            $tjClass = [['classId' => self::TJ_CLASS_ID, 'className' => '今日特价', 'print' => 0,
+                'classCover' => imgUtil::groupImg('item_class/tj.jpg'), 'child' => $tjItem,]];
+            $classData = array_merge($tjClass, $classData);
+        }
+        if ($showTodayDiscount && !empty($preSellItem)) {
+            $preSellClass = [['classId' => self::PRESELL_CLASS_ID, 'className' => '预售专区', 'print' => 0,
+                'classCover' => imgUtil::groupImg('item_class/mrfl.png'), 'child' => $preSellItem,]];
+            $classData = array_merge($preSellClass, $classData);
+        }
+        return ['classItem' => $classData, 'itemList' => $itemGroup];
+    }
+
     //组装分类花材数据
     public static function assembleData($classIds, $itemInfoData, $showTodayDiscount = false)
     {