Ver código fonte

关闭今日特价

shish 5 anos atrás
pai
commit
382c21daf9
1 arquivos alterados com 42 adições e 66 exclusões
  1. 42 66
      biz-ghs/product/services/ProductService.php

+ 42 - 66
biz-ghs/product/services/ProductService.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace bizGhs\product\services;
 
 
@@ -15,80 +16,60 @@ class ProductService extends BaseService
     const OFTEN_CLASS_ID = '-2';
 
     //组装分类花材数据
-    public static function assembleData($classIds,$itemIdsInfo,$itemInfoData,$oftenItemIds,$type,$showSale=false)
+    public static function assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type, $showSale = false)
     {
-        $oftenItemInfoData = [];
-        $allData = [];
         $saleItem = []; //今日特价
-        if($itemInfoData){
-            foreach ($itemInfoData as $v){
-//                if(in_array($v['itemId'],$oftenItemIds)){
-//                    $v['classId'] = self::OFTEN_CLASS_ID;
-//                    $oftenItemInfoData[] = $v;
+        //暂时关闭今日特价
+//        if($itemInfoData){
+//            foreach ($itemInfoData as $v){
+//                $v['classId'] = self::ALL_CLASS_ID;
+//                if($v['price'] < $v['cost']+ $v['addPrice']){
+//                    $saleItem[] = $v;
 //                }
-                $v['classId'] = self::ALL_CLASS_ID;
-                if($v['price'] < $v['cost']+ $v['addPrice']){
-                    //特价
-                    $saleItem[] = $v;
-                }
-            }
-        }
+//            }
+//        }
 
         //classId=>itemId
         $classMapItem = [];
-        if($itemInfoData){
-            foreach ($itemInfoData as $v){
+        if ($itemInfoData) {
+            foreach ($itemInfoData as $v) {
                 $classMapItem[$v['classId']][] = $v['itemId'];
             }
         }
-        //全部, 常用, 各个分类
-        //常用改为今日特价
+        //今日特价
         $saleData = [
             [
-                'classId'=> self::ALL_CLASS_ID,
-                'className'=>'今日特价',
-                'child'=>$saleItem,
+                'classId' => self::ALL_CLASS_ID,
+                'className' => '今日特价',
+                'child' => $saleItem,
             ]
         ];
-        //常用
-//        $oftenData = [
-//            [
-//                'classId'=> self::OFTEN_CLASS_ID,
-//                'className'=>'常用',
-//                'child'=>$oftenItemInfoData,
-//            ]
-//        ];
-
-        //改价,库存预警只要常用分类 (弃用)
-//        if(in_array($type,['waring','change-price'])){
-//            return $oftenData;
-//        }
         $classData = [];
 
-        foreach ($classIds as $v){
+        foreach ($classIds as $v) {
             $classId = $v['id'];
-            if($classId > 0 ){
-                $tmp =[];
+            if ($classId > 0) {
+                $tmp = [];
                 $tmp['classId'] = $classId;
                 $tmp['className'] = $v['name'];
-                $items = $classMapItem[$classId]??[];
-                if($items){
-                    if($itemInfoData){
-                        foreach ($itemInfoData as $v){
-                            if(in_array($v['itemId'],$items)){
+                $items = $classMapItem[$classId] ?? [];
+                if ($items) {
+                    if ($itemInfoData) {
+                        foreach ($itemInfoData as $v) {
+                            if (in_array($v['itemId'], $items)) {
                                 $v['classId'] = $classId; //前端要求增加classId 2021.1.31 linqh
                                 $tmp['child'][] = $v;
                             }
                         }
-                    }else{
+                    } else {
                         $tmp['child'] = [];
                     }
-                }else{
+                } else {
                     $tmp['child'] = [];
                 }
                 //去除空分类
-                if(empty($tmp['child'])){
-					//暂时列出所有的分类 shish 2021.5.2
+                if (empty($tmp['child'])) {
+                    //暂时列出所有的分类 shish 2021.5.2
                     //continue;
                 }
                 $classData[] = $tmp;
@@ -96,14 +77,9 @@ class ProductService extends BaseService
 
         }
 
-        if($showSale && !empty($saleItem)){
-            $classData = array_merge($saleData,$classData);
+        if ($showSale && !empty($saleItem)) {
+            $classData = array_merge($saleData, $classData);
         }
-        //$data = array_merge($oftenData,$allData,$classData);
-        //去除全部
-        //隐藏常用
-        //$data = array_merge($oftenData,$classData);
-
         return $classData;
     }
 
@@ -114,24 +90,24 @@ class ProductService extends BaseService
         $productIds = array_column($ghsItemInfo, 'productId');
         $productData = ProductClass::getProductByIds($productIds);
         $productData = array_column($productData, NULL, 'id');
-        $itemIds =  array_column($productData,'itemId');
+        $itemIds = array_column($productData, 'itemId');
         $itemData = xhItemService::getByIds($itemIds);
         $itemData = array_column($itemData, NULL, 'id');
         $data = [
-            'totalPrice'=>0,
-            'totalWeight'=>0,
+            'totalPrice' => 0,
+            'totalWeight' => 0,
         ];
-        foreach($ghsItemInfo as $v){
+        foreach ($ghsItemInfo as $v) {
             $productId = $v['productId'];
             $itemId = $productData[$productId]['itemId'];
-            $unitNum = $itemData[$itemId]['unitNum']??0;
-            $weight = $itemData[$itemId]['weight']??0;// 每扎重量
-            $itemNum = ProductClass::mergeItemNum($v['bigNum'],$v['smallNum'],$unitNum); // 总共多少扎
-            $weight = bcmul($weight,$itemNum,2);
-            $itemPrice =$productData[$productId]['price']??0; //当时售卖的价格
-            $price = bcmul($itemNum,$itemPrice,2);
-            $data['totalWeight'] = bcadd($data['totalWeight'],$weight,2);
-            $data['totalPrice'] =bcadd($data['totalPrice'],$price,2);
+            $unitNum = $itemData[$itemId]['unitNum'] ?? 0;
+            $weight = $itemData[$itemId]['weight'] ?? 0;// 每扎重量
+            $itemNum = ProductClass::mergeItemNum($v['bigNum'], $v['smallNum'], $unitNum); // 总共多少扎
+            $weight = bcmul($weight, $itemNum, 2);
+            $itemPrice = $productData[$productId]['price'] ?? 0; //当时售卖的价格
+            $price = bcmul($itemNum, $itemPrice, 2);
+            $data['totalWeight'] = bcadd($data['totalWeight'], $weight, 2);
+            $data['totalPrice'] = bcadd($data['totalPrice'], $price, 2);
         }
         return $data;
     }